Skip to content

Commit 56cccb9

Browse files
committed
ci: comment preview URLs for PR deploy/undeploy events (+lint)
1 parent 83fb274 commit 56cccb9

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

.github/workflows/deploy-pr.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,54 @@ jobs:
2929
app-id: '${{ secrets.CR_APP_CI_APP_ID }}'
3030
private-key: '${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
3131
owner: '${{ env.FLUX_OWNER }}'
32-
repositories: '${{ env.FLUX_REPO }}'
32+
repositories: |
33+
'${{ env.FLUX_REPO }}'
34+
gitingest
35+
3336
- name: Checkout Flux repo
3437
uses: actions/checkout@v4
3538
with:
3639
repository: '${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
3740
token: '${{ steps.app-token.outputs.token }}'
3841
path: flux-repo
3942
persist-credentials: false
43+
4044
- name: Export PR ID
41-
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
4245
shell: bash
46+
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
47+
4348
- name: Ensure template exists
49+
shell: bash
4450
run: >
4551
T="flux-repo/pr-template/${APP_NAME}"
4652
4753
[[ -d "$T" ]] || { echo "Missing $T"; exit 1; }
4854
4955
[[ $(find "$T" -type f | wc -l) -gt 0 ]] || { echo "No files in $T";
5056
exit 1; }
51-
shell: bash
57+
5258
- name: Render & copy template
59+
shell: bash
5360
run: |
5461
SRC="flux-repo/pr-template/${APP_NAME}"
5562
DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
5663
mkdir -p "$DST"
5764
cp -r "$SRC/." "$DST/"
5865
find "$DST" -type f -print0 \
5966
| xargs -0 -n1 sed -i "s|@PR-ID@|${PR_ID}|g"
60-
shell: bash
67+
6168
- name: Sanity‑check rendered output
69+
shell: bash
6270
run: >
6371
E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l)
6472
6573
G=$(find "flux-repo/deployments/prs-${APP_NAME}/${PR_ID}" -type f | wc
6674
-l)
6775
6876
(( G == E )) || { echo "Expected $E files, got $G"; exit 1; }
69-
shell: bash
77+
7078
- name: Commit & push creation
79+
shell: bash
7180
run: >
7281
cd flux-repo
7382
@@ -84,7 +93,17 @@ jobs:
8493
git remote set-url origin \
8594
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
8695
git push origin HEAD:main
87-
shell: bash
96+
97+
- name: Comment preview URL on PR
98+
uses: thollander/actions-comment-pull-request@v3
99+
with:
100+
github-token: '${{ steps.app-token.outputs.token }}'
101+
pr-number: '${{ github.event.pull_request.number }}'
102+
comment-tag: 'pr-preview'
103+
create-if-not-exists: 'true'
104+
message: |
105+
⚙️ Preview environment for PR #${{ env.PR_ID }} is available at:
106+
https://pr-${{ env.PR_ID }}.${{ env.APP_NAME }}.coderamp.dev/
88107
89108
remove-pr-env:
90109
if: >-
@@ -100,18 +119,24 @@ jobs:
100119
app-id: '${{ secrets.CR_APP_CI_APP_ID }}'
101120
private-key: '${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
102121
owner: '${{ env.FLUX_OWNER }}'
103-
repositories: '${{ env.FLUX_REPO }}'
122+
repositories: |
123+
'${{ env.FLUX_REPO }}'
124+
gitingest
125+
104126
- name: Checkout Flux repo
105127
uses: actions/checkout@v4
106128
with:
107129
repository: '${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
108130
token: '${{ steps.app-token.outputs.token }}'
109131
path: flux-repo
110132
persist-credentials: false
133+
111134
- name: Export PR ID
112-
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
113135
shell: bash
136+
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
137+
114138
- name: Remove deployed directory
139+
shell: bash
115140
run: |
116141
DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
117142
if [[ -d "$DST" ]]; then
@@ -120,8 +145,9 @@ jobs:
120145
else
121146
echo "⏭️ Nothing to delete at $DST"
122147
fi
123-
shell: bash
148+
124149
- name: Commit & push deletion
150+
shell: bash
125151
run: >
126152
cd flux-repo
127153
@@ -138,4 +164,13 @@ jobs:
138164
git remote set-url origin \
139165
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
140166
git push origin HEAD:main
141-
shell: bash
167+
168+
- name: Comment preview URL on PR
169+
uses: thollander/actions-comment-pull-request@v3
170+
with:
171+
github-token: '${{ steps.app-token.outputs.token }}'
172+
pr-number: '${{ github.event.pull_request.number }}'
173+
comment-tag: 'pr-preview'
174+
create-if-not-exists: 'true'
175+
message: |
176+
⚙️ Preview environment was undeployed.

0 commit comments

Comments
 (0)