Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/dependabot-vendor.yml
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Clean the generated manifests before checking out the PR

For every npm update where package.json or package-lock.json differs from the default branch, the earlier fetch step overwrites those tracked files in the current checkout, so this unforced checkout aborts with Your local changes ... would be overwritten by checkout even though the working-tree contents match FETCH_HEAD; consequently the workflow never reaches the vendor commit. As confirmed by git checkout -h, --force is 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 👍 / 👎.

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"
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,37 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
expected_sha:
description: Commit SHA that this manually dispatched run must test
required: true
type: string

# Cancel superseded runs on the same ref to save CI minutes.
concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
dispatch-integrity:
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Verify manually dispatched commit identity
shell: bash
env:
EXPECTED_SHA: ${{ inputs.expected_sha }}
run: |
set -eu
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
[[ "$EXPECTED_SHA" =~ ^[0-9a-f]{40}$ ]]
test "$GITHUB_SHA" = "$EXPECTED_SHA"
fi

dependency-locks:
needs: dispatch-integrity
runs-on: ubuntu-24.04
permissions:
contents: read
Expand All @@ -36,6 +59,7 @@ jobs:
run: ./scripts/lock_requirements.ps1 -Check

pytest:
needs: dispatch-integrity
name: ${{ matrix.check_name }}
runs-on: ubuntu-24.04
permissions:
Expand Down Expand Up @@ -83,6 +107,7 @@ jobs:
run: pytest tests/ -v

redis-rate-limiter:
needs: dispatch-integrity
name: Redis rate limiter (${{ matrix.redis-version }})
runs-on: ubuntu-24.04
permissions:
Expand Down Expand Up @@ -129,6 +154,7 @@ jobs:
run: pytest tests/test_rate_limiter.py -v

ssh-integration:
needs: dispatch-integrity
runs-on: ubuntu-24.04
permissions:
contents: read
Expand All @@ -155,6 +181,7 @@ jobs:
run: python scripts/run_integration_tests.py

browser-e2e:
needs: dispatch-integrity
runs-on: ubuntu-24.04
permissions:
contents: read
Expand Down Expand Up @@ -208,6 +235,7 @@ jobs:
retention-days: 7

container-threading-smoke:
needs: dispatch-integrity
runs-on: ubuntu-24.04
permissions:
contents: read
Expand Down
Loading
Loading