-
Notifications
You must be signed in to change notification settings - Fork 7
168 lines (145 loc) · 6.73 KB
/
jsCodePush-PROD.yaml
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
name: Minibits JS bundle code push
# This workflow is manually triggered. Only if package.json version has changed it creates .env file,
# builds new js bundle and pushes it to devices running app with TEST env and STAGING code push deployment key.
# At the end it creates and pushes new version tag to github.
on: workflow_dispatch
jobs:
deploy-code-push:
runs-on: macos-latest
permissions:
id-token: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-node@v4
with:
node-version: 20
# Fetch javascript bundle version from package.json
- name: Read package.json version and detect changes
id: version-check
uses: salsify/action-detect-and-tag-new-version@v2
with:
create-tag: false
- name: Set versions
run: |-
echo "PREV_JS_VERSION=${{steps.version-check.outputs.previous-version }}" >> $GITHUB_ENV
echo "CURRENT_JS_VERSION=${{steps.version-check.outputs.current-version }}" >> $GITHUB_ENV
# Codepush build will continue only if version changed from previous commit - TEMP SKIP CHECK
- name: Detect version change
run: |
if [ "${{ env.PREV_JS_VERSION }}" != "${{ env.CURRENT_JS_VERSION }}" ]; then
echo "IS_VERSION_CHANGED=true" >> $GITHUB_ENV
echo "Detected version change"
else
echo "IS_VERSION_CHANGED=true" >> $GITHUB_ENV
echo "No version change, skipping further processing"
fi
# Fetch native app versionName and versionCode from app/build.gradle
- name: Get Android native version
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
id: version-reader-android
uses: michpohl/[email protected]
with:
path: android/app/build.gradle
expose-version-name: 'true' # sets ANDROID_VERSION_NAME to env
# Get commit hash
- name: Get commit hash
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
id: commit-hash
uses: pr-mpt/actions-commit-hash@v2
- name: Set commit hash
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: |-
echo "COMMIT_HASH=${{steps.commit-hash.outputs.short }}" >> $GITHUB_ENV
# Get commit message
- name: Get last commit message
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha
});
const lastCommit = response.data.commit;
const message = lastCommit.message;
console.log(message);
core.exportVariable('COMMIT_MESSAGE', message);
# Create .env file
- name: Generate .env
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: |-
echo APP_ENV='PROD' >> .env
echo SENTRY_DSN='${{ secrets.SENTRY_DSN }}' >> .env
echo CODEPUSH_PRODUCTION_DEPLOYMENT_KEY='${{ secrets.CODEPUSH_PRODUCTION_DEPLOYMENT_KEY }}' >> .env
echo NATIVE_VERSION_ANDROID='${{ env.ANDROID_VERSION_NAME }}' >> .env
echo JS_BUNDLE_VERSION='${{ env.CURRENT_JS_VERSION }}' >> .env
echo MINIBITS_SERVER_API_KEY='${{ secrets.MINIBITS_SERVER_API_KEY }}' >> .env
echo MINIBIT_SERVER_NOSTR_PUBKEY='${{ secrets.MINIBIT_SERVER_NOSTR_PUBKEY }}' >> .env
echo MINIBITS_SERVER_API_HOST='https://api.minibits.cash' >> .env
echo MINIBITS_NIP05_DOMAIN='@minibits.cash' >> .env
echo MINIBITS_RELAY_URL='wss://relay.minibits.cash' >> .env
echo MINIBITS_MINT_URL='https://mint.minibits.cash/Bitcoin' >> .env
echo COMMIT='${{ env.COMMIT_HASH }}' >> .env
# Install dependecies from package.json
- name: Setup yarn
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: |-
corepack enable
corepack prepare [email protected] --activate
yarn set version 3.6.4
- name: Install app dependencies
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: yarn
# - name: Install app dependencies
# if: ${{ env.IS_VERSION_CHANGED == 'true' }}
# uses: bahmutov/[email protected]
# with:
# install-command: yarn
- name: Apply patches
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: yarn postinstall
- name: Install Sentry CLI
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: brew install getsentry/tools/sentry-cli
# Code push with source maps export for Sentry
- name: Install AppCenter CLI
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: npm install -g appcenter-cli
- name: Deploy to CodePush Android
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: appcenter codepush release-react -a minibits-cash/minibits_wallet_android -d Production --description '${{ env.COMMIT_MESSAGE }} (v${{ env.CURRENT_JS_VERSION }})' --sourcemap-output ./build/index.android.bundle.map --output-dir ./build
env:
APPCENTER_ACCESS_TOKEN: ${{ secrets.APPCENTER_ACCESS_TOKEN_ANDROID }}
# Upload source files to Sentry
- name: Upload source files to Sentry
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
run: |-
sentry-cli login --auth-token ${{ secrets.SENTRY_AUTH_TOKEN }}
sentry-cli releases \
files minibits_wallet_android@${{ env.CURRENT_JS_VERSION }} \
upload-sourcemaps \
--strip-prefix /build \
--dist ${{ env.ANDROID_VERSION_NAME }} \
--org ${{ secrets.SENTRY_ORG }} \
--project minibits-wallet \
./build/index.android.bundle.map ./build/Codepush/index.android.bundle
# Create the release tag in github repo
- name: Create tag
if: ${{ env.IS_VERSION_CHANGED == 'true' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tagPrefix = "v";
const tagName = tagPrefix + process.env.CURRENT_JS_VERSION;
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.sha
});