Skip to content

Commit b581dea

Browse files
committed
Automate verified content updates
1 parent f7fd230 commit b581dea

4 files changed

Lines changed: 71 additions & 6 deletions

File tree

.github/workflows/community-stats.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ on:
66
workflow_dispatch:
77

88
permissions:
9-
contents: write
10-
pull-requests: write
9+
contents: read
1110

1211
jobs:
1312
update-community:
@@ -27,9 +26,17 @@ jobs:
2726
- name: Fetch Discourse activity
2827
run: node .github/scripts/fetch-discourse-activity.js
2928

29+
- name: Create GitHub App token
30+
id: app-token
31+
uses: actions/create-github-app-token@v3
32+
with:
33+
client-id: ${{ vars.AUTOMATION_APP_CLIENT_ID }}
34+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
35+
3036
- name: Create pull request for updated community stats
3137
uses: peter-evans/create-pull-request@v8.1.1
3238
with:
39+
token: ${{ steps.app-token.outputs.token }}
3340
add-paths: data/community_stats.json
3441
branch: automation/update-community-stats
3542
commit-message: Update community stats

.github/workflows/meetup-sync.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ on:
66
workflow_dispatch:
77

88
permissions:
9-
contents: write
10-
pull-requests: write
9+
contents: read
1110

1211
concurrency:
1312
group: sync-meetup-events
@@ -28,9 +27,17 @@ jobs:
2827
- name: Sync upcoming Meetup events
2928
run: node .github/scripts/sync-meetup-events.mjs
3029

30+
- name: Create GitHub App token
31+
id: app-token
32+
uses: actions/create-github-app-token@v3
33+
with:
34+
client-id: ${{ vars.AUTOMATION_APP_CLIENT_ID }}
35+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
36+
3137
- name: Create pull request for synchronized events
3238
uses: peter-evans/create-pull-request@v8.1.1
3339
with:
40+
token: ${{ steps.app-token.outputs.token }}
3441
add-paths: |
3542
content/calendar
3643
branch: automation/sync-meetup-events
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Merge Verified Automation Pull Requests
2+
3+
on:
4+
workflow_run:
5+
workflows: [Build Hugo Site]
6+
types: [completed]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
merge:
13+
if: >-
14+
github.event.workflow_run.conclusion == 'success' &&
15+
github.event.workflow_run.event == 'pull_request' &&
16+
github.event.workflow_run.head_repository.full_name == github.repository &&
17+
(github.event.workflow_run.head_branch == 'automation/update-community-stats' ||
18+
github.event.workflow_run.head_branch == 'automation/sync-meetup-events' ||
19+
github.event.workflow_run.head_branch == 'automation/sync-podcast')
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Create GitHub App token
23+
id: app-token
24+
uses: actions/create-github-app-token@v3
25+
with:
26+
client-id: ${{ vars.AUTOMATION_APP_CLIENT_ID }}
27+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
28+
29+
- name: Merge the verified automation pull request
30+
env:
31+
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
32+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
33+
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
34+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
35+
run: |
36+
pull_request=$(gh pr view "$HEAD_BRANCH" --repo "$GITHUB_REPOSITORY" --json number,headRefOid,author,baseRefName,state)
37+
test "$(jq -r '.author.login' <<<"$pull_request")" = "${APP_SLUG}[bot]"
38+
test "$(jq -r '.baseRefName' <<<"$pull_request")" = main
39+
test "$(jq -r '.state' <<<"$pull_request")" = OPEN
40+
gh pr merge "$(jq -r '.number' <<<"$pull_request")" \
41+
--repo "$GITHUB_REPOSITORY" \
42+
--squash \
43+
--delete-branch \
44+
--match-head-commit "$HEAD_SHA"

.github/workflows/podcast-sync.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ on:
99
# episode could roll off the feed. See docs/adr/0003-incremental-podcast-sync.md.
1010

1111
permissions:
12-
contents: write
13-
pull-requests: write
12+
contents: read
1413

1514
jobs:
1615
sync-podcast:
@@ -30,9 +29,17 @@ jobs:
3029
- name: Sync podcast feed
3130
run: node .github/scripts/sync-podcast-feed.js
3231

32+
- name: Create GitHub App token
33+
id: app-token
34+
uses: actions/create-github-app-token@v3
35+
with:
36+
client-id: ${{ vars.AUTOMATION_APP_CLIENT_ID }}
37+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
38+
3339
- name: Create pull request for new episodes
3440
uses: peter-evans/create-pull-request@v8.1.1
3541
with:
42+
token: ${{ steps.app-token.outputs.token }}
3643
add-paths: |
3744
content/podcast
3845
branch: automation/sync-podcast

0 commit comments

Comments
 (0)