Dependabot Automerge #232
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
| name: Dependabot Automerge | |
| on: | |
| workflow_run: | |
| workflows: ['Node.js CI'] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| dependabot-automerge: | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.actor.login == 'dependabot[bot]' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Automerge Dependabot PRs if all checks have passed | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_NUM: ${{ fromJSON(toJson(github.event.workflow_run.pull_requests))[0].number }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| echo "Attempting to merge PR #${PR_NUM} in ${REPO}" | |
| gh pr merge "$PR_NUM" --squash --admin | |
| Sync-patches-after-dependabot-automerge: | |
| needs: [dependabot-automerge] | |
| runs-on: ubuntu-latest | |
| env: | |
| RUN_E2E: ${{ vars.RUN_E2E }} # from repository settings -> Actions -> Variables | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: master | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 'lts/*' | |
| cache: 'npm' | |
| - name: Rename patch-package files to match current versions | |
| id: rename-patches | |
| shell: bash | |
| run: | | |
| shopt -s nullglob | |
| get_version() { | |
| jq -r ".dependencies[\"$1\"] // .devDependencies[\"$1\"]" package.json | |
| } | |
| CHANGED=0 | |
| for PATCH in patches/*.patch; do | |
| BASE=$(basename "$PATCH" .patch) | |
| NAME_WITHOUT_VERSION="${BASE%+*}" | |
| if [[ "$NAME_WITHOUT_VERSION" == @*+* ]]; then | |
| PACKAGE="${NAME_WITHOUT_VERSION/+//}" | |
| else | |
| PACKAGE="$NAME_WITHOUT_VERSION" | |
| fi | |
| VERSION=$(get_version "$PACKAGE") | |
| if [ "$VERSION" == "null" ]; then | |
| echo "Skipping $PACKAGE — not found in package.json" | |
| continue | |
| fi | |
| VERSION="${VERSION#^}" | |
| NEW_NAME="$(echo "$PACKAGE" | sed 's|/|+|g')+${VERSION}.patch" | |
| if [ "$BASE.patch" != "$NEW_NAME" ]; then | |
| echo "Renaming $BASE.patch -> $NEW_NAME" | |
| git mv "$PATCH" "patches/$NEW_NAME" | |
| CHANGED=1 | |
| fi | |
| done | |
| # Expose whether any files changed as a step output so it can be safely | |
| # referenced by later step `if` conditions without static analyzer warnings. | |
| echo "changed=$CHANGED" >> $GITHUB_OUTPUT | |
| - name: Install dependencies | |
| if: ${{ steps.rename-patches.outputs.changed == '1' }} | |
| run: npm ci | |
| - name: Run tests | |
| if: ${{ steps.rename-patches.outputs.changed == '1' }} | |
| run: npm test | |
| - name: Run e2e tests | |
| if: ${{ steps.rename-patches.outputs.changed == '1' && (env.RUN_E2E == 'true' || github.repository == 'sahat/hackathon-starter') }} | |
| run: npm run test:e2e:replay | |
| - name: Run e2e tests that don't require API keys against live APIs | |
| if: ${{ steps.rename-patches.outputs.changed == '1' && (env.RUN_E2E == 'true' || github.repository == 'sahat/hackathon-starter') }} | |
| run: npm run test:e2e:custom -- --project=chromium-nokey-live | |
| - name: Commit and push patch renames | |
| if: ${{ steps.rename-patches.outputs.changed == '1' }} | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| git add patches/ | |
| git commit -m "chore: sync patch-package filenames with current versions" | |
| git push |