-
-
Notifications
You must be signed in to change notification settings - Fork 53
Automate Dependabot vendor refreshes #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| name: Dependabot vendor refresh | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: [Tests] | ||
| types: [completed] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: read | ||
| actions: write | ||
|
|
||
| jobs: | ||
| refresh-vendor: | ||
| if: >- | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'failure' && | ||
| github.event.workflow_run.actor.login == 'dependabot[bot]' && | ||
| github.event.workflow_run.head_repository.full_name == github.repository && | ||
| startsWith(github.event.workflow_run.head_branch, 'dependabot/npm_and_yarn/') | ||
| runs-on: ubuntu-24.04 | ||
|
|
||
| steps: | ||
| - name: Checkout trusted default branch | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: '22' | ||
|
|
||
| - name: Fetch and validate Dependabot context | ||
| id: context | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} | ||
| RUN_ID: ${{ github.event.workflow_run.id }} | ||
| run: | | ||
| set -euo pipefail | ||
| [[ "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]] | ||
| [[ "$RUN_ID" =~ ^[1-9][0-9]*$ ]] | ||
| gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" \ | ||
| > "$RUNNER_TEMP/pull-request.json" | ||
| gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?per_page=100" \ | ||
| > "$RUNNER_TEMP/files.json" | ||
| gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/jobs?filter=latest&per_page=100" \ | ||
| > "$RUNNER_TEMP/jobs.json" | ||
| python scripts/dependabot_vendor.py validate \ | ||
| --event "$GITHUB_EVENT_PATH" \ | ||
| --pull-request "$RUNNER_TEMP/pull-request.json" \ | ||
| --files "$RUNNER_TEMP/files.json" \ | ||
| --jobs "$RUNNER_TEMP/jobs.json" \ | ||
| --github-output "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Fetch locked manifests | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| HEAD_SHA: ${{ steps.context.outputs.head_sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| gh api -H "Accept: application/vnd.github.raw+json" \ | ||
| "repos/${GITHUB_REPOSITORY}/contents/package.json?ref=${HEAD_SHA}" \ | ||
| > package.json | ||
| gh api -H "Accept: application/vnd.github.raw+json" \ | ||
| "repos/${GITHUB_REPOSITORY}/contents/package-lock.json?ref=${HEAD_SHA}" \ | ||
| > package-lock.json | ||
|
|
||
| - name: Generate vendor assets from locked dependencies | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| npm ci --ignore-scripts | ||
| node scripts/vendor.js | ||
| node scripts/vendor.js --check | ||
| cp scripts/dependabot_vendor.py "$RUNNER_TEMP/dependabot_vendor.py" | ||
| cp -a static/vendor "$RUNNER_TEMP/vendor" | ||
|
|
||
| - name: Commit generated assets to the validated branch | ||
| id: commit | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| HEAD_REF: ${{ steps.context.outputs.head_ref }} | ||
| HEAD_SHA: ${{ steps.context.outputs.head_sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| git fetch --no-tags origin "refs/heads/${HEAD_REF}" | ||
| test "$(git rev-parse FETCH_HEAD)" = "$HEAD_SHA" | ||
| git checkout --detach FETCH_HEAD | ||
| rsync --archive --delete "$RUNNER_TEMP/vendor/" static/vendor/ | ||
| python "$RUNNER_TEMP/dependabot_vendor.py" stage \ | ||
| --root . \ | ||
| --github-output "$GITHUB_OUTPUT" | ||
|
|
||
| if [ "$(tail -n 1 "$GITHUB_OUTPUT")" = "changed=false" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git commit -m "Update vendored frontend assets [dependabot skip]" | ||
| generated_sha="$(git rev-parse HEAD)" | ||
|
|
||
| test "$(git ls-remote origin "refs/heads/${HEAD_REF}" | cut -f1)" = "$HEAD_SHA" | ||
| gh auth setup-git | ||
| git push origin "HEAD:refs/heads/${HEAD_REF}" | ||
| echo "generated_sha=${generated_sha}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Run tests for the generated commit | ||
| if: steps.commit.outputs.changed == 'true' | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| HEAD_REF: ${{ steps.context.outputs.head_ref }} | ||
| EXPECTED_SHA: ${{ steps.commit.outputs.generated_sha }} | ||
| run: gh workflow run tests.yml --ref "$HEAD_REF" -f expected_sha="$EXPECTED_SHA" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For every npm update where
package.jsonorpackage-lock.jsondiffers from the default branch, the earlier fetch step overwrites those tracked files in the current checkout, so this unforced checkout aborts withYour local changes ... would be overwritten by checkouteven though the working-tree contents matchFETCH_HEAD; consequently the workflow never reaches the vendor commit. As confirmed bygit checkout -h,--forceis the option that will “throw away local modifications,” so reset/clean the generation checkout or perform the PR checkout in a separate clean worktree.Useful? React with 👍 / 👎.