Skip to content

Commit e599ef2

Browse files
authored
Merge pull request #128 from NTUT-NPC/checkbox-controlled-deploys
2 parents 5e80b65 + dee9c2d commit e599ef2

File tree

1 file changed

+97
-22
lines changed

1 file changed

+97
-22
lines changed

.github/workflows/pr-preview.yaml

Lines changed: 97 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ on:
1212
description: 'Specific commit SHA to build (overrides branch)'
1313
required: false
1414
type: string
15-
skip_upload:
16-
description: 'Build without uploading or bumping build number'
15+
deploy_android:
16+
description: 'Deploy Android to Firebase App Distribution'
17+
required: false
18+
type: boolean
19+
default: true
20+
deploy_ios:
21+
description: 'Deploy iOS to TestFlight'
1722
required: false
1823
type: boolean
1924
default: false
@@ -36,7 +41,6 @@ jobs:
3641
# so this output may be an empty string. This is intentional; all downstream uses of
3742
# needs.prepare.outputs.comment_id are guarded by the same pull_request-only condition.
3843
comment_id: ${{ steps.create.outputs.comment-id }}
39-
skip_upload: ${{ steps.flags.outputs.skip_upload }}
4044
target_ref: ${{ steps.set-ref.outputs.ref }}
4145
steps:
4246
- name: Checkout Actions
@@ -57,18 +61,7 @@ jobs:
5761
with:
5862
ref: ${{ steps.set-ref.outputs.ref }}
5963

60-
- name: Check for skip-upload flag
61-
id: flags
62-
run: |
63-
COMMIT_MSG="$(git show -s --format=%B)"
64-
if [[ "$COMMIT_MSG" == *"[skip upload]"* ]] || [[ "${{ inputs.skip_upload }}" == "true" ]]; then
65-
echo "skip_upload=true" >> $GITHUB_OUTPUT
66-
else
67-
echo "skip_upload=false" >> $GITHUB_OUTPUT
68-
fi
69-
7064
- name: Manage Build Number
71-
if: steps.flags.outputs.skip_upload != 'true'
7265
id: build-number
7366
uses: ./.github/actions/manage-build-number
7467
with:
@@ -83,17 +76,37 @@ jobs:
8376
build_number: ${{ steps.build-number.outputs.build_number || vars.build_number }}
8477

8578
- name: Find existing comment
86-
if: github.event_name == 'pull_request' && steps.flags.outputs.skip_upload != 'true'
79+
if: github.event_name == 'pull_request'
8780
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
8881
id: find-comment
8982
with:
9083
issue-number: ${{ github.event.pull_request.number }}
9184
comment-author: github-actions[bot]
9285
body-includes: <!-- pr-preview-comment -->
9386

87+
- name: Read existing deploy checkboxes
88+
id: checkboxes
89+
if: github.event_name == 'pull_request'
90+
env:
91+
COMMENT_BODY: ${{ steps.find-comment.outputs.comment-body }}
92+
run: |
93+
ANDROID="x"
94+
IOS=" "
95+
BODY="$COMMENT_BODY"
96+
if [ -n "$BODY" ]; then
97+
if echo "$BODY" | grep -q '<!-- deploy-android -->'; then
98+
[[ "$BODY" =~ \[x\]\ \<\!--\ deploy-android ]] && ANDROID="x" || ANDROID=" "
99+
fi
100+
if echo "$BODY" | grep -q '<!-- deploy-ios -->'; then
101+
[[ "$BODY" =~ \[x\]\ \<\!--\ deploy-ios ]] && IOS="x" || IOS=" "
102+
fi
103+
fi
104+
echo "android=$ANDROID" >> $GITHUB_OUTPUT
105+
echo "ios=$IOS" >> $GITHUB_OUTPUT
106+
94107
- name: Create or update initial comment
95108
id: create
96-
if: github.event_name == 'pull_request' && steps.flags.outputs.skip_upload != 'true'
109+
if: github.event_name == 'pull_request'
97110
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
98111
with:
99112
comment-id: ${{ steps.find-comment.outputs.comment-id }}
@@ -104,6 +117,10 @@ jobs:
104117
**Build Number:** ${{ steps.build-number.outputs.build_number }}
105118
**Commit:** ${{ steps.summary.outputs.sha }}
106119
**Message:** ${{ steps.summary.outputs.message }}
120+
121+
### Deploy
122+
- [${{ steps.checkboxes.outputs.android }}] <!-- deploy-android --> Android (Firebase App Distribution)
123+
- [${{ steps.checkboxes.outputs.ios }}] <!-- deploy-ios --> iOS (TestFlight)
107124
edit-mode: replace
108125

109126
android:
@@ -131,22 +148,51 @@ jobs:
131148
with:
132149
platform: android
133150

