Skip to content

Commit 7fc1194

Browse files
committed
ci: add custom system comment for Cloudflare Pages deployments
1 parent c1db965 commit 7fc1194

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed

.github/workflows/automation.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@ on:
77
pull_request_target:
88

99
jobs:
10+
comment:
11+
name: Create system comments 🖥️
12+
if: ${{ github.event_name == 'pull_request_target'}}
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Create job summary and add to environment
16+
id: msg
17+
env:
18+
COMMIT: ${{ github.sha }}
19+
BRANCH_URL: https://${{ github.head_ref }}.jf-vue.pages.dev
20+
run: |
21+
echo "## Cloudflare Pages deployment" > $GITHUB_STEP_SUMMARY
22+
echo "" >> $GITHUB_STEP_SUMMARY
23+
echo "| **Latest commit** | <code>$COMMIT</code> |" >> $GITHUB_STEP_SUMMARY
24+
echo "|------------------------- |:----------------------------: |" >> $GITHUB_STEP_SUMMARY
25+
echo "| **Status** | 🔄 Deploying... |" >> $GITHUB_STEP_SUMMARY
26+
echo "| **Preview URL** | Not available yet |" >> $GITHUB_STEP_SUMMARY
27+
echo "| **Branch Preview URL:** | $BRANCH_URL |" >> $GITHUB_STEP_SUMMARY
28+
echo "" >> $GITHUB_STEP_SUMMARY
29+
echo "<!--- CFPages deployment marker --->" >> $GITHUB_STEP_SUMMARY
30+
COMPOSED_MSG=$(cat $GITHUB_STEP_SUMMARY)
31+
echo "msg=$COMPOSED_MSG" >> $GITHUB_ENV
32+
33+
- name: Create CF Pages deployment comment
34+
uses: thollander/[email protected]
35+
with:
36+
GITHUB_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
37+
message: ${{ env.msg }}
38+
comment_includes: '<!--- CFPages deployment marker --->'
39+
1040
project:
1141
name: Project board 📊
1242
runs-on: ubuntu-latest

.github/workflows/deploy.yml

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ on:
1616
description: Name of the branch that it's being deployed
1717
required: true
1818
type: string
19+
commit_id:
20+
description: Commit ID that triggered the workflow
21+
required: true
22+
type: string
1923

2024
jobs:
2125
cf-pages:
2226
name: CloudFlare Pages 📃
2327
runs-on: ubuntu-latest
24-
if: ${{ (inputs.workflow_run_id && inputs.branch) || github.event.workflow_run.conclusion == 'success' }}
28+
if: ${{ (inputs.workflow_run_id != '' && inputs.branch != '' && inputs.commit_id != '') || github.event.workflow_run.conclusion == 'success' }}
2529

2630
steps:
2731
- name: Download workflow artifact ⬇️
2832
uses: dawidd6/[email protected]
2933
with:
30-
run_id: ${{ inputs.workflow_run_id || github.event.workflow_run.id }}
34+
run_id: ${{ inputs.workflow_run_id != '' && inputs.workflow_run_id || github.event.workflow_run.id }}
3135
name: frontend
3236
path: dist
3337

@@ -39,10 +43,63 @@ jobs:
3943
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
4044
projectName: jf-vue
4145
directory: dist
42-
branch: ${{ inputs.branch || github.event.workflow_run.head_branch }}
46+
branch: ${{ inputs.branch != '' && inputs.branch || github.event.workflow_run.head_branch }}
4347
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
4448

