forked from quarck/CalendarNotification
-
Notifications
You must be signed in to change notification settings - Fork 0
264 lines (226 loc) · 11.2 KB
/
actions.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: CNPlus CI (Android) App Build
env:
# The name of the main module repository
main_project_module: app
# The name of the Play Store
app_name: "Calendar Notifications Plus"
app_file_name_prefix: "calendar_notifications_plus"
on:
push:
tags:
- '**'
pull_request:
branches:
- "**" # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#patterns-to-match-branches-and-tags
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
install-and-build-android:
runs-on: ubuntu-latest
env:
ENTRY_FILE: "index.tsx"
timeout-minutes: 30
strategy:
matrix:
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
# https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- name: Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
# Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
# Yarn cache is also reusable between arch and os.
- name: Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-download-cache-
# Invalidated on yarn.lock changes
- name: Restore yarn install state
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: .yarn/ci-cache/
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
- run: yarn install --immutable --inline-builds
env:
# CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_NM_MODE: 'hardlinks-local' # Hardlinks-(local|global) reduces io / node_modules size
YARN_INSTALL_STATE_PATH: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
# Where android build starts. one day we will have a separate job for this but i dont know how pass the node_modules cache to it
# Set Current Date As Env Variable
- name: Set current date as env variable
run: echo "build_datetime=$(date +'%Y-%m-%d %H_%M_%S')" >> $GITHUB_ENV
# Set Repository Name As Env Variable
- name: Set repository name as env variable
run: echo "repository_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew and show version
run: cd android && chmod +x gradlew && ./gradlew --version
- name: Build with Gradle
run: cd android && ./gradlew build --warning-mode all --info --stacktrace
# Create APK Debug
- name: Build apk debug project (APK) - ${{ env.main_project_module }} module
run: cd android && ./gradlew assembleDebug
# Create APK Release
- name: Build apk release project (APK) - ${{ env.main_project_module }} module
run: cd android && ./gradlew assemble
# Create Bundle AAB Release
# Noted for main module build [main_project_module]:bundleRelease
- name: Build app bundle release (AAB) - ${{ env.main_project_module }} module
run: cd android && ./gradlew ${{ env.main_project_module }}:bundleRelease
- uses: r0adkll/sign-android-release@v1
name: Sign debug app APKs
# ID used to access action output
id: sign_debug_app
with:
releaseDirectory: android/${{ env.main_project_module }}/build/outputs/apk/debug/
signingKeyBase64: ${{ secrets.DEBUG_SIGNING_KEYSTORE }}
alias: ${{ secrets.DEBUG_KEYSTORE_ALIAS }}
keyStorePassword: ${{ secrets.DEBUG_KEYSTORE_PASSWORD }}
keyPassword: ${{ secrets.DEBUG_KEYSTORE_ALIAS_PASS }}
env:
# override default build-tools version (33.0.0) -- optional
BUILD_TOOLS_VERSION: "34.0.0"
- uses: r0adkll/sign-android-release@v1
name: Sign RELEASE app APKs
# ID used to access action output
id: sign_release_app
with:
releaseDirectory: android/${{ env.main_project_module }}/build/outputs/apk/release/
signingKeyBase64: ${{ secrets.RELEASE_SIGNING_KEYSTORE }}
alias: ${{ secrets.RELEASE_KEYSTORE_ALIAS }}
keyStorePassword: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
keyPassword: ${{ secrets.RELEASE_KEYSTORE_ALIAS_PASS }}
env:
# override default build-tools version (33.0.0) -- optional
BUILD_TOOLS_VERSION: "34.0.0"
- uses: r0adkll/sign-android-release@v1
name: Sign RELEASE app AABs
# ID used to access action output
id: sign_release_aab
with:
releaseDirectory: android/${{ env.main_project_module }}/build/outputs/bundle/release/
signingKeyBase64: ${{ secrets.RELEASE_SIGNING_KEYSTORE }}
alias: ${{ secrets.RELEASE_KEYSTORE_ALIAS }}
keyStorePassword: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
keyPassword: ${{ secrets.RELEASE_KEYSTORE_ALIAS_PASS }}
env:
# override default build-tools version (33.0.0) -- optional
BUILD_TOOLS_VERSION: "34.0.0"
# for tags: calendar_notifications_plus-1.2.3-debug.apk
# for PRs: calendar_notifications_plus-pr-123-feature-branch-abcdef-debug.apk
# for pushes to branches other than main: calendar_notifications_plus-feature-branch-abcdef-debug.apk
- name: Rename APKs
run: |
sanitize_branch_name() {
echo "$1" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//' | cut -c1-20
}
if [[ $GITHUB_REF == refs/tags/* ]]; then
# For tags
VERSION=${GITHUB_REF#refs/tags/v}
SUFFIX="-${VERSION}"
elif [[ $GITHUB_REF == refs/pull/* ]]; then
# For pull requests
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
BRANCH_NAME=$(sanitize_branch_name "$GITHUB_HEAD_REF")
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
SUFFIX="-pr-${PR_NUMBER}-${BRANCH_NAME}-${SHORT_SHA}"
else
# For pushes to branches other than main
BRANCH_NAME=$(sanitize_branch_name "${GITHUB_REF#refs/heads/}")
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
SUFFIX="-${BRANCH_NAME}-${SHORT_SHA}"
fi
mv ${{steps.sign_debug_app.outputs.signedReleaseFile}} ${{env.app_file_name_prefix}}${SUFFIX}-debug.apk
mv ${{steps.sign_release_app.outputs.signedReleaseFile}} ${{env.app_file_name_prefix}}${SUFFIX}-release.apk
mv ${{steps.sign_release_aab.outputs.signedReleaseFile}} ${{env.app_file_name_prefix}}${SUFFIX}.aab
# # Upload Artifact Build
# # Noted For Output [main_project_module]/build/outputs/apk/debug/
# - name: Upload unsigned APK Debug - ${{ env.repository_name }}
# uses: actions/upload-artifact@v4
# with:
# name: ${{ matrix.node-version }} - ${{ env.build_datetime }} - ${{ env.app_name }} - ${{ env.repository_name }} - unsigned APK(s) debug generated
# path: android/${{ env.main_project_module }}/build/outputs/apk/debug/
# Upload Artifact Build
- name: Upload SIGNED APK Debug - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: signed - ${{ matrix.node-version }} - ${{ env.build_datetime }} - ${{ env.app_name }} - ${{ env.repository_name }} - APK(s) debug generated
path: ${{env.app_file_name_prefix}}-*-debug.apk
# # Noted For Output [main_project_module]/build/outputs/apk/release/
# - name: Upload unsigned APK Release - ${{ env.repository_name }}
# uses: actions/upload-artifact@v4
# with:
# name: ${{ matrix.node-version }} - ${{ env.build_datetime }} - ${{ env.app_name }} - ${{ env.repository_name }} - unsigned APK(s) release generated
# path: android/${{ env.main_project_module }}/build/outputs/apk/release/
# Upload Artifact Build
- name: Upload SIGNED APK RELEASE - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: signed - ${{ matrix.node-version }} - ${{ env.build_datetime }} - ${{ env.app_name }} - ${{ env.repository_name }} - APK(s) release generated
path: ${{env.app_file_name_prefix}}-*-release.apk
# # Noted For Output [main_project_module]/build/outputs/bundle/release/
# - name: Upload unsigned AAB (App Bundle) Release - ${{ env.repository_name }}
# uses: actions/upload-artifact@v4
# with:
# name: ${{ matrix.node-version }} - ${{ env.build_datetime }} - ${{ env.app_name }} - ${{ env.repository_name }} - unsigned App bundle(s) AAB release generated
# path: android/${{ env.main_project_module }}/build/outputs/bundle/release/
# Upload Artifact Build
- name: Upload SIGNED AAB (App Bundle) Release - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: signed - ${{ matrix.node-version }} - ${{ env.build_datetime }} - ${{ env.app_name }} - ${{ env.repository_name }} - App bundle(s) AAB release generated
path: ${{env.app_file_name_prefix}}-*.aab
- name: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const workflowUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Build artifacts for this PR are available:
- [Debug APK](${workflowUrl}#artifacts)
- [Release APK](${workflowUrl}#artifacts)
- [AAB](${workflowUrl}#artifacts)
You can download these artifacts from the "Artifacts" section of the workflow run.`
});
- name: Generate Changelog
run: |
echo "# Release ${GITHUB_REF#refs/tags/}" > ${{ github.workspace }}-CHANGELOG.txt
echo "" >> ${{ github.workspace }}-CHANGELOG.txt
echo "## What's Changed" >> ${{ github.workspace }}-CHANGELOG.txt
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:"* %s" >> ${{ github.workspace }}-CHANGELOG.txt
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
body_path: ${{ github.workspace }}-CHANGELOG.txt
files: |
${{env.app_file_name_prefix}}*-debug.apk
${{env.app_file_name_prefix}}*-release.apk
${{env.app_file_name_prefix}}*.aab