@@ -30,44 +30,51 @@ jobs:
30
30
private-key : ' ${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
31
31
owner : ' ${{ env.FLUX_OWNER }}'
32
32
repositories : ' ${{ env.FLUX_REPO }}'
33
+
33
34
- name : Checkout Flux repo
34
35
uses : actions/checkout@v4
35
36
with :
36
37
repository : ' ${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
37
38
token : ' ${{ steps.app-token.outputs.token }}'
38
39
path : flux-repo
39
40
persist-credentials : false
41
+
40
42
- name : Export PR ID
41
- run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
42
43
shell : bash
44
+ run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
45
+
43
46
- name : Ensure template exists
47
+ shell : bash
44
48
run : >
45
49
T="flux-repo/pr-template/${APP_NAME}"
46
50
47
51
[[ -d "$T" ]] || { echo "Missing $T"; exit 1; }
48
52
49
53
[[ $(find "$T" -type f | wc -l) -gt 0 ]] || { echo "No files in $T";
50
54
exit 1; }
51
- shell : bash
55
+
52
56
- name : Render & copy template
57
+ shell : bash
53
58
run : |
54
59
SRC="flux-repo/pr-template/${APP_NAME}"
55
60
DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
56
61
mkdir -p "$DST"
57
62
cp -r "$SRC/." "$DST/"
58
63
find "$DST" -type f -print0 \
59
64
| xargs -0 -n1 sed -i "s|@PR-ID@|${PR_ID}|g"
60
- shell : bash
65
+
61
66
- name : Sanity‑check rendered output
67
+ shell : bash
62
68
run : >
63
69
E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l)
64
70
65
71
G=$(find "flux-repo/deployments/prs-${APP_NAME}/${PR_ID}" -type f | wc
66
72
-l)
67
73
68
74
(( G == E )) || { echo "Expected $E files, got $G"; exit 1; }
69
- shell : bash
75
+
70
76
- name : Commit & push creation
77
+ shell : bash
71
78
run : >
72
79
cd flux-repo
73
80
@@ -84,13 +91,22 @@ jobs:
84
91
git remote set-url origin \
85
92
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
86
93
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/
88
105
89
106
remove-pr-env :
90
107
if : >-
91
108
(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')
94
110
runs-on : ubuntu-latest
95
111
steps :
96
112
- name : Create GitHub App token
@@ -101,17 +117,21 @@ jobs:
101
117
private-key : ' ${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
102
118
owner : ' ${{ env.FLUX_OWNER }}'
103
119
repositories : ' ${{ env.FLUX_REPO }}'
120
+
104
121
- name : Checkout Flux repo
105
122
uses : actions/checkout@v4
106
123
with :
107
124
repository : ' ${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
108
125
token : ' ${{ steps.app-token.outputs.token }}'
109
126
path : flux-repo
110
127
persist-credentials : false
128
+
111
129
- name : Export PR ID
112
- run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
113
130
shell : bash
131
+ run : ' echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
132
+
114
133
- name : Remove deployed directory
134
+ shell : bash
115
135
run : |
116
136
DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
117
137
if [[ -d "$DST" ]]; then
@@ -120,8 +140,9 @@ jobs:
120
140
else
121
141
echo "⏭️ Nothing to delete at $DST"
122
142
fi
123
- shell : bash
143
+
124
144
- name : Commit & push deletion
145
+ shell : bash
125
146
run : >
126
147
cd flux-repo
127
148
@@ -138,4 +159,13 @@ jobs:
138
159
git remote set-url origin \
139
160
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
140
161
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