-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (88 loc) · 3.67 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
name: Build Android apk from Web code, and release if pushing a version tag
permissions:
contents: write
on:
push:
branches: ["apk"]
tags:
- "v*.*.*"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# Set up environment variables
- name: Get the paths to Android project and output apk
run: grep --invert-match '^#' "./.env" >> "${GITHUB_ENV}"
- name: Set app name
run: |
# Set app name to repository name
echo "APP_NAME=/${GITHUB_REPOSITORY#*/}/" >> "${GITHUB_ENV}"
echo "APP_NAME_UNVERSIONED_WITH_EXTENSION=${APP_NAME}-debug.apk" >> "${GITHUB_ENV}"
echo "APP_NAME_VERSIONED_WITH_EXTENSION=${GITHUB_REF_NAME}.apk" >> "${GITHUB_ENV}"
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"
- name: Set up npm dependencies
run: npm install && npm run setUp:capacitor
- name: set up JDK
uses: actions/setup-java@v3
with:
java-version: "19"
distribution: "temurin"
cache: "gradle"
- name: Create the Android project
run: npx cap add android
- name: Guarantee scripts execution permission
run: chmod +x ./scripts/*
- name: Set apk version number
if: startsWith(github.ref, 'refs/tags/v')
run: npm run setVersionNumber
- name: Sync the web code and Build apk
run: npm run build:apk
# Rename
- name: Rename unversioned built apk
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
run: mv "${OUTPUT_APK_PATH}/${APP_DEBUG}" "${OUTPUT_APK_PATH}/${APP_NAME_UNVERSIONED_WITH_EXTENSION}"
- name: Rename versioned built apk
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: mv "${OUTPUT_APK_PATH}/${APP_DEBUG}" "${OUTPUT_APK_PATH}/${APP_NAME_VERSIONED_WITH_EXTENSION}"
# Upload
- name: Upload apk when pushing the branch "apk"
if: startsWith(github.ref, 'refs/heads/apk')
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME_UNVERSIONED_WITH_EXTENSION }}
path: ${{ env.OUTPUT_APK_PATH }}/${{ env.APP_NAME_UNVERSIONED_WITH_EXTENSION }}
- name: Upload apk when pushing a version tag
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME_VERSIONED_WITH_EXTENSION }}
path: ${{ env.OUTPUT_APK_PATH }}/${{ env.APP_NAME_VERSIONED_WITH_EXTENSION }}
- name: Upload output-metadata.json
uses: actions/upload-artifact@v3
with:
name: output-metadata.json
path: ${{ env.OUTPUT_APK_PATH }}/output-metadata.json
# - name: Get latest version tag
# id: git-version-tag
# run: |
# latestButOneVersionTag="$(git for-each-ref --sort=-creatordate --count 2 --format="%(refname:short)" "refs/tags/v*"|tail --lines 1)"
# echo "LATEST_BUT_ONE_VERSION_TAG=${lastVersionTag}" >> "$GITHUB_OUTPUT"
- name: Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
# body: "**Full Changelog**: https://github.com/${GITHUB_REPOSITORY}/compare/${{ steps.git-version-tag.outputs.LATEST_BUT_ONE_VERSION_TAG }}...${{github.ref_name}}"
# Can't use quotes here
files: |
${{ env.OUTPUT_APK_PATH }}/${{ env.APP_NAME_VERSIONED_WITH_EXTENSION }}
${{ env.OUTPUT_APK_PATH }}/output-metadata.json
# Name of the release
name: apk ${{github.ref_name}}