Skip to content

Commit 9540607

Browse files
authored
Merge pull request #1 from gitgitgadget-workflows/migrate-gitgitgadget-to-github-actions
Migrate GitGitGadget to GitHub Actions
2 parents 371afac + 52c2c9d commit 9540607

File tree

5 files changed

+315
-0
lines changed

5 files changed

+315
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Handle new mails
2+
3+
on:
4+
# GitGitGadget's GitHub App is expected to trigger this on `git-mailing-list-mirror` updates
5+
workflow_dispatch:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}
9+
10+
jobs:
11+
handle-new-mails:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/create-github-app-token@v1
16+
id: gitgitgadget-git-token
17+
with:
18+
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
19+
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
20+
owner: gitgitgadget
21+
repositories: git
22+
- uses: actions/create-github-app-token@v1
23+
id: git-git-token
24+
with:
25+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
26+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
27+
owner: git
28+
repositories: git
29+
- uses: actions/create-github-app-token@v1
30+
id: dscho-git-token
31+
with:
32+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
33+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
34+
owner: dscho
35+
repositories: git
36+
- uses: gitgitgadget/gitgitgadget/handle-new-mails@v1
37+
with:
38+
pr-repo-token: ${{ steps.gitgitgadget-git-token.outputs.token }}
39+
upstream-repo-token: ${{ steps.git-git-token.outputs.token }}
40+
test-repo-token: ${{ steps.dscho-git-token.outputs.token }}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Handle a PR comment
2+
run-name: Handle slash command in a PR comment`
3+
4+
on:
5+
# GitGitGadget's GitHub App is expected to trigger this on `issue_comment` events
6+
# that have the `action` set to `created` or `edited`
7+
workflow_dispatch:
8+
inputs:
9+
pr-comment-url:
10+
description: 'URL of the PR comment to handle'
11+
required: true
12+
13+
env:
14+
PR_COMMENT_URL: ${{ inputs.pr-comment-url }}
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ inputs.pr-comment-url }}
18+
19+
jobs:
20+
handle-pr-comment:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/create-github-app-token@v1
25+
id: gitgitgadget-git-token
26+
with:
27+
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
28+
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
29+
owner: gitgitgadget
30+
repositories: git
31+
- uses: actions/create-github-app-token@v1
32+
id: git-git-token
33+
with:
34+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
35+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
36+
owner: git
37+
repositories: git
38+
- uses: actions/create-github-app-token@v1
39+
id: dscho-git-token
40+
with:
41+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
42+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
43+
owner: dscho
44+
repositories: git
45+
- name: create a check run
46+
id: create-check-run
47+
run: |
48+
title="Handle PR comment"
49+
summary="Handling PR comment $PR_COMMENT_URL"
50+
details_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
51+
text="This handles $PR_COMMENT_URL, see $details_url for details."
52+
echo "title=$title" >> $GITHUB_OUTPUT
53+
echo "summary=$summary" >> $GITHUB_OUTPUT
54+
echo "text=$text" >> $GITHUB_OUTPUT
55+
56+
PR_NUMBER="${PR_COMMENT_URL%#*}" # skip the suffix with the comment ID
57+
PR_NUMBER="${PR_NUMBER##*/}" # skip the prefix before the PR number
58+
59+
export GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
60+
eval "$(gh api repos/gitgitgadget/git/pulls/$PR_NUMBER \
61+
--jq '"head_sha=\(.head.sha) && repo=\(.base.repo.full_name)"')"
62+
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
63+
echo "repo=$repo" >> $GITHUB_OUTPUT
64+
65+
export GH_TOKEN="$(case "$repo" in
66+
gitgitgadget/git) echo "${{ steps.gitgitgadget-git-token.outputs.token }}";;
67+
git/git) echo "${{ steps.git-git-token.outputs.token }}";;
68+
dscho/git) echo "${{ steps.dscho-git-token.outputs.token }}";;
69+
*) echo "${{ secrets.GITHUB_TOKEN }}";;
70+
esac
71+
)"
72+
eval "$(gh api repos/$repo/check-runs -X POST \
73+
-f name='handle_pr_comment' \
74+
-f head_sha="$head_sha" \
75+
-f status='in_progress' \
76+
-f details_url="$details_url" \
77+
-f "output[title]=$title" \
78+
-f "output[summary]=$summary" \
79+
-f "output[text]=$text" \
80+
--jq '"check_run_id=\(.id)"')"
81+
echo "check_run_id=$check_run_id" >> $GITHUB_OUTPUT
82+
- uses: gitgitgadget/gitgitgadget/handle-pr-comment@v1
83+
with:
84+
pr-repo-token: ${{ steps.gitgitgadget-git-token.outputs.token }}
85+
upstream-repo-token: ${{ steps.git-git-token.outputs.token }}
86+
test-repo-token: ${{ steps.dscho-git-token.outputs.token }}
87+
smtp-host: smtp.gmail.com
88+
smtp-user: [email protected]
89+
smtp-pass: "${{ secrets.GITGITGADGET_SMTP_PASS }}"
90+
pr-comment-url: ${{ env.PR_COMMENT_URL }}
91+
- name: update the check run
92+
if: always() && steps.create-check-run.outputs.check_run_id != ''
93+
run: |
94+
export GH_TOKEN="$(case "${{ steps.create-check-run.outputs.repo }}" in
95+
gitgitgadget/git) echo "${{ steps.gitgitgadget-git-token.outputs.token }}";;
96+
git/git) echo "${{ steps.git-git-token.outputs.token }}";;
97+
dscho/git) echo "${{ steps.dscho-git-token.outputs.token }}";;
98+
*) echo "${{ secrets.GITHUB_TOKEN }}";;
99+
esac
100+
)"
101+
gh api repos/${{ steps.create-check-run.outputs.repo }}/check-runs/${{ steps.create-check-run.outputs.check_run_id }} \
102+
-X PATCH \
103+
-f status='completed' \
104+
-f conclusion='${{ job.status }}' \
105+
-f 'output[title]=${{ steps.create-check-run.outputs.title }}' \
106+
-f 'output[summary]=${{ steps.create-check-run.outputs.summary }}' \
107+
-f 'output[text]=${{ steps.create-check-run.outputs.text }}'
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Handle pushes to PRs
2+
run-name: Check and validate commits pushed to a PR
3+
4+
on:
5+
# GitGitGadget's GitHub App is expected to trigger this on `pull_request` events
6+
# that have the `action` set to `opened` or `synchronize`
7+
workflow_dispatch:
8+
inputs:
9+
pr-url:
10+
description: 'URL of the PR to handle'
11+
required: true
12+
13+
env:
14+
PR_URL: ${{ inputs.pr-url }}
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ inputs.pr-url }}
18+
19+
jobs:
20+
handle-pr-push:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/create-github-app-token@v1
25+
id: gitgitgadget-git-token
26+
with:
27+
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
28+
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
29+
owner: gitgitgadget
30+
repositories: git
31+
- uses: actions/create-github-app-token@v1
32+
id: git-git-token
33+
with:
34+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
35+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
36+
owner: git
37+
repositories: git
38+
- uses: actions/create-github-app-token@v1
39+
id: dscho-git-token
40+
with:
41+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
42+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
43+
owner: dscho
44+
repositories: git
45+
- name: create a check run
46+
id: create-check-run
47+
run: |
48+
title="Handle PR push"
49+
summary="Handling new commits in $PR_URL"
50+
details_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
51+
text="This handles $PR_URL, see $details_url for details."
52+
echo "title=$title" >> $GITHUB_OUTPUT
53+
echo "summary=$summary" >> $GITHUB_OUTPUT
54+
echo "text=$text" >> $GITHUB_OUTPUT
55+
56+
PR_NUMBER="${PR_URL##*/}" # skip the prefix before the PR number
57+
58+
export GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
59+
eval "$(gh api repos/gitgitgadget/git/pulls/$PR_NUMBER \
60+
--jq '"head_sha=\(.head.sha) && repo=\(.base.repo.full_name)"')"
61+
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
62+
echo "repo=$repo" >> $GITHUB_OUTPUT
63+
64+
export GH_TOKEN="$(case "$repo" in
65+
gitgitgadget/git) echo "${{ steps.gitgitgadget-git-token.outputs.token }}";;
66+
git/git) echo "${{ steps.git-git-token.outputs.token }}";;
67+
dscho/git) echo "${{ steps.dscho-git-token.outputs.token }}";;
68+
*) echo "${{ secrets.GITHUB_TOKEN }}";;
69+
esac
70+
)"
71+
eval "$(gh api repos/$repo/check-runs -X POST \
72+
-f name='handle_pr_push' \
73+
-f head_sha="$head_sha" \
74+
-f status='in_progress' \
75+
-f details_url="$details_url" \
76+
-f "output[title]=$title" \
77+
-f "output[summary]=$summary" \
78+
-f "output[text]=$text" \
79+
--jq '"check_run_id=\(.id)"')"
80+
echo "check_run_id=$check_run_id" >> $GITHUB_OUTPUT
81+
- uses: gitgitgadget/gitgitgadget/handle-pr-push@v1
82+
with:
83+
pr-repo-token: ${{ steps.gitgitgadget-git-token.outputs.token }}
84+
upstream-repo-token: ${{ steps.git-git-token.outputs.token }}
85+
test-repo-token: ${{ steps.dscho-git-token.outputs.token }}
86+
pr-url: ${{ env.PR_URL }}
87+
- name: update the check run
88+
if: always() && steps.create-check-run.outputs.check_run_id != ''
89+
run: |
90+
export GH_TOKEN="$(case "${{ steps.create-check-run.outputs.repo }}" in
91+
gitgitgadget/git) echo "${{ steps.gitgitgadget-git-token.outputs.token }}";;
92+
git/git) echo "${{ steps.git-git-token.outputs.token }}";;
93+
dscho/git) echo "${{ steps.dscho-git-token.outputs.token }}";;
94+
*) echo "${{ secrets.GITHUB_TOKEN }}";;
95+
esac
96+
)"
97+
gh api repos/${{ steps.create-check-run.outputs.repo }}/check-runs/${{ steps.create-check-run.outputs.check_run_id }} \
98+
-X PATCH \
99+
-f status='completed' \
100+
-f conclusion='${{ job.status }}' \
101+
-f 'output[title]=${{ steps.create-check-run.outputs.title }}' \
102+
-f 'output[summary]=${{ steps.create-check-run.outputs.summary }}' \
103+
-f 'output[text]=${{ steps.create-check-run.outputs.text }}'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Update Mail to Commit Notes
2+
run-name: Update the `mail-to-commit` and `commit-to-mail` Git notes
3+
4+
on:
5+
# GitGitGadget's GitHub App is expected to trigger this on `seen` updates
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}
10+
11+
jobs:
12+
update-mail-to-commit-notes:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/create-github-app-token@v1
17+
id: gitgitgadget-git-token
18+
with:
19+
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
20+
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
21+
owner: gitgitgadget
22+
repositories: git
23+
- uses: gitgitgadget/gitgitgadget/update-mail-to-commit-notes@v1
24+
with:
25+
pr-repo-token: ${{ steps.gitgitgadget-git-token.outputs.token }}

.github/workflows/update-prs.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Update GitGitGadget's PRs
2+
3+
on:
4+
# GitGitGadget's GitHub App is expected to trigger this on `seen` updates
5+
workflow_dispatch:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}
9+
10+
jobs:
11+
update-prs:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/create-github-app-token@v1
16+
id: gitgitgadget-git-token
17+
with:
18+
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
19+
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
20+
owner: gitgitgadget
21+
repositories: git
22+
- uses: actions/create-github-app-token@v1
23+
id: git-git-token
24+
with:
25+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
26+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
27+
owner: git
28+
repositories: git
29+
- uses: actions/create-github-app-token@v1
30+
id: dscho-git-token
31+
with:
32+
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
33+
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
34+
owner: dscho
35+
repositories: git
36+
- uses: gitgitgadget/gitgitgadget/update-prs@v1
37+
with:
38+
pr-repo-token: ${{ steps.gitgitgadget-git-token.outputs.token }}
39+
upstream-repo-token: ${{ steps.git-git-token.outputs.token }}
40+
test-repo-token: ${{ steps.dscho-git-token.outputs.token }}

0 commit comments

Comments
 (0)