Skip to content

Commit c2830e9

Browse files
CI: Nightly Builds (#1612)
* add nightly builds CI * add if check comment, uncomment while pushing to upstream repo * add workflow_dispatch for testing * Update nightly-build.yml * add: envs for keystore & build json path, removal step for those * use caching for Gradle * Update apk path * add: workflow call, creation of nightly releases. and comments (if ran in PR) * fix: PREV_TAG messed up EOF 🙃 * fix: PR_NUMBER if condition * fix: (again) PR_NUMBER if condition * fix: UPDATED_VERSION bad substitution * fix: PR_NUMBER assignment * add(CI): community-release-notifier, nightly-build concurrency, on demand PR builds * add(CI): PR label removal for on demand Preview Releases CI * remove(CI): remove .github excluding from on-demand preview CI for testing * add(CI): checkout action for on-demand-preview-releases-PR.yml * fix(CI): workflow path for on-demand-preview-releases-PR.yml * add(CI): comments for on-demand-preview-releases-PR.yml * fix(CI): on-demand-preview-releases-PR CI running without satisfying run conditions * fix(CI): on-demand-preview-releases-PR CI env * refactor(CI): on-demand-preview-releases-PR to use `.outcome` instead of `failure()` * refactor(CI): on-demand-preview-releases-PR to use `.outcome` instead of `failure()` * fix(CI): on-demand-preview-releases-PR to use backslash backticks * chore: fetch-depth to 0 * chore: remove branch from reusable workflow * chore: add clean false to the checkout for on-demand-preview-releases-PR.yml * chore: add sha commit to the reusable workflow for on-demand-preview-releases-PR.yml * chore: add repo to the reusable workflow for on-demand-preview-releases-PR.yml * refactor: builder, update last comment step in separate jobs As GitHub doesn't like reusable workflows in steps * chore: update on-demand-preview-releases-PR.yml * chore: use `needs` for on-demand-preview-releases-PR.yml & expose nightly-build status via outputs * fix: concurrency group deadlock when triggered from on-demand Previews... CI * fix: concurrency group deadlock when triggered from on-demand Previews... CI * fix: concurrency group deadlock when triggered from on-demand Previews... CI * fix: secrets not found in on-demand-preview-releases-PR.yml * chore: update * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update on-demand-preview-releases-PR.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * Update community-release-notifier.yml * chore: add community-release-notifier to nightly-build.yml * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * Update(nightly-build): use sticky comment in case of PR. * Update nightly-build.yml * update(on-demand-preview-releases-PR): use sticky comments * Update nightly-build.yml * Update nightly-build.yml * Update nightly-build.yml * add: release outputs * Update nightly-build.yml * Update community-release-notifier.yml * Update nightly-build.yml * Update nightly-build.yml * Update community-release-notifier.yml * Update nightly-build.yml * Update on-demand-preview-releases-PR.yml * fix: on-demand PR builds CI's failure detection conditions * refactor(on-demand-ci): To use sticky comments for initial Informing of build status. * fix(on-demand-ci): job failure comment always triggering, uses `always()` alongside now. These commit fixes job failure comment always triggering and posting failure comments regardless if build workflow succeeds * chore: limit failure status (PR) comment to failure, cancelled types * chore: remove debug upstream result step (saving ~2-3s run time) * chore: update * chore: update * chore: update * chore: add if for releaseRequired in release-notifier for nightly-build.yml * chore: add if for releaseRequired in release-notifier for nightly-build.yml * chore: add if for releaseRequired in release-notifier for nightly-build.yml * chore: add check if release url is present before running community actions * chore: add Repo checks
1 parent d98d349 commit c2830e9

File tree

3 files changed

+363
-0
lines changed

3 files changed

+363
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: community-release-notifier
2+
on:
3+
release:
4+
types: [ released ]
5+
workflow_call:
6+
inputs:
7+
tag_name:
8+
required: true
9+
description: "Release tag_name"
10+
type: 'string'
11+
url:
12+
required: true
13+
description: "release URL"
14+
type: 'string'
15+
secrets:
16+
DISCORD_WEBHOOK_RELEASE_NOTES:
17+
description: 'Discord Webhook for Notifying Releases to Discord'
18+
required: true
19+
20+
jobs:
21+
discord-release:
22+
if: github.repository_owner == 'Acode-Foundation'
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Get Release Content
26+
id: get-release-content
27+
uses: 2428392/gh-truncate-string-action@b3ff790d21cf42af3ca7579146eedb93c8fb0757 # v1.4.1
28+
with:
29+
maxLength: 2000
30+
stringToTruncate: |
31+
📢 Acode [${{ github.event.release.tag_name || inputs.tag_name }}](<${{ github.event.release.url || inputs.url }}>) was just Released 🎉!
32+
33+
34+
- name: Discord Webhook Action (Publishing)
35+
uses: tsickert/discord-webhook@c840d45a03a323fbc3f7507ac7769dbd91bfb164 # v5.3.0
36+
with:
37+
webhook-url: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}
38+
content: ${{ steps.get-release-content.outputs.string }}
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
name: Nightly Build
2+
3+
on:
4+
schedule:
5+
# Fire every day at 7:00am UTC (Roughly before EU workday and after US workday)
6+
- cron: "0 7 * * *"
7+
push:
8+
tags:
9+
- nightly
10+
workflow_call:
11+
inputs:
12+
is_PR:
13+
default: false
14+
type: boolean
15+
description: If a Pull Request has triggered it.
16+
PR_NUMBER:
17+
required: true
18+
type: number
19+
description: The Pull Request that triggered this workflow
20+
skip_tagging_and_releases:
21+
required: false
22+
default: true
23+
type: boolean
24+
description: Skips Tagging & releases, since workflow_call isn't available for github.event_name, default is true
25+
outputs:
26+
job_result:
27+
description: "Build job result"
28+
value: ${{ jobs.build.result }}
29+
30+
workflow_dispatch:
31+
32+
concurrency:
33+
# Allow only one workflow per any non-`main` branch.
34+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}-${{ inputs.is_PR && 'is_PR' || 'not_PR'}}
35+
cancel-in-progress: true
36+
37+
env:
38+
STORE_FILE_PATH: /tmp/app-debug.keystore
39+
BUILD_JSON_PATH: build.json
40+
VERSION_LABEL: ${{ (inputs.is_PR && 'pr') || 'nightly' }}
41+
DISCORD_RELEASE_NOTIFIER_ENABLED: "true"
42+
jobs:
43+
build:
44+
timeout-minutes: 60
45+
runs-on: ubuntu-latest
46+
if: github.repository_owner == 'Acode-Foundation'
47+
48+
outputs:
49+
release_output_url: ${{ steps.release.outputs.url }}
50+
updated_version: ${{ steps.update-version.outputs.UPDATED_VERSION}}
51+
steps:
52+
- name: Fast Fail if secrets are missing
53+
if: ${{ env.KEYSTORE_CONTENT == '' || env.BUILD_JSON_CONTENT == '' }}
54+
env:
55+
KEYSTORE_CONTENT: ${{ secrets.KEYSTORE_CONTENT }}
56+
BUILD_JSON_CONTENT: ${{ secrets.BUILD_JSON_CONTENT }}
57+
run: |
58+
echo "::error title=Missing Secrets::KEYSTORE_CONTENT or BUILD_JSON_CONTENT secrets are missing! Aborting workflow."
59+
exit 1
60+
61+
- name: Logging & summaries
62+
run: |
63+
echo "::group::Logging"
64+
echo "🎯 github trigger event name: ${{ github.event_name }}"
65+
echo "is_PR: ${{ inputs.is_PR }} "
66+
echo "PR_NUMBER: ${{ inputs.PR_NUMBER }}"
67+
echo "env: STORE_FILE_PATH: ${{ env.STORE_FILE_PATH }}"
68+
echo "env: BUILD_JSON_PATH: ${{ env.BUILD_JSON_PATH }}"
69+
echo "env: VERSION_LABEL: ${{ env. VERSION_LABEL }}"
70+
echo "github sha: ${{ github.sha }}"
71+
echo "should not skip tags, releases: ${{ ! inputs.skip_tagging_and_releases }} "
72+
echo "::endgroup::"
73+
74+
echo "## 🚀 Build Type: ${{ env.VERSION_LABEL }}" >> $GITHUB_STEP_SUMMARY
75+
echo "is_PR: ${{ inputs.is_PR || 'NOT a PR' }}" >> $GITHUB_STEP_SUMMARY
76+
echo "PR_NUMBER: ${{ inputs.PR_NUMBER || 'not a PR' }}" >> $GITHUB_STEP_SUMMARY
77+
echo "should not skip tags, releases: ${{ ! inputs.skip_tagging_and_releases }}" >> $GITHUB_STEP_SUMMARY
78+
79+
- name: Checkout Repository
80+
uses: actions/checkout@v4
81+
with:
82+
fetch-depth: 0 # Required for tags
83+
84+
- name: Set up Java 21
85+
uses: actions/setup-java@v4
86+
with:
87+
distribution: 'temurin'
88+
java-version: '21'
89+
cache: ${{ (github.ref == 'refs/heads/main' && 'gradle') || '' }}
90+
91+
- name: Set up Node.js
92+
uses: actions/setup-node@v4
93+
with:
94+
node-version: 'lts/*' # or '18.x' for latest stable
95+
96+
- name: Add keystore and build.json from secrets
97+
run: |
98+
echo "${{ secrets.KEYSTORE_CONTENT }}" | base64 -d > $STORE_FILE_PATH
99+
echo "${{ secrets.BUILD_JSON_CONTENT }}" | base64 -d > $BUILD_JSON_PATH
100+
echo "Keystore and build.json added successfully."
101+
102+
- name: Export Commit Hash & prev tag
103+
run: |
104+
echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
105+
echo "PREV_TAG=$(git describe --tags --abbrev=0 || git rev-list --max-parents=0 HEAD)" >> $GITHUB_ENV
106+
107+
- name: Extract versionCode and version from config.xml
108+
id: extract_version
109+
run: |
110+
if [ ! -f config.xml ]; then
111+
echo "config.xml not found!"
112+
exit 1
113+
fi
114+
VERSION_CODE=$(grep 'versionCode=' config.xml | sed -E 's/.*versionCode="([0-9]+)".*/\1/')
115+
VERSION=$(grep -oP 'version="\K[0-9.]+' config.xml)
116+
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_OUTPUT
117+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
118+
echo "Extracted Version Code: $VERSION_CODE"
119+
echo "Extracted Version: $VERSION"
120+
121+
- name: Append Commit Hash to Version and Update config.xml
122+
id: update-version
123+
run: |
124+
SHORT_COMMIT_HASH=$(echo "${{ env.GIT_COMMIT }}" | cut -c 1-7)
125+
if ${{ inputs.is_PR || false }}; then
126+
PR_NUMBER=${{ inputs.PR_NUMBER }}
127+
else
128+
PR_NUMBER=
129+
fi
130+
UPDATED_VERSION="${{ steps.extract_version.outputs.VERSION }}-${{ env.VERSION_LABEL }}.${PR_NUMBER:-$SHORT_COMMIT_HASH}"
131+
echo "Updated Version: $UPDATED_VERSION"
132+
133+
# Update config.xml with the new version
134+
sed -i "s/version=\"${{ steps.extract_version.outputs.VERSION }}\"/version=\"$UPDATED_VERSION\"/g" config.xml
135+
echo "Updated version in config.xml"
136+
# Output the updated version
137+
echo "UPDATED_VERSION=$UPDATED_VERSION" >> $GITHUB_ENV
138+
echo "UPDATED_VERSION=$UPDATED_VERSION" >> $GITHUB_OUTPUT
139+
140+
- name: Install Node.js Packages
141+
run: npm install
142+
143+
- name: Run npm setup
144+
run: npm run setup
145+
146+
- name: Run npm build paid dev apk
147+
run: |
148+
npm run build paid dev apk
149+
echo "VERSION: $UPDATED_VERSION" >> $GITHUB_STEP_SUMMARY
150+
151+
- name: Upload APK Artifact
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: app-debug-${{ env.GIT_COMMIT }}
155+
path: platforms/android/app/build/outputs/apk/debug/app-debug.apk
156+
157+
- name: remove keystore and build.json
158+
run: |
159+
rm $STORE_FILE_PATH $BUILD_JSON_PATH
160+
echo "Keystore and build.json removed successfully."
161+
162+
- name: Check Nightly Tag and Force Update
163+
#if: github.event_name == 'push' && contains(github.event.ref, 'tags/nightly') == false
164+
if: ${{ ! inputs.skip_tagging_and_releases }}
165+
run: |
166+
# Check if the nightly tag exists and get the commit it points to
167+
if git show-ref --quiet refs/tags/nightly; then
168+
TAG_COMMIT=$(git rev-parse nightly)
169+
else
170+
TAG_COMMIT=""
171+
fi
172+
173+
# If the current commit is the same as the tag, skip updating the tag
174+
if [ "$TAG_COMMIT" != "${{ env.GIT_COMMIT }}" ]; then
175+
echo "releaseRequired=true" >> $GITHUB_ENV
176+
# export tag commit before updating for change logs comparing.
177+
echo "TAG_COMMIT=$TAG_COMMIT" >> $GITHUB_ENV
178+
179+
git config --global user.name 'GitHub Actions'
180+
git config --global user.email 'github-actions@github.com'
181+
git tag -f nightly
182+
git push origin nightly --force
183+
else
184+
echo "Nightly tag already points to this commit. Skipping update."
185+
fi
186+
187+
- name: Release Nightly Version
188+
# Only run this step, if not called from another workflow. And a previous step is successful with releasedRequired=true
189+
id: release
190+
if: ${{ ! inputs.skip_tagging_and_releases && success() && env.releaseRequired == 'true' }}
191+
uses: softprops/action-gh-release@v2
192+
with:
193+
prerelease: true
194+
name: ${{ env.UPDATED_VERSION }}
195+
tag_name: ${{ env.UPDATED_VERSION }}
196+
files: |
197+
platforms/android/app/build/outputs/apk/debug/app-debug.apk
198+
body: |
199+
Automated Nightly (pre-release) Releases for Today
200+
\n\n[Compare Changes](https://github.com/${{ github.repository }}/compare/${{ env.TAG_COMMIT }}...${{ github.sha }})
201+
202+
- name: Update Last Comment by bot (If ran in PR)
203+
if: inputs.is_PR
204+
uses: marocchino/sticky-pull-request-comment@v2
205+
with:
206+
hide_and_recreate: true
207+
hide_classify: "OUTDATED"
208+
header: on-demand-build-status
209+
message: |
210+
Preview Release for this, has been built.
211+
212+
[Click here to view that github actions build](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})
213+
214+
215+
community-release-notifier:
216+
needs: build
217+
# Run only if push tags, or triggered by a schedule
218+
if: ${{ github.repository_owner == 'Acode-Foundation' && (contains(fromJSON('["push", "schedule"]'), github.event_name) || ! inputs.skip_tagging_and_releases) && needs.build.outputs.release_output_url }}
219+
uses: Acode-Foundation/acode/.github/workflows/community-release-notifier.yml@main
220+
with:
221+
tag_name: ${{ needs.build.outputs.updated_version }}
222+
url: ${{ needs.build.outputs.release_output_url }}
223+
secrets:
224+
DISCORD_WEBHOOK_RELEASE_NOTES: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: On Demand Preview Releases for PR
2+
# avoids paths like .md, and anything in .github folder
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- '!*.md'
7+
# - '.github/**'
8+
types: [labeled, synchronize]
9+
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
# All Pull Requests are issues, but not all issues are Pull Requests (like GitHub says 🙃)
15+
issues: write
16+
17+
concurrency:
18+
# Allow only one workflow per any non-`main` branch.
19+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
job_trigger:
24+
name: Trigger Preview Release (if conditions met)
25+
if: |
26+
(github.repository_owner == 'Acode-Foundation'
27+
&& (!contains(github.event.pull_request.labels.*.name, 'DO NOT PREVIEW RELEASE')
28+
&& (contains(github.event.pull_request.labels.*.name, 'Bypass check - PREVIEW RELEASE')
29+
|| contains(github.event.pull_request.labels.*.name, 'CI: RUN ON-DEMAND PREVIEW RELEASES')))
30+
)
31+
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
with:
38+
clean: false
39+
fetch-depth: 0
40+
41+
- name: Remove Manually added PR Label
42+
if: |
43+
contains(github.event.pull_request.labels.*.name, 'CI: RUN ON-DEMAND PREVIEW RELEASES')
44+
45+
run: gh pr edit $PR --remove-label "$labels"
46+
env:
47+
PR: ${{ github.event.pull_request.number }}
48+
labels: 'CI: RUN ON-DEMAND PREVIEW RELEASES'
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Add comment to PR
52+
uses: marocchino/sticky-pull-request-comment@v2
53+
with:
54+
hide_and_recreate: true
55+
hide_classify: "OUTDATED"
56+
header: on-demand-build-status
57+
message: |
58+
⚒️ Starting a workflow to build, Your On-Demand Preview Release/build for ${{ github.event.pull_request.html_url || github.event.pull_request.url }}.
59+
60+
status: **\`🟡 in_progress\`**
61+
62+
Kindly wait, this message may be updated with success or failure status.
63+
64+
For Owners: Please [Click here to view that github actions](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})/
65+
66+
env:
67+
PR: ${{ github.event.pull_request.number }}
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
70+
trigger_builder:
71+
needs: job_trigger
72+
secrets: inherit
73+
uses: Acode-Foundation/acode/.github/workflows/nightly-build.yml@main
74+
with:
75+
is_PR: true
76+
PR_NUMBER: ${{ github.event.pull_request.number }}
77+
skip_tagging_and_releases: true
78+
79+
update_Last_Comment:
80+
needs: [job_trigger,trigger_builder]
81+
runs-on: ubuntu-latest
82+
if: ${{ github.repository_owner == 'Acode-Foundation' && always() && contains(fromJSON('["failure","cancelled"]'), needs.trigger_builder.result) }}
83+
steps:
84+
# - name: Checkout code
85+
# uses: actions/checkout@v4
86+
# with:
87+
# clean: false
88+
# fetch-depth: 0
89+
90+
- name: Update Last Comment by bot (if Workflow Triggering failed)
91+
uses: marocchino/sticky-pull-request-comment@v2
92+
with:
93+
hide_and_recreate: true
94+
hide_classify: "OUTDATED"
95+
header: on-demand-build-status
96+
message: |
97+
🔴 (Workflow Trigger stopped), Your On-Demand Preview Release/build for ${{ github.event.pull_request.html_url || github.event.pull_request.url }}.
98+
status: **${{ needs.trigger_builder.result || 'failure'}}**
99+
100+
---
101+
For Owners: Please [Click here to view that github actions](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})

0 commit comments

Comments
 (0)