@@ -30,44 +30,51 @@ jobs:
3030 private-key : ' ${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
3131 owner : ' ${{ env.FLUX_OWNER }}'
3232 repositories : ' ${{ env.FLUX_REPO }}'
33+
3334 - name : Checkout Flux repo
3435 uses : actions/checkout@v4
3536 with :
3637 repository : ' ${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
3738 token : ' ${{ steps.app-token.outputs.token }}'
3839 path : flux-repo
3940 persist-credentials : false
41+
4042 - name : Export PR ID
41- run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
4243 shell : bash
44+ run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
45+
4346 - name : Ensure template exists
47+ shell : bash
4448 run : >
4549 T="flux-repo/pr-template/${APP_NAME}"
4650
4751 [[ -d "$T" ]] || { echo "Missing $T"; exit 1; }
4852
4953 [[ $(find "$T" -type f | wc -l) -gt 0 ]] || { echo "No files in $T";
5054 exit 1; }
51- shell : bash
55+
5256 - name : Render & copy template
57+ shell : bash
5358 run : |
5459 SRC="flux-repo/pr-template/${APP_NAME}"
5560 DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
5661 mkdir -p "$DST"
5762 cp -r "$SRC/." "$DST/"
5863 find "$DST" -type f -print0 \
5964 | xargs -0 -n1 sed -i "s|@PR-ID@|${PR_ID}|g"
60- shell : bash
65+
6166 - name : Sanity‑check rendered output
67+ shell : bash
6268 run : >
6369 E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l)
6470
6571 G=$(find "flux-repo/deployments/prs-${APP_NAME}/${PR_ID}" -type f | wc
6672 -l)
6773
6874 (( G == E )) || { echo "Expected $E files, got $G"; exit 1; }
69- shell : bash
75+
7076 - name : Commit & push creation
77+ shell : bash
7178 run : >
7279 cd flux-repo
7380
@@ -84,13 +91,22 @@ jobs:
8491 git remote set-url origin \
8592 https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
8693 git push origin HEAD:main
87- shell : bash
94+
95+ - name : Comment preview URL on PR
96+ uses : thollander/actions-comment-pull-request@v3
97+ with :
98+ github-token : ' ${{ secrets.GITHUB_TOKEN }}'
99+ pr-number : ' ${{ github.event.pull_request.number }}'
100+ comment-tag : ' pr-preview'
101+ create-if-not-exists : ' true'
102+ message : |
103+ ⚙️ Preview environment for PR #${{ env.PR_ID }} is available at:
104+ https://pr-${{ env.PR_ID }}.${{ env.APP_NAME }}.coderamp.dev/
88105
89106 remove-pr-env :
90107 if : >-
91108 (github.event.action == 'unlabeled' && github.event.label.name ==
92- 'deploy-pr-temp-env') || (github.event.action == 'closed' &&
93- github.event.pull_request.merged == true)
109+ 'deploy-pr-temp-env') || (github.event.action == 'closed')
94110 runs-on : ubuntu-latest
95111 steps :
96112 - name : Create GitHub App token
@@ -101,17 +117,21 @@ jobs:
101117 private-key : ' ${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
102118 owner : ' ${{ env.FLUX_OWNER }}'
103119 repositories : ' ${{ env.FLUX_REPO }}'
120+
104121 - name : Checkout Flux repo
105122 uses : actions/checkout@v4
106123 with :
107124 repository : ' ${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
108125 token : ' ${{ steps.app-token.outputs.token }}'
109126 path : flux-repo
110127 persist-credentials : false
128+
111129 - name : Export PR ID
112- run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
113130 shell : bash
131+ run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
132+
114133 - name : Remove deployed directory
134+ shell : bash
115135 run : |
116136 DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
117137 if [[ -d "$DST" ]]; then
@@ -120,8 +140,9 @@ jobs:
120140 else
121141 echo "⏭️ Nothing to delete at $DST"
122142 fi
123- shell : bash
143+
124144 - name : Commit & push deletion
145+ shell : bash
125146 run : >
126147 cd flux-repo
127148
@@ -138,4 +159,13 @@ jobs:
138159 git remote set-url origin \
139160 https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
140161 git push origin HEAD:main
141- shell : bash
162+
163+ - name : Comment preview URL on PR
164+ uses : thollander/actions-comment-pull-request@v3
165+ with :
166+ github-token : ' ${{ secrets.GITHUB_TOKEN }}'
167+ pr-number : ' ${{ github.event.pull_request.number }}'
168+ comment-tag : ' pr-preview'
169+ create-if-not-exists : ' true'
170+ message : |
171+ ⚙️ Preview environment was undeployed.
0 commit comments