Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 1cbf2b8

Browse files
authored
ci(build): add artifact download comment (#22)
1 parent 0c0d06d commit 1cbf2b8

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

.github/workflows/build.yml

+66-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
hdiutil create -volname "InjectGUI" -srcfolder "build/Build/Products/${{ env.APP_CONF }}/InjectGUI.app" -ov -format UDZO "InjectGUI.dmg"
5757
cp "InjectGUI.dmg" "$RUNNER_TEMP/InjectGUI.dmg"
5858
- name: Upload DMG Artifact
59+
id: upload-artifact
5960
uses: actions/upload-artifact@v4
6061
with:
6162
name: InjectGUI
@@ -110,4 +111,68 @@ jobs:
110111
uses: actions/upload-artifact@v4
111112
with:
112113
name: appcast.xml
113-
path: "${{ RUNNER.TEMP }}/Sparkle_Archive/appcast.xml"
114+
path: "${{ RUNNER.TEMP }}/Sparkle_Archive/appcast.xml"
115+
116+
- name: Find Comment
117+
if: github.event_name == 'pull_request'
118+
uses: peter-evans/find-comment@v3
119+
id: fc
120+
with:
121+
issue-number: ${{ github.event.pull_request.number }}
122+
comment-author: 'github-actions[bot]'
123+
body-includes: 'InjectGUI'
124+
125+
- name: Gen Previous Builds List
126+
if: github.event_name == 'pull_request'
127+
run: |
128+
shas_and_links=$(echo "${{ steps.fc.outputs.comment-body }}" | sed -n 's/.*\[\([^!][^]]*\)\].*/\1/p')
129+
result_list=""
130+
IFS=',' # 设置内部字段分隔符为逗号
131+
for entry in $shas_and_links; do
132+
sha=$(echo "$entry" | cut -d';' -f1)
133+
link=$(echo "$entry" | cut -d';' -f2)
134+
result_list+="<sup><li><a href='${link}'>${sha}</a></li></sup>"
135+
done
136+
137+
echo "PREVIOUS_BUILDS=${result_list}" >> $GITHUB_ENV
138+
139+
- name: Add new build to Previous Builds List
140+
if: github.event_name == 'pull_request'
141+
run: |
142+
new_sha="${{github.sha}}"
143+
new_link="${{ steps.upload-artifact.outputs.artifact-id }}"
144+
new_link="https://github.com/wibus-wee/InjectGUI/actions/runs/${{ github.run_id }}/artifacts/${new_link}"
145+
comment_body="${{ steps.fc.outputs.comment-body }}"
146+
147+
if [ -z "$new_link" ]; then
148+
echo "Artifact URL is empty. Skipping update."
149+
else
150+
shas_and_links=$(echo "$comment_body" | sed -n 's/.*\[\([^!][^]]*\)\].*/\1/p')
151+
shas_and_links="${shas_and_links},[${new_sha};${new_link}]"
152+
echo "NEW_COMMENT_LIST=${shas_and_links}" >> $GITHUB_ENV
153+
fi
154+
155+
- name: Create Pull Request Comment
156+
if: github.event_name == 'pull_request'
157+
uses: peter-evans/create-or-update-comment@v4
158+
with:
159+
edit-mode: replace
160+
comment-id: ${{ steps.fc.outputs.comment-id }}
161+
issue-number: ${{ github.event.pull_request.number }}
162+
body: |
163+
Hi, thanks for your contribution!
164+
165+
**InjectGUI** (${{ github.sha }}) has been built and is available for download to test. (Based on PR ${{ github.event.pull_request.number }})
166+
167+
You can download the latest artifact from here: https://github.com/wibus-wee/InjectGUI/actions/runs/${{ github.run_id }}/artifacts/${{ steps.upload-artifact.outputs.artifact-id }}
168+
169+
> [!WARNING]
170+
> This is a PR build and may not be stable. It's only for testing purposes.
171+
172+
---
173+
174+
<!--${{ env.NEW_COMMENT_LIST }}-->
175+
176+
<sup>Previous builds:</sup>
177+
178+
${{ env.PREVIOUS_BUILDS }}

0 commit comments

Comments
 (0)