diff --git a/.github/workflow-templates/dependabot-auto-merge.properties.json b/.github/workflow-templates/dependabot-auto-merge.properties.json new file mode 100644 index 00000000..72e17be3 --- /dev/null +++ b/.github/workflow-templates/dependabot-auto-merge.properties.json @@ -0,0 +1,6 @@ +{ + "name": "Dependabot Auto-Merge", + "description": "Automatically approves and squash-merges dependency update PRs that carry the 'automerge' label.", + "iconName": "example-icon", + "categories": ["Dependency management", "Continuous integration"] +} diff --git a/.github/workflow-templates/dependabot-auto-merge.yml b/.github/workflow-templates/dependabot-auto-merge.yml new file mode 100644 index 00000000..678e90c8 --- /dev/null +++ b/.github/workflow-templates/dependabot-auto-merge.yml @@ -0,0 +1,33 @@ +--- +name: Dependabot Auto-Merge + +# Automatically approves and enables auto-merge for dependabot/jules PRs +# that have the 'automerge' label. No unexpected auto-merges. + +# yamllint disable-line rule:truthy +on: pull_request + +permissions: + contents: read + +jobs: + auto-merge: + # Only run for dependabot or jules bots with the automerge label + if: >- + (github.actor == 'dependabot[bot]' + || github.actor == 'google-labs-jules[bot]') + && contains( + github.event.pull_request.labels.*.name, 'automerge') + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + pull-requests: write + contents: write + steps: + - name: Approve and enable auto-merge + run: | + gh pr review --approve "$PR_URL" + gh pr merge --auto --squash "$PR_URL" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/lib/__tests__/workflows.test.ts b/src/lib/__tests__/workflows.test.ts index 0317d3eb..1ef2936a 100644 --- a/src/lib/__tests__/workflows.test.ts +++ b/src/lib/__tests__/workflows.test.ts @@ -311,5 +311,30 @@ describe('GitHub Actions Workflows', () => { expect(properties.name).toBe('CI Pipeline') expect(properties.description.length).toBeGreaterThan(0) }) + + it('should have a valid dependabot-auto-merge template with properties file', () => { + const templatePath = join( + process.cwd(), + '.github/workflow-templates/dependabot-auto-merge.yml' + ) + expect(existsSync(templatePath)).toBe(true) + const template = parse(readFileSync(templatePath, 'utf-8')) + expect(template).toBeDefined() + expect(template.name).toBe('Dependabot Auto-Merge') + + const job = template.jobs['auto-merge'] + expect(job).toBeDefined() + expect(job.if).toContain('automerge') + + const propertiesPath = join( + process.cwd(), + '.github/workflow-templates/dependabot-auto-merge.properties.json' + ) + const properties = JSON.parse( + readFileSync(propertiesPath, 'utf-8') + ) as { name: string; description: string } + expect(properties.name).toBe('Dependabot Auto-Merge') + expect(properties.description.length).toBeGreaterThan(0) + }) }) }) \ No newline at end of file