151+
- name: Find preview comment
152+
if: github.event_name == 'pull_request'
153+
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
154+
id: find-comment
155+
with:
156+
issue-number: ${{ github.event.pull_request.number }}
157+
comment-author: github-actions[bot]
158+
body-includes: <!-- pr-preview-comment -->
159+
160+
- name: Check deploy checkbox
161+
id: check-deploy
162+
env:
163+
COMMENT_BODY: ${{ steps.find-comment.outputs.comment-body }}
164+
run: |
165+
BODY="$COMMENT_BODY"
166+
if [ -z "$BODY" ]; then
167+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.deploy_android }}" != "false" ]; then
168+
echo "skip_upload=false" >> $GITHUB_OUTPUT
169+
else
170+
echo "skip_upload=true" >> $GITHUB_OUTPUT
171+
fi
172+
exit 0
173+
fi
174+
if echo "$BODY" | grep -q '\[x\] <!-- deploy-android -->'; then
175+
echo "skip_upload=false" >> $GITHUB_OUTPUT
176+
else
177+
echo "skip_upload=true" >> $GITHUB_OUTPUT
178+
fi
179+
134180
- name: Build and upload to Firebase App Distribution
135181
id: upload
136182
env:
137183
FIREBASEAPPDISTRO_APP: ${{ secrets.FIREBASEAPPDISTRO_APP }}
138-
run: bundle exec fastlane android preview skip_upload:${{ needs.prepare.outputs.skip_upload }}
184+
run: bundle exec fastlane android preview skip_upload:${{ steps.check-deploy.outputs.skip_upload }}
139185

140186
- name: Write Android Job Summary
141-
if: needs.prepare.outputs.skip_upload != 'true'
187+
if: steps.check-deploy.outputs.skip_upload != 'true'
142188
uses: ./.github/actions/android-summary
143189
with:
144190
build_number: ${{ needs.prepare.outputs.build_number }}
145191
type: 'firebase'
146192
testing_uri: ${{ steps.upload.outputs.testing_uri }}
147193

148194
- name: Update comment with Android build
149-
if: github.event_name == 'pull_request' && needs.prepare.outputs.skip_upload != 'true'
195+
if: github.event_name == 'pull_request' && steps.check-deploy.outputs.skip_upload != 'true'
150196
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
151197
with:
152198
comment-id: ${{ needs.prepare.outputs.comment_id }}
@@ -190,17 +236,46 @@ jobs:
190236
cd ios && bundle exec pod install
191237
git diff --exit-code Podfile.lock
192238
239+
- name: Find preview comment
240+
if: github.event_name == 'pull_request'
241+
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
242+
id: find-comment
243+
with:
244+
issue-number: ${{ github.event.pull_request.number }}
245+
comment-author: github-actions[bot]
246+
body-includes: <!-- pr-preview-comment -->
247+
248+
- name: Check deploy checkbox
249+
id: check-deploy
250+
env:
251+
COMMENT_BODY: ${{ steps.find-comment.outputs.comment-body }}
252+
run: |
253+
BODY="$COMMENT_BODY"
254+
if [ -z "$BODY" ]; then
255+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.deploy_ios }}" != "false" ]; then
256+
echo "skip_upload=false" >> $GITHUB_OUTPUT
257+
else
258+
echo "skip_upload=true" >> $GITHUB_OUTPUT
259+
fi
260+
exit 0
261+
fi
262+
if echo "$BODY" | grep -q '\[x\] <!-- deploy-ios -->'; then
263+
echo "skip_upload=false" >> $GITHUB_OUTPUT
264+
else
265+
echo "skip_upload=true" >> $GITHUB_OUTPUT
266+
fi
267+
193268
- name: Build and Upload to TestFlight
194-
run: bundle exec fastlane ios beta skip_upload:${{ needs.prepare.outputs.skip_upload }}
269+
run: bundle exec fastlane ios beta skip_upload:${{ steps.check-deploy.outputs.skip_upload }}
195270

196271
- name: Write iOS Job Summary
197-
if: needs.prepare.outputs.skip_upload != 'true'
272+
if: steps.check-deploy.outputs.skip_upload != 'true'
198273
uses: ./.github/actions/ios-summary
199274
with:
200275
build_number: ${{ needs.prepare.outputs.build_number }}
201276

202277
- name: Update comment with iOS build
203-
if: github.event_name == 'pull_request' && needs.prepare.outputs.skip_upload != 'true'
278+
if: github.event_name == 'pull_request' && steps.check-deploy.outputs.skip_upload != 'true'
204279
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
205280
with:
206281
comment-id: ${{ needs.prepare.outputs.comment_id }}

0 commit comments

Comments
 (0)