Skip to content

Commit 39e789b

Browse files
committed
feat: add Android CI/CD workflows
1 parent aaa3fbb commit 39e789b

File tree

6 files changed

+205
-36
lines changed

6 files changed

+205
-36
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github/** @modos189
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Setup NPM Cache'
2+
description: 'Setup NPM cache for faster builds'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Get npm cache directory
8+
id: npm-cache-dir
9+
shell: bash
10+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
11+
12+
- uses: actions/cache@v4
13+
with:
14+
path: ${{ steps.npm-cache-dir.outputs.dir }}
15+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
16+
restore-keys: |
17+
${{ runner.os }}-node-
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: 'Setup Development Environment'
2+
description: 'Setup Node.js, Java, Android SDK, Python and NativeScript CLI'
3+
4+
inputs:
5+
node-version:
6+
description: 'Node.js version to use'
7+
required: false
8+
default: '18'
9+
java-version:
10+
description: 'Java version to use'
11+
required: false
12+
default: '17'
13+
14+
runs:
15+
using: 'composite'
16+
steps:
17+
- uses: actions/setup-java@v4
18+
with:
19+
distribution: 'temurin'
20+
java-version: ${{ inputs.java-version }}
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ inputs.node-version }}
25+
26+
- name: Cache Android SDK
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
/usr/local/lib/android/sdk
31+
~/.android
32+
key: ${{ runner.os }}-android-sdk-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
33+
restore-keys: |
34+
${{ runner.os }}-android-sdk-
35+
36+
- name: Setup Android SDK
37+
uses: android-actions/setup-android@v3
38+
39+
- name: Cache Python virtual environment
40+
uses: actions/cache@v4
41+
with:
42+
path: venv
43+
key: ${{ runner.os }}-python-venv-${{ hashFiles('**/requirements.txt') }}
44+
restore-keys: |
45+
${{ runner.os }}-python-venv-
46+
47+
- name: Install Python dependencies
48+
shell: bash
49+
run: |
50+
python3 -m venv venv
51+
source venv/bin/activate
52+
python3 -m pip install six
53+
54+
- name: Cache NativeScript CLI
55+
uses: actions/cache@v4
56+
with:
57+
path: ~/.npm
58+
key: ${{ runner.os }}-nativescript-cli-${{ hashFiles('**/package*.json') }}
59+
restore-keys: |
60+
${{ runner.os }}-nativescript-cli-
61+
62+
- name: Install NativeScript CLI
63+
shell: bash
64+
run: |
65+
npm install -g nativescript
66+
ns doctor android
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build Android
2+
3+
on:
4+
push:
5+
branches: [master]
6+
tags: ['*']
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup environment
16+
uses: ./.github/actions/setup-environment
17+
18+
- name: Setup cache
19+
uses: ./.github/actions/setup-cache
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Decode Android keystore
25+
run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > android_keystore.jks
26+
27+
- name: Set build type
28+
run: |
29+
if [[ $GITHUB_REF == refs/heads/master ]]; then
30+
echo "BUILD_TYPE=beta" >> $GITHUB_ENV
31+
echo "BUILD_SCRIPT=build:android:beta" >> $GITHUB_ENV
32+
elif [[ $GITHUB_REF == refs/tags/* ]]; then
33+
echo "BUILD_TYPE=release" >> $GITHUB_ENV
34+
echo "BUILD_SCRIPT=build:android:release" >> $GITHUB_ENV
35+
fi
36+
37+
- name: Build Android APK
38+
env:
39+
KEYSTORE_PATH: ./android_keystore.jks
40+
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
41+
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
42+
KEYSTORE_ALIAS_PASSWORD: ${{ secrets.KEYSTORE_ALIAS_PASSWORD }}
43+
run: npm run ${{ env.BUILD_SCRIPT }}
44+
45+
- name: Get APK filename
46+
id: apk-info
47+
run: |
48+
APK_PATH=$(find platforms/android/app/build/outputs -name "*.apk" | head -n 1)
49+
APK_FILENAME=$(basename "$APK_PATH")
50+
echo "apk_path=$APK_PATH" >> $GITHUB_OUTPUT
51+
echo "apk_filename=$APK_FILENAME" >> $GITHUB_OUTPUT
52+
53+
- name: Create release for tags
54+
if: startsWith(github.ref, 'refs/tags/')
55+
uses: ncipollo/release-action@v1
56+
with:
57+
allowUpdates: true
58+
artifacts: ${{ steps.apk-info.outputs.apk_path }}
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Prepare metadata
62+
run: |
63+
mkdir -p artifact/.metadata
64+
echo "${{ env.BUILD_TYPE }}" > artifact/.metadata/build_type
65+
echo "${{ github.sha }}" > artifact/.metadata/commit
66+
echo "${{ steps.apk-info.outputs.apk_filename }}" > artifact/.metadata/apk_filename
67+
echo "$(date -u +'%Y-%m-%d_%H-%M')" > artifact/.metadata/buildstamp
68+
69+
# Copy APK to artifact directory
70+
mkdir -p artifact/build
71+
cp "${{ steps.apk-info.outputs.apk_path }}" artifact/build/
72+
73+
- uses: actions/upload-artifact@v4
74+
id: upload-artifact
75+
with:
76+
name: android-build
77+
include-hidden-files: true
78+
path: |
79+
artifact/.metadata/
80+
artifact/build/
81+
82+
- name: Get artifact ID
83+
id: get-artifact-id
84+
if: vars.WEBSITE_REPO != ''
85+
uses: actions/github-script@v7
86+
with:
87+
script: |
88+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
run_id: context.runId
92+
});
93+
const artifact = artifacts.data.artifacts.find(a => a.name === 'android-build');
94+
return artifact.id;
95+
96+
- name: Send build to website
97+
if: vars.WEBSITE_REPO != ''
98+
uses: peter-evans/repository-dispatch@v3
99+
with:
100+
token: ${{ secrets.API_TOKEN_GITHUB }}
101+
repository: ${{ vars.WEBSITE_REPO }}
102+
event-type: 'new_iitc_prime_build'
103+
client-payload: |
104+
{
105+
"repo": {
106+
"owner": "${{ github.repository_owner }}",
107+
"repo": "${{ github.event.repository.name }}"
108+
},
109+
"artifact_id": "${{ steps.get-artifact-id.outputs.result }}"
110+
}

.github/workflows/test-build.yml

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,27 @@
11
name: Make test build
22

33
on:
4-
push:
5-
branches:
6-
- master
74
pull_request:
85
workflow_dispatch:
96

107
jobs:
118
test_build:
12-
runs-on: macos-latest
9+
runs-on: ubuntu-latest
1310

1411
steps:
1512
- uses: actions/checkout@v4
1613

17-
- uses: actions/setup-java@v4
18-
with:
19-
distribution: 'temurin'
20-
java-version: '17'
14+
- name: Setup environment
15+
uses: ./.github/actions/setup-environment
2116

22-
- name: Get yarn cache
23-
id: yarn-cache
24-
run: echo "::set-output name=dir::$(yarn cache dir)"
17+
- name: Setup cache
18+
uses: ./.github/actions/setup-cache
2519

26-
- uses: actions/cache@v4
27-
with:
28-
path: ${{ steps.yarn-cache.outputs.dir }}
29-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
30-
restore-keys: |
31-
${{ runner.os }}-yarn-
32-
33-
- name: Install six
34-
run: |
35-
python3 -m venv venv
36-
source venv/bin/activate
37-
python3 -m pip install six
38-
39-
- name: Install NativeScript
40-
run: |
41-
yarn global add nativescript@latest
42-
tns doctor
43-
tns package-manager set yarn
44-
45-
- name: Yarn dependencies
46-
run: yarn
20+
- name: Install dependencies
21+
run: npm install
4722

4823
- name: Make test build
49-
run: tns build android --debug --clean
24+
run: npm run build:android:debug
5025

5126
- name: Upload artifact
5227
uses: actions/upload-artifact@v4

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"private": true,
66
"scripts": {
77
"run:android": "ns run android",
8-
"build:android:release": "BUILD_TYPE=release ns build android --release --env.snapshot --env.compileSnapshot --env.uglify --aab",
9-
"build:android:beta": "BUILD_TYPE=beta ns build android",
10-
"build:android:debug": "BUILD_TYPE=debug ns build android",
8+
"build:android:release": "BUILD_TYPE=release ns build android --release --clean --key-store-path $KEYSTORE_PATH --key-store-password $KEYSTORE_PASSWORD --key-store-alias $KEYSTORE_ALIAS --key-store-alias-password $KEYSTORE_ALIAS_PASSWORD --env.snapshot --env.compileSnapshot --env.uglify",
9+
"build:android:beta": "BUILD_TYPE=beta ns build android --release --clean --key-store-path $KEYSTORE_PATH --key-store-password $KEYSTORE_PASSWORD --key-store-alias $KEYSTORE_ALIAS --key-store-alias-password $KEYSTORE_ALIAS_PASSWORD --env.snapshot --env.compileSnapshot --env.sourceMap",
10+
"build:android:debug": "BUILD_TYPE=debug ns build android --env.sourceMap",
1111
"run:ios": "ns run ios",
1212
"build:ios:release": "ns build ios --release --env.uglify",
1313
"build:ios:beta": "ns build ios",

0 commit comments

Comments
 (0)