Skip to content

Commit

Permalink
github: use github app to have a token for creating pull requests
Browse files Browse the repository at this point in the history
This then allows for triggering workflows
  • Loading branch information
ahayzen committed Apr 5, 2024
1 parent f3763fe commit 12d8fcd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

name: auto merge

on: pull_request_target
on:
pull_request_target:
workflow_dispatch:

permissions:
pull-requests: write
Expand All @@ -16,7 +18,7 @@ jobs:
# Auto merge if this is
# - dependabot
# - update of flake.lock
if: "${{ github.event.pull_request.user.login == 'dependabot[bot]' || (github.event.pull_request.user.login == 'github-actions[bot]' && github.event.pull_request.title == 'chore: update flake.lock') }}"
if: "${{ github.event.pull_request.user.login == 'dependabot[bot]' || (github.event.pull_request.user.login == 'ahayzen-nix-config-bot' && github.event.pull_request.title == 'chore: update flake.lock') }}"
steps:
- name: approve the pr
run: gh pr review $PR_URL --approve
Expand Down
43 changes: 13 additions & 30 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,27 @@ on:
- cron: '1 22 * * *'
workflow_dispatch:

permissions:
# So that we can trigger the workflow
actions: write
# So that a pull request and commit can be created
pull-requests: write
contents: write

jobs:
lock-updater:
name: nix flake update
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v10
- uses: DeterminateSystems/update-flake-lock@v21
with:
pr-title: "chore: update flake.lock"

# We need to manually trigger CI status checks
# as github prevents workflows automatically running to prevent loops
- name: trigger ci status checks
uses: actions/github-script@v6
# Github action workflows can't trigger another workflow
# so we need to have a different token to do this
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs
#
# Using a Github app allows us a token limited to this repo
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens
- uses: actions/create-github-app-token@v1
id: generate-token
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'check.yml',
ref: 'update_flake_lock_action',
})
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}

- name: trigger auto merge
uses: actions/github-script@v6
- uses: DeterminateSystems/update-flake-lock@v21
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'auto-merge.yml',
ref: 'update_flake_lock_action',
})
pr-title: "chore: update flake.lock"
token: ${{ steps.generate-token.outputs.token }}

0 comments on commit 12d8fcd

Please sign in to comment.