45-
- name: Create job summary 📖
49+
- name: Create job summary and add to environment
50+
id: msg
51+
env:
52+
COMMIT: ${{ inputs.commit_id != '' && inputs.commit_id || github.event.workflow_run.head_commit.id }}
53+
BRANCH_URL: https://${{ inputs.branch != '' && inputs.branch || github.event.workflow_run.head_branch }}.jf-vue.pages.dev
4654
run: |
47-
echo '# CloudFlare Pages deployment' >> $GITHUB_STEP_SUMMARY
48-
echo '${{ steps.cf.outputs.url }}' >> $GITHUB_STEP_SUMMARY
55+
echo "## Cloudflare Pages deployment" > $GITHUB_STEP_SUMMARY
56+
echo "" >> $GITHUB_STEP_SUMMARY
57+
echo "| **Latest commit** | <code>$COMMIT</code> |" >> $GITHUB_STEP_SUMMARY
58+
echo "|------------------------- |:----------------------------: |" >> $GITHUB_STEP_SUMMARY
59+
echo "| **Status** | ✅ Deployed! |" >> $GITHUB_STEP_SUMMARY
60+
echo "| **Preview URL** | ${{ steps.cf.outputs.url }} |" >> $GITHUB_STEP_SUMMARY
61+
echo "| **Branch Preview URL:** | $BRANCH_URL |" >> $GITHUB_STEP_SUMMARY
62+
echo "" >> $GITHUB_STEP_SUMMARY
63+
echo "<!--- CFPages deployment marker --->" >> $GITHUB_STEP_SUMMARY
64+
COMPOSED_MSG=$(cat $GITHUB_STEP_SUMMARY)
65+
echo "msg=$COMPOSED_MSG" >> $GITHUB_ENV
66+
67+
- name: Update CF Pages deployment comment
68+
uses: thollander/[email protected]
69+
with:
70+
GITHUB_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
71+
message: ${{ env.msg }}
72+
pr_number: ${{ github.event.workflow_run.pull_requests[0].number }}
73+
comment_includes: '<!--- CFPages deployment marker --->'
74+
75+
comment:
76+
name: Update system comment status
77+
runs-on: ubuntu-latest
78+
if: ${{ github.event.workflow_run.conclusion != 'success' || failure() }}
79+
80+
steps:
81+
- name: Create job summary and add to environment
82+
id: msg
83+
env:
84+
COMMIT: ${{ github.event.workflow_run.head_commit.id }}
85+
BRANCH_URL: https://${{ github.event.workflow_run.head_branch }}.jf-vue.pages.dev
86+
run: |
87+
echo "## Cloudflare Pages deployment" > $GITHUB_STEP_SUMMARY
88+
echo "" >> $GITHUB_STEP_SUMMARY
89+
echo "| **Latest commit** | <code>$COMMIT</code> |" >> $GITHUB_STEP_SUMMARY
90+
echo "|------------------------- |:----------------------------: |" >> $GITHUB_STEP_SUMMARY
91+
echo "| **Status** | ❌ Failure. Check workflow logs for more info |" >> $GITHUB_STEP_SUMMARY
92+
echo "| **Preview URL** | Not available |" >> $GITHUB_STEP_SUMMARY
93+
echo "| **Branch Preview URL:** | $BRANCH_URL |" >> $GITHUB_STEP_SUMMARY
94+
echo "" >> $GITHUB_STEP_SUMMARY
95+
echo "<!--- CFPages deployment marker --->" >> $GITHUB_STEP_SUMMARY
96+
COMPOSED_MSG=$(cat $GITHUB_STEP_SUMMARY)
97+
echo "msg=$COMPOSED_MSG" >> $GITHUB_ENV
98+
99+
- name: Update CF Pages deployment comment
100+
uses: thollander/[email protected]
101+
with:
102+
GITHUB_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
103+
message: ${{ env.msg }}
104+
pr_number: ${{ github.event.workflow_run.pull_requests[0].number }}
105+
comment_includes: '<!--- CFPages deployment marker --->'

.github/workflows/unstable.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@ jobs:
141141
with:
142142
workflow_run_id: ${{ github.run_id }}
143143
branch: ${{ github.head_ref }}
144+
commit_id: ${{ github.sha }}

0 commit comments

Comments
 (0)