Skip to content

Commit ceb52ae

Browse files
committed
ci/merge: add pr-merged workflow
Will be used for notifying when new plugins are added. Currently it is mostly printing info to the markdown summary.
1 parent ee0f56f commit ceb52ae

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

.github/workflows/pr-merged.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: PR Merged
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
merged:
12+
name: Show info
13+
if: github.event.pull_request.merged == true
14+
runs-on: ubuntu-24.04-arm
15+
steps:
16+
# github.event.pull_request.base may not refer to the _actual_ parent commit of the PR,
17+
# instead it is the commit that the PR was merged/rebased onto.
18+
#
19+
# Since we want to diff the PR's commits, query the first commit's first parent.
20+
#
21+
# Alternatively, we could compare
22+
# github.event.pull_request.merge_commit_sha to github.event.pull_request.base.sha,
23+
# however I'm unsure how that'll interact with grouped Merge Queue 🤔
24+
- name: Get base commit
25+
id: base
26+
env:
27+
GH_TOKEN: ${{ github.token }}
28+
owner: ${{ github.repository_owner }}
29+
repo: ${{ github.event.repository.name }}
30+
pr: ${{ github.event.pull_request.number }}
31+
run: |
32+
out=$(mktemp)
33+
gh api graphql -F owner="$owner" -F repo="$repo" -F pr="$pr" -f query='
34+
query($owner: String!, $repo: String!, $pr: Int!) {
35+
repository(owner: $owner, name: $repo) {
36+
pullRequest(number: $pr) {
37+
commits(first: 1) {
38+
edges {
39+
node {
40+
commit {
41+
parents(first: 1) {
42+
edges {
43+
node {
44+
oid
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
' --jq '
56+
.data
57+
.repository
58+
.pullRequest
59+
.commits
60+
.edges[0]
61+
.node
62+
.commit
63+
.parents
64+
.edges[0]
65+
.node
66+
.oid
67+
' > "$out"
68+
echo "sha=$(cat "$out")" >> "$GITHUB_OUTPUT"
69+
70+
# Checkout CI scripts from the latest commit from the base branch.
71+
# This ensures we get the latest scripts, even if the PR's base was outdated.
72+
- name: Checkout base branch
73+
id: checkout
74+
uses: actions/checkout@v4
75+
with:
76+
sparse-checkout: flake/dev/diff-plugins.py
77+
sparse-checkout-cone-mode: false
78+
79+
- name: Install Nix
80+
uses: cachix/install-nix-action@v31
81+
with:
82+
nix_path: nixpkgs=channel:nixpkgs-unstable
83+
extra_nix_config: |
84+
accept-flake-config = true
85+
86+
# NOTE: This is here for debugging and gathering data
87+
# TODO: Remove
88+
- name: Print metadata
89+
env:
90+
checked_out: ${{ steps.checkout.outputs.commit }}
91+
workflow_base: ${{ github.base_ref }}
92+
workflow_head: ${{ github.head_ref }}
93+
parent: ${{ steps.base.outputs.sha }}
94+
base: ${{ github.event.pull_request.base.sha }}
95+
head: ${{ github.event.pull_request.head.sha }}
96+
merge: ${{ github.event.pull_request.merge_commit_sha }}
97+
pull_request: ${{ toJSON(github.event.pull_request) }}
98+
run: |
99+
{
100+
echo '## Commits'
101+
echo
102+
echo "Checked out: $checked_out"
103+
echo "Workflow base: $workflow_base"
104+
echo "Workflow head: $workflow_head"
105+
echo "PR parent: $parent"
106+
echo "Base: $base"
107+
echo "Head: $head"
108+
echo "Merge: $merge"
109+
echo
110+
echo '<details><summary><code>pull_request</code> details</summary>'
111+
echo
112+
echo '```json'
113+
echo "$pull_request" | jq .
114+
echo '```'
115+
echo
116+
echo '</details>'
117+
echo
118+
} >> "$GITHUB_STEP_SUMMARY"
119+
120+
- name: Compare parent -> head
121+
id: diff1
122+
env:
123+
base: ${{ steps.base.outputs.sha }}
124+
head: ${{ github.event.pull_request.head.sha }}
125+
run: |
126+
out=$(mktemp)
127+
./flake/dev/diff-plugins.py --compact "$base" "$head" > "$out"
128+
{
129+
echo -n 'json='
130+
jq -c . < "$out"
131+
} >> "$GITHUB_OUTPUT"
132+
jq . < "$out"
133+
134+
- name: Compare base -> merge
135+
id: diff2
136+
env:
137+
base: ${{ github.event.pull_request.base.sha }}
138+
head: ${{ github.event.pull_request.merge_commit_sha }}
139+
run: |
140+
out=$(mktemp)
141+
./flake/dev/diff-plugins.py --compact "$base" "$head" > "$out"
142+
{
143+
echo -n 'json='
144+
jq -c . < "$out"
145+
} >> "$GITHUB_OUTPUT"
146+
jq . < "$out"
147+
148+
- name: Print summary
149+
env:
150+
json1: ${{ steps.diff1.outputs.json }}
151+
json2: ${{ steps.diff2.outputs.json }}
152+
run: |
153+
{
154+
echo '## JSON plugin diff: parent -> head'
155+
echo
156+
echo '```json'
157+
echo "$json1" | jq .
158+
echo '```'
159+
echo
160+
echo '## JSON plugin diff: base -> merge'
161+
echo
162+
echo '```json'
163+
echo "$json2" | jq .
164+
echo '```'
165+
echo
166+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)