-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependabot-post-update.yaml
More file actions
59 lines (53 loc) · 2.25 KB
/
dependabot-post-update.yaml
File metadata and controls
59 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Dependabot Post-Update
permissions:
contents: write # so the commit can be pushed
actions: write # so createWorkflowDispatch can be invoked
on:
pull_request:
types: [opened, synchronize]
branches:
- main
jobs:
post-update:
if: ${{ github.actor == 'dependabot[bot]' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4.2.2
with:
persist-credentials: true # (default) makes GITHUB_TOKEN available for git push
fetch-depth: 1 # Fetch tip commit so we can push back
ref: ${{ github.event.pull_request.head.ref }} # Check out the head ref of the PR instead of detached HEAD
- name: Configure Git author
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Update devcontainer hash
run: python3 .github/workflows/hash_git_files.py . --for-devcontainer-config-update --exit-zero
- name: Commit & push changes
id: commit
run: |
if ! git diff --quiet; then
git add .
git commit -m "chore: apply post-Dependabot script changes [dependabot skip]"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
echo "pushed=true" >> $GITHUB_OUTPUT
else
echo "pushed=false" >> $GITHUB_OUTPUT
fi
- name: Dispatch CI on PR branch # pushes done by GITHUB_TOKEN don't trigger workflows, so we have to restart the CI job manually, see https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
if: steps.commit.outputs.pushed == 'true'
uses: actions/github-script@v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
if (!pr) {
throw new Error("No pull_request found in payload; aborting dispatch.");
}
await github.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "ci.yaml",
ref: pr.head.ref,
});