@@ -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
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 : ' ${{ steps.app-token.outputs.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 : >-
@@ -101,17 +118,21 @@ jobs:
101118 private-key : ' ${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
102119 owner : ' ${{ env.FLUX_OWNER }}'
103120 repositories : ' ${{ env.FLUX_REPO }}'
121+
104122 - name : Checkout Flux repo
105123 uses : actions/checkout@v4
106124 with :
107125 repository : ' ${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
108126 token : ' ${{ steps.app-token.outputs.token }}'
109127 path : flux-repo
110128 persist-credentials : false
129+
111130 - name : Export PR ID
112- run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
113131 shell : bash
132+ run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
133+
114134 - name : Remove deployed directory
135+ shell : bash
115136 run : |
116137 DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
117138 if [[ -d "$DST" ]]; then
@@ -120,8 +141,9 @@ jobs:
120141 else
121142 echo "⏭️ Nothing to delete at $DST"
122143 fi
123- shell : bash
144+
124145 - name : Commit & push deletion
146+ shell : bash
125147 run : >
126148 cd flux-repo
127149
@@ -138,4 +160,13 @@ jobs:
138160 git remote set-url origin \
139161 https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
140162 git push origin HEAD:main
141- shell : bash
163+
164+ - name : Comment preview URL on PR
165+ uses : thollander/actions-comment-pull-request@v3
166+ with :
167+ github-token : ' ${{ steps.app-token.outputs.token }}'
168+ pr-number : ' ${{ github.event.pull_request.number }}'
169+ comment-tag : ' pr-preview'
170+ create-if-not-exists : ' true'
171+ message : |
172+ ⚙️ Preview environment was undeployed.
0 commit comments