Skip to content

Commit cab8e8d

Browse files
committed
chore(gh-action): create comment action
1 parent 5113561 commit cab8e8d

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Comment on the pull request the artifact url
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Publish artifacts"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
upload:
11+
runs-on: ubuntu-latest
12+
if: >
13+
github.event.workflow_run.event == 'pull_request' &&
14+
github.event.workflow_run.conclusion == 'success'
15+
steps:
16+
# - name: 'Download artifact'
17+
# uses: actions/github-script@v6
18+
# with:
19+
# script: |
20+
# let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
21+
# owner: context.repo.owner,
22+
# repo: context.repo.repo,
23+
# run_id: context.payload.workflow_run.id,
24+
# });
25+
# let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
26+
# return artifact.name == "pr_number"
27+
# })[0];
28+
# let download = await github.rest.actions.downloadArtifact({
29+
# owner: context.repo.owner,
30+
# repo: context.repo.repo,
31+
# artifact_id: matchArtifact.id,
32+
# archive_format: 'zip',
33+
# });
34+
# let fs = require('fs');
35+
# fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
36+
# - name: 'Download artifact'
37+
# uses: actions/[email protected]
38+
# with:
39+
# script: |
40+
# var artifacts = await github.actions.listWorkflowRunArtifacts({
41+
# owner: context.repo.owner,
42+
# repo: context.repo.repo,
43+
# run_id: ${{github.event.workflow_run.id }},
44+
# });
45+
# var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
46+
# print(artifact.name);
47+
# return artifact.name == "limeAppBuild"
48+
# })[0];
49+
# print(matchArtifact);
50+
# var download = await github.actions.downloadArtifact({
51+
# owner: context.repo.owner,
52+
# repo: context.repo.repo,
53+
# artifact_id: matchArtifact.id,
54+
# archive_format: 'zip',
55+
# });
56+
# var fs = require('fs');
57+
# fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
58+
# - run: unzip pr.zip
59+
# - name: 'Comment on PR'
60+
# uses: actions/github-script@v3
61+
# with:
62+
# github-token: ${{ secrets.GITHUB_TOKEN }}
63+
# script: |
64+
# var fs = require('fs');
65+
# var issue_number = Number(fs.readFileSync('./NR'));
66+
# await github.issues.createComment({
67+
# owner: context.repo.owner,
68+
# repo: context.repo.repo,
69+
# issue_number: issue_number,
70+
# body: 'Everything is OK. Thank you for the PR!'
71+
# });
72+
73+
- run: |
74+
echo "Downloading artifact"
75+
echo ${{github.event.workflow_run.id }}
76+
echo ${{github.event.workflow_run.artifacts_url }}
77+
echo ${{github.event.workflow_run.pull_requests[0].url }}
78+
- uses: actions/download-artifact@v4
79+
with:
80+
github-token: ${{ secrets.GITHUB_TOKEN }}
81+
run-id: ${{github.event.workflow_run.id }}
82+
83+
- name: Get PR number
84+
run: echo "PR_NUM=$(ls limeAppBuild/pr_number)" >> $GITHUB_ENV
85+
- name: Display structure of downloaded files
86+
run: ls -R
87+
- name: Test
88+
run: echo $PR_NUM
89+
90+
- name: Find a PR comment
91+
uses: peter-evans/find-comment@v2
92+
id: fc
93+
with:
94+
issue-number: ${{ env.PR_NUM }}
95+
body-includes: 'Artifacts deployed: '
96+
- name: Delete Comment
97+
uses: actions/github-script@v6
98+
continue-on-error: true
99+
if: steps.fc.outputs.comment-id != 0
100+
with:
101+
script: |
102+
github.rest.issues.deleteComment({
103+
comment_id: ${{ steps.fc.outputs.comment-id }},
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
})
107+
108+
- name: Update the PR comment
109+
uses: peter-evans/create-or-update-comment@v2
110+
with:
111+
issue-number: ${{ env.PR_NUM }}
112+
body: |
113+
Artifacts deployed: ${{github.event.workflow_run.artifacts_url }}

0 commit comments

Comments
 (0)