-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (190 loc) · 8.63 KB
/
ci-cd-develop.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
name: Dev CI/CD
on:
push:
branches:
- develop
jobs:
# Don't run CI/CD if only README.md and/or any .yml file is updated
check_readme_yml_txt_changes:
runs-on: ubuntu-latest
outputs:
run_rest_jobs: ${{ steps.set_output.outputs.run_jobs }}
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check for README, yml or txt changes
id: set_output
run: |
# Get the list of changed files between the base and head branches
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
# Check if 'README.md' or '.yml' files are the only files changed
if [[ ${CHANGED_FILES} =~ ^(README\.md|.*\.yml|.*\.txt)$ && ! ${CHANGED_FILES} =~ ^(?!.*(README\.md|.*\.yml|.*\.txt)).*$ ]]; then
echo "Only README.md or .yml or .txt files have been updated. Skipping the CI/CD workflow."
# GITHUB_OUTPUT is a default GitHub env. variable
echo "run_jobs=false" >> ${GITHUB_OUTPUT}
else
echo "Changes to files other than README.md or *.yml or .txt detected. Proceeding with the CI/CD workflow."
echo "run_jobs=true" >> ${GITHUB_OUTPUT}
fi
test:
needs: check_readme_yml_txt_changes
if: needs.check_readme_yml_txt_changes.outputs.run_rest_jobs == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3
# Cache npm dependencies (from GitHub docs)
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# If there's a cache miss
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
# Caching process complete
- name: Install dependencies
run: npm install
- name: Lint check
run: npm run lint
- name: Run tests
run: npm run test
deploy:
needs: test
# default action is success(): if(success)
runs-on: ubuntu-latest
env:
MYAPP_UPLOAD_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_ALIAS }}
MYAPP_UPLOAD_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
MYAPP_UPLOAD_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
steps:
# We need to checkout the current branch and install node
# dependencies again because every GH Actions job runs on
# a seperate runner (VM)
- name: Checkout branch
uses: actions/checkout@v3
# Cache npm dependencies (from GitHub docs)
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# If there's a cache miss
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
# Caching process complete
- name: Install dependencies
run: npm install
# - name: Read Version
# id: read-version
# run: |
# echo "::set-output name=versionCode::$(jq -r '.versionCode' version.json)"
# echo "::set-output name=versionName::$(jq -r '.versionName' version.json)"
# # echo "::set-output name=versionCode::$(jq -r '.versionCode' version.json)"
# # echo "::set-output name=versionName::$(node -p -e "require('./version.json').versionName")"
# - name: Increment Version
# id: increment-version
# run: |
# echo "::set-output name=versionCode::$(node -p \"parseInt('${{ steps.read-version.outputs.versionCode }}') + 1\")"
# echo "::set-output name=versionName::$(node -p \"'${{ steps.read-version.outputs.versionName }}'.replace(/(\\d+\\.\\d+\\.)(\\d+)/, (_, p1, p2) => p1 + (parseInt(p2) + 1))\")"
# # echo "::set-output name=versionCode::$(node -p -e 'parseInt(${ steps.read-version.outputs.versionCode }) + 1')"
# # echo "::set-output name=versionName::$(node -p -e "'${{ steps.read-version.outputs.versionName }}'.replace(/(\\d+\\.\\d+\\.)(\\d+)/, (_, p1, p2) => p1 + (parseInt(p2) + 1))")"
# - name: Update build.gradle
# run: |
# sed -i "s/versionCode .*/versionCode ${{ steps.increment-version.outputs.versionCode }}/" android/app/build.gradle
# sed -i "s/versionName .*/versionName '${{ steps.increment-version.outputs.versionName }}'/" android/app/build.gradle
# - name: Commit and Push Changes
# uses: stefanzweifel/git-auto-commit-action@v4
# with:
# commit_message: devops - update versionCode and versionName [skip ci]
- name: Cache Gradle Wrapper
uses: actions/cache@v3
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Cache Gradle Dependencies
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-caches-
# Start the build process
- name: Make Gradlew Executable
run: cd android && chmod +x ./gradlew
# - name: Generate App APK
# run: |
# cd android && ./gradlew assembleRelease --no-daemon
# - name: Sign generated APK
# id: sign_app
# uses: r0adkll/sign-android-release@v1
# with:
# releaseDirectory: android/app/build/outputs/apk/release
# signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }}
# alias: ${{ secrets.ANDROID_SIGNING_ALIAS }}
# keyStorePassword: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
# keyPassword: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
# - name: Check app directory after signing (debug)
# run: |
# ls -a android/app/build/outputs/apk/release
- name: Build Android App Bundle
run: cd android && ./gradlew bundleRelease --no-daemon
- name: Sign App Bundle
id: sign_app
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: android/app/build/outputs/bundle/release
signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }}
alias: ${{ secrets.ANDROID_SIGNING_ALIAS }}
keyStorePassword: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
keyPassword: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
# ## Distribute app to Firebase App Distribution for testing
# ## Use google play internal track if you have a google play account
# ## (uncomment the sections below if you want to use Play Store)
# - name: Upload artifact to Firebase App Distribution
# uses: wzieba/Firebase-Distribution-Github-Action@v1
# with:
# appId: ${{secrets.ANDROID_FIREBASE_APP_ID}}
# token: ${{secrets.ANDROID_FIREBASE_TOKEN}}
# groups: testers
# file: ${{steps.sign_app.outputs.signedReleaseFile}}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: Signed App Bundle
path: ${{steps.sign_app.outputs.signedReleaseFile}}
- name: Deploy to Play Store (Internal testing)
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.ANDROID_SERVICE_ACCOUNT }}
# The packageName must already exist in the play console account, so make sure you upload a manual apk or aab first through the console
# https://github.com/r0adkll/upload-google-play/tree/v1/
packageName: com.thebest.gamchha
releaseFiles: ${{steps.sign_app.outputs.signedReleaseFile}}
track: internal
inAppUpdatePriority: 3
status: draft
# userFraction: 0.5
whatsNewDirectory: android/release-notes/
releaseName: v1.0.4