-
Notifications
You must be signed in to change notification settings - Fork 58
198 lines (193 loc) · 9.03 KB
/
android.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
# This is a basic workflow to help you get started with Actions
name: Android release
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [master, staging, next]
pull_request:
branches: [master]
types:
- closed
workflow_dispatch:
inputs:
release:
description: 'release type'
required: true
default: ''
type: choice
options:
- master
- staging
- next
jobs:
codepush:
name: Hot Code Push
runs-on: ubuntu-22.04
# hot push is for hotfix commits to PROD only
# manual PROD releases and release commits are going through the full flow
if: |
github.event_name != 'workflow_dispatch' &&
endsWith(github.ref, '/next') &&
!contains(github.event.head_commit.message, 'release prod')
steps:
- name: Pre-checks - Env is PROD
if: ${{ endsWith(github.ref, '/next') }}
run: |
echo "ENV=prod" >> $GITHUB_ENV
echo "APPCENTER_NAME=GoodDollar/GoodDollar-Android-production" >> $GITHUB_ENV
echo "APPCENTER_CODEPUSH_FLAGS=''" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- uses: actions/setup-python@v4
with:
python-version: '3.7.x'
- name: Cache & install dependencies
run: yarn --immutable
- name: add .env secrets
env:
SENTRYRC: ${{ secrets.sentryrc_file }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: |
env_name="${{ env.ENV }}"
vercel_env_name="production"
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
cat .vercel/.env.$vercel_env_name.local >> .env.$env_name
echo $env_name
cat .env.$env_name
echo "adding secrets to .env.$env_name file"
echo "$SENTRYRC" > android/sentry.properties
echo "REACT_APP_CODE_PUSH_KEY=$(grep -Po '(?<=^APPCENTER_CODEPUSH_TOKEN=)\S+' .env.$env_name)" >> .env.$env_name
- name: Code push release
run: |
BUILD_VERSION=`node -pe "require('./package.json')['version']"`
FORMATTED_VERSION=${BUILD_VERSION%.*}.x
APPCENTER_TOKEN=`node -pe "require('dotenv').parse(require('fs').readFileSync('.env.${{ env.ENV }}')).APPCENTER_ANDROID_TOKEN"`
echo Code push release target version ${FORMATTED_VERSION}
yarn lingui:compile
yarn animation:assets
npx appcenter codepush release-react --token ${APPCENTER_TOKEN} -a ${{ env.APPCENTER_NAME }} -d Production -t ${FORMATTED_VERSION}
build:
name: Build
# The type of runner that the job will run on
runs-on: ubuntu-22.04
# Build runs on manual release or on any commit to dev/qa or on release commit to PROD
# GH actions not supports regex match, so to avoid adding extra step with custom action
# we compare to commt string to starts with 2. Should be updated on major version change
if: |
github.event_name == 'workflow_dispatch' ||
endsWith(github.ref, '/master') ||
endsWith(github.ref, '/staging') || (
endsWith(github.ref, '/next') && (
contains(github.event.head_commit.message, 'release prod') ||
startsWith(github.event.head_commit.message, '2.')
)
)
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Git branch name
id: git-branch-name
uses: EthanSK/git-branch-name-action@v1
- name: Detect and set target branch
run: echo "TARGET_BRANCH=${{ github.event.inputs.release || env.GIT_BRANCH_NAME }}" >> $GITHUB_ENV
- name: Pre-checks - Env is Dev
run: |
echo "ENV=development" >> $GITHUB_ENV
echo "APPCENTER_NAME=GoodDollar/GoodDollar-Android-development" >> $GITHUB_ENV
echo "ANDROID_BUNDLE_PATH=./android/app/build/outputs/bundle/release/app-release.aab" >> $GITHUB_ENV
echo "BUILD_NUMBER_PREFIX=20" >> $GITHUB_ENV
echo "BUILD_VERSION_SUFFIX=-alpha" >> $GITHUB_ENV
- name: Pre-checks - Env is QA
if: ${{ env.TARGET_BRANCH == 'staging' }}
run: |
echo "ENV=staging" >> $GITHUB_ENV
echo "APPCENTER_NAME=GoodDollar/GoodDollar-Android-staging" >> $GITHUB_ENV
echo "BUILD_NUMBER_PREFIX=10" >> $GITHUB_ENV
echo "BUILD_VERSION_SUFFIX=-beta" >> $GITHUB_ENV
- name: Pre-checks - Env is PROD
if: ${{ env.TARGET_BRANCH == 'next' }}
run: |
echo "ENV=prod" >> $GITHUB_ENV
echo "APPCENTER_NAME=GoodDollar/GoodDollar-Android-production" >> $GITHUB_ENV
echo "APPCENTER_STORE=Production" >> $GITHUB_ENV
echo "BUILD_NUMBER_PREFIX=" >> $GITHUB_ENV
echo "BUILD_VERSION_SUFFIX=" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: ${{ env.TARGET_BRANCH }}
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- uses: actions/setup-python@v4
with:
python-version: '3.7.x'
- name: fix max_user_watches
run: |
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- name: Cache & install dependencies
run: yarn --immutable
- name: add .env secrets
env:
SENTRYRC: ${{ secrets.sentryrc_file }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: |
env_name="${{ env.ENV }}"
if [[ $env_name == "development" ]]; then
vercel_env_name="development"
vercel pull --yes --environment=$vercel_env_name --token=${{ secrets.VERCEL_TOKEN }}
elif [[ $env_name == "prod" ]]; then
vercel_env_name="production"
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
else
vercel_env_name="preview"
vercel pull --yes --environment=$vercel_env_name --git-branch=$env_name --token=${{ secrets.VERCEL_TOKEN }}
fi
cat .vercel/.env.$vercel_env_name.local >> .env.$env_name
echo $env_name
echo "APPCENTER_TOKEN=$(grep -Po '(?<=^APPCENTER_ANDROID_TOKEN=)\S+' .env.$env_name)" >> $GITHUB_ENV
echo "APPCENTER_CODEPUSH_TOKEN=$(grep -Po '(?<=^APPCENTER_CODEPUSH_TOKEN=)\S+' .env.$env_name)" >> $GITHUB_ENV
cat .env.$env_name
echo "adding secrets to .env.$env_name file"
echo "$SENTRYRC" > android/sentry.properties
echo "REACT_APP_CODE_PUSH_KEY=$(grep -Po '(?<=^APPCENTER_CODEPUSH_TOKEN=)\S+' .env.$env_name)" >> .env.$env_name
- name: Setup google services file
run: echo "${{ secrets.ANDROID_GOOGLE_SERVICES}}" | base64 --decode > ./android/app/google-services.json
- name: Set release keystore
run: |
echo "${{ secrets.RELEASE_ANDROID_KEYSTORE }}" > release.keystore.asc
gpg -d --passphrase "${{ secrets.RELEASE_ANDROID_PASSPHRASE }}" --batch release.keystore.asc > android/app/release.keystore
- name: Build Android Release
env:
RELEASE_ANDROID_PASSPHRASE: ${{ secrets.RELEASE_ANDROID_PASSPHRASE }}
ENVFILE: '.env.${{ env.ENV }}'
BUILD_NUMBER: '${{ env.BUILD_NUMBER_PREFIX }}${{ github.run_number }}'
CODE_PUSH_DEPLOYMENT_KEY: ${{ env.APPCENTER_CODEPUSH_TOKEN }}
run: |
PACKAGE_VERSION=`node -pe "require('./package.json')['version']"`
BUILD_VERSION=${PACKAGE_VERSION}${{ env.BUILD_VERSION_SUFFIX }}
echo "Creating release using env: ${ENVFILE} build:${BUILD_NUMBER} version:${BUILD_VERSION} ${GITHUB_RUN_NUMBER} ${{ github.run_number }}"
yarn lingui:compile
yarn animation:assets
cd android && ./gradlew bundleRelease
- name: Build Universal APK
uses: skywall/[email protected]
with:
aab_path: ${{ env.ANDROID_BUNDLE_PATH }}
keystore_path: './android/app/release.keystore'
keystore_password: ${{secrets.RELEASE_ANDROID_PASSPHRASE}}
keystore_alias: 'release-alias'
keystore_alias_password: ${{secrets.RELEASE_ANDROID_PASSPHRASE}}
- name: Deploy to App Center
run: |
echo "deploying to ${{ env.APPCENTER_NAME }} ${{ env.INPUT_APK_PATH }}"
npx appcenter distribute release --token "${{ env.APPCENTER_TOKEN }}" --app "${{ env.APPCENTER_NAME }}" --group "Collaborators" --file "${{ env.UNIVERSAL_APK_PATH }}" --release-notes "$(git log -1 --pretty=format:'%h %s')" --debug
- name: Distribute to stores - PROD only
if: ${{ env.ENV == 'prod' }}
run: |
npx appcenter distribute stores publish --token "${{ env.APPCENTER_TOKEN }}" --app "${{ env.APPCENTER_NAME }}" --store "${{ env.APPCENTER_STORE }}" --file "${{ env.ANDROID_BUNDLE_PATH }}" --release-notes "$(git log -1 --pretty=format:'%h %s')"