@@ -24,7 +24,7 @@ concurrency:
24
24
cancel-in-progress : true
25
25
26
26
env :
27
- APP_NAME : qa-react-webpack-rails-tutorial-pr -${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
27
+ APP_NAME : ${{ vars.REVIEW_APP_PREFIX }} -${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
28
28
CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
29
29
CPLN_ORG : ${{ vars.CPLN_ORG_STAGING }}
30
30
PR_NUMBER : ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
@@ -62,27 +62,61 @@ jobs:
62
62
with :
63
63
fetch-depth : 0
64
64
65
+ - name : Validate Required Secrets and Variables
66
+ shell : bash
67
+ run : |
68
+ missing=()
69
+
70
+ # Check secrets
71
+ if [ -z "${{ secrets.CPLN_TOKEN_STAGING }}" ]; then
72
+ missing+=("Secret: CPLN_TOKEN_STAGING")
73
+ fi
74
+
75
+ # Check variables
76
+ if [ -z "${{ vars.CPLN_ORG_STAGING }}" ]; then
77
+ missing+=("Variable: CPLN_ORG_STAGING")
78
+ fi
79
+
80
+ if [ -z "${{ vars.REVIEW_APP_PREFIX }}" ]; then
81
+ missing+=("Variable: REVIEW_APP_PREFIX")
82
+ fi
83
+
84
+ if [ ${#missing[@]} -ne 0 ]; then
85
+ echo "Required secrets/variables are not set: ${missing[*]}"
86
+ exit 1
87
+ fi
88
+
65
89
- name : Get PR HEAD Ref
66
90
id : getRef
67
91
env :
68
92
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69
93
run : |
70
- if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
71
- PR_NUMBER="${{ github.event.inputs.pr }}"
72
- elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
73
- PR_NUMBER="${{ github.event.issue.number }}"
74
- elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
75
- PR_NUMBER="${{ github.event.pull_request.number }}"
76
- elif [[ "${{ github.event_name }}" == "push" ]]; then
77
- # For push events, find associated PR
78
- PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number')
79
- if [[ -n "$PR_DATA" ]]; then
80
- PR_NUMBER="$PR_DATA"
81
- else
82
- echo "Error: No PR found for branch ${{ github.ref_name }}"
94
+ # Get PR number based on event type
95
+ case "${{ github.event_name }}" in
96
+ "workflow_dispatch")
97
+ PR_NUMBER="${{ github.event.inputs.pr_number }}"
98
+ ;;
99
+ "issue_comment")
100
+ PR_NUMBER="${{ github.event.issue.number }}"
101
+ ;;
102
+ "pull_request")
103
+ PR_NUMBER="${{ github.event.pull_request.number }}"
104
+ ;;
105
+ "push")
106
+ # For push events, find associated PR
107
+ PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number')
108
+ if [[ -n "$PR_DATA" ]]; then
109
+ PR_NUMBER="$PR_DATA"
110
+ else
111
+ echo "Error: No PR found for branch ${{ github.ref_name }}"
112
+ exit 1
113
+ fi
114
+ ;;
115
+ *)
116
+ echo "Error: Unsupported event type ${{ github.event_name }}"
83
117
exit 1
84
- fi
85
- fi
118
+ ;;
119
+ esac
86
120
87
121
if [[ -z "$PR_NUMBER" ]]; then
88
122
echo "Error: Could not determine PR number"
91
125
92
126
# Set environment variables
93
127
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
94
- echo "APP_NAME=qa-react-webpack-rails-tutorial-pr -$PR_NUMBER" >> $GITHUB_ENV
128
+ echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }} -$PR_NUMBER" >> $GITHUB_ENV
95
129
96
130
# Get PR data using GitHub CLI
97
131
PR_DATA=$(gh pr view $PR_NUMBER --repo shakacode/react-webpack-rails-tutorial --json headRefName,headRefOid)
@@ -150,6 +184,7 @@ jobs:
150
184
- name : Create Initial Comment
151
185
if : env.DO_DEPLOY != 'false'
152
186
uses : actions/github-script@v7
187
+ id : create-comment
153
188
with :
154
189
script : |
155
190
const result = await github.rest.issues.createComment({
@@ -160,6 +195,26 @@ jobs:
160
195
});
161
196
core.setOutput('comment-id', result.data.id);
162
197
198
+ - name : Update Comment - Building
199
+ if : env.DO_DEPLOY != 'false'
200
+ uses : actions/github-script@v7
201
+ with :
202
+ script : |
203
+ const buildingMessage = [
204
+ `🏗️ Building Docker image for PR #${process.env.PR_NUMBER}, commit ${process.env.PR_SHA}`,
205
+ '',
206
+ `📝 [View Build Logs](${process.env.WORKFLOW_URL})`,
207
+ '',
208
+ process.env.CONSOLE_LINK
209
+ ].join('\n');
210
+
211
+ await github.rest.issues.updateComment({
212
+ owner: context.repo.owner,
213
+ repo: context.repo.repo,
214
+ comment_id: ${{ steps.create-comment.outputs.comment-id }},
215
+ body: buildingMessage
216
+ });
217
+
163
218
- name : Set Deployment URLs
164
219
id : set-urls
165
220
if : env.DO_DEPLOY != 'false'
@@ -189,7 +244,7 @@ jobs:
189
244
with :
190
245
script : |
191
246
const buildingMessage = [
192
- '🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}' ,
247
+ '🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + process. env.PR_SHA ,
193
248
'',
194
249
'📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
195
250
'',
0 commit comments