Skip to content

Commit d51cc69

Browse files
committed
template: Update auto-dependabot workflow to use an app token
To be able to enable auto-merge effectively, we need to use an external auth token to interact with GitHub, otherwise no events are produced when using the Action's provided token, and the merge never happens (either because the auto-merging doesn't trigger, or because the PR is queued but no CI is run on the queue so it times out). This job now requires the repo having a APP ID and PRIVATE KEY to generate a token to do the auto-merging and approving. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 5e92c63 commit d51cc69

7 files changed

Lines changed: 73 additions & 12 deletions

File tree

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/auto-dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ on:
44
pull_request:
55

66
permissions:
7-
contents: write
7+
contents: read
88
pull-requests: write
99

1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
1313
runs-on: ubuntu-slim
1414
steps:
15+
- name: Generate GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
18+
with:
19+
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
20+
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
21+
1522
- name: Auto-merge Dependabot PR
1623
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2
1724
with:
18-
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
github-token: ${{ steps.app-token.outputs.token }}
1926
dependency-type: 'all'
2027
auto-merge: 'true'
2128
merge-method: 'merge'

docs/user-guide/start-a-new-project/configure-github.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ Import the following
115115

116116
* Enable *Dependabot version updates* if relevant
117117

118+
#### Auto-merge Dependabot PRs (GitHub App)
119+
120+
The templates include an `.github/workflows/auto-dependabot.yaml` workflow that
121+
auto-approves and enables auto-merge for Dependabot PRs.
122+
123+
This workflow uses a GitHub App installation token (not `GITHUB_TOKEN`). This is
124+
intentional: actions performed with `GITHUB_TOKEN` do not trigger certain
125+
follow-up workflow runs, which can prevent merge queue CI (`merge_group`) from
126+
starting.
127+
128+
To make it work, ensure:
129+
130+
* The GitHub App is installed on the repository.
131+
* The following secrets are available to the workflow (typically as org secrets):
132+
`FREQUENZ_AUTO_DEPENDABOT_APP_ID` and `FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY`.
133+
* The app installation has sufficient repository permissions to approve/label
134+
and enable auto-merge. In practice, this means at least `Pull requests: write`
135+
and `Contents: write`.
136+
118137
## Code
119138

120139
The basic code configuration should be generate using

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/auto-dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ on:
44
pull_request:
55

66
permissions:
7-
contents: write
7+
contents: read
88
pull-requests: write
99

1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
1313
runs-on: ubuntu-slim
1414
steps:
15+
- name: Generate GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
18+
with:
19+
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
20+
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
21+
1522
- name: Auto-merge Dependabot PR
1623
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2
1724
with:
18-
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
github-token: ${{ steps.app-token.outputs.token }}
1926
dependency-type: 'all'
2027
auto-merge: 'true'
2128
merge-method: 'merge'

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/.github/workflows/auto-dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ on:
44
pull_request:
55

66
permissions:
7-
contents: write
7+
contents: read
88
pull-requests: write
99

1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
1313
runs-on: ubuntu-slim
1414
steps:
15+
- name: Generate GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
18+
with:
19+
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
20+
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
21+
1522
- name: Auto-merge Dependabot PR
1623
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2
1724
with:
18-
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
github-token: ${{ steps.app-token.outputs.token }}
1926
dependency-type: 'all'
2027
auto-merge: 'true'
2128
merge-method: 'merge'

tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/.github/workflows/auto-dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ on:
44
pull_request:
55

66
permissions:
7-
contents: write
7+
contents: read
88
pull-requests: write
99

1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
1313
runs-on: ubuntu-slim
1414
steps:
15+
- name: Generate GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
18+
with:
19+
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
20+
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
21+
1522
- name: Auto-merge Dependabot PR
1623
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2
1724
with:
18-
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
github-token: ${{ steps.app-token.outputs.token }}
1926
dependency-type: 'all'
2027
auto-merge: 'true'
2128
merge-method: 'merge'

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/.github/workflows/auto-dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ on:
44
pull_request:
55

66
permissions:
7-
contents: write
7+
contents: read
88
pull-requests: write
99

1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
1313
runs-on: ubuntu-slim
1414
steps:
15+
- name: Generate GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
18+
with:
19+
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
20+
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
21+
1522
- name: Auto-merge Dependabot PR
1623
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2
1724
with:
18-
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
github-token: ${{ steps.app-token.outputs.token }}
1926
dependency-type: 'all'
2027
auto-merge: 'true'
2128
merge-method: 'merge'

tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/.github/workflows/auto-dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@ on:
44
pull_request:
55

66
permissions:
7-
contents: write
7+
contents: read
88
pull-requests: write
99

1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
1313
runs-on: ubuntu-slim
1414
steps:
15+
- name: Generate GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
18+
with:
19+
app-id: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_ID }}
20+
private-key: ${{ secrets.FREQUENZ_AUTO_DEPENDABOT_APP_PRIVATE_KEY }}
21+
1522
- name: Auto-merge Dependabot PR
1623
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2
1724
with:
18-
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
github-token: ${{ steps.app-token.outputs.token }}
1926
dependency-type: 'all'
2027
auto-merge: 'true'
2128
merge-method: 'merge'

0 commit comments

Comments
 (0)