Skip to content

Commit 9739b02

Browse files
committed
Add build and create release action
1 parent 8916cff commit 9739b02

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build and create release
2+
on: workflow_dispatch
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Check out repository
9+
uses: actions/checkout@v4
10+
11+
- name: Set up JDK 17
12+
uses: actions/setup-java@v4
13+
with:
14+
java-version: 17
15+
distribution: "temurin"
16+
cache: 'gradle'
17+
18+
- name: Extract version, version code, changelog and some paths
19+
run: |
20+
echo "VERSION=$(sed -nE 's~versionName ?= ?\"(.*)\"~\1~p' app/build.gradle.kts | tr -d ' ' )" >> "$GITHUB_ENV"
21+
echo "VERSION_CODE=$(sed -nE 's~versionCode ?= ?(.*)~\1~p' app/build.gradle.kts | tr -d ' ' )" >> "$GITHUB_ENV"
22+
23+
CHANGELOG_FILE="fastlane/metadata/android/en-US/changelogs/$VERSION_CODE.txt"
24+
if [ -f "$CHANGELOG_FILE" ]; then
25+
cp "$CHANGELOG_FILE" "__changelog_file__";
26+
sed -Ei 's/^([a-zA-Z0-9 ]+):$/### \1/g' "__changelog_file__";
27+
sed -i 's/•/-/g' "__changelog_file__";
28+
else
29+
echo "Did not find changelog file";
30+
touch "__changelog_file__";
31+
fi;
32+
33+
BUILD_TOOLS_PATH="$("$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --list_installed | grep build-tools/ | tail -n 1 | sed -nE 's~^.*(build-tools/[^ \t]+).*$~\1~p')"
34+
echo "APKSIGNER=$ANDROID_HOME/$BUILD_TOOLS_PATH/apksigner" >> $GITHUB_ENV
35+
36+
- name: Print some information
37+
env:
38+
VERSION: ${{ env.VERSION }}
39+
VERSION_CODE: ${{ env.VERSION_CODE }}
40+
APKSIGNER: ${{ env.APKSIGNER }}
41+
run: |
42+
echo "Version: $VERSION" >> "$GITHUB_STEP_SUMMARY"
43+
echo "Version code: $VERSION_CODE" >> "$GITHUB_STEP_SUMMARY"
44+
echo "Build directory: $BUILD_DIR" >> "$GITHUB_STEP_SUMMARY"
45+
echo "Android home: $ANDROID_HOME" >> "$GITHUB_STEP_SUMMARY"
46+
echo "Chosen apksigner: $APKSIGNER" >> "$GITHUB_STEP_SUMMARY"
47+
echo "Available Android build-tools:" "$(ls "$ANDROID_HOME/build-tools/" | xargs)" >> "$GITHUB_STEP_SUMMARY"
48+
echo >> "$GITHUB_STEP_SUMMARY"
49+
echo "Changelog:" >> "$GITHUB_STEP_SUMMARY"
50+
cat "__changelog_file__" >> "$GITHUB_STEP_SUMMARY"
51+
52+
- name: Build release APK
53+
run: ./gradlew assembleRelease
54+
55+
- name: Move APK to folder for upload
56+
env:
57+
VERSION: ${{ env.VERSION }}
58+
run: |
59+
mkdir apks
60+
mv "app/release/app-release.apk" "./apks/Dicio_${VERSION}.apk"
61+
62+
- name: Sign APKs
63+
env:
64+
KEYSTORE_BASE64: ${{ secrets.SIGNING_KEYSTORE_BASE64 }}
65+
KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
66+
KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
67+
VERSION: ${{ env.VERSION }}
68+
APKSIGNER: ${{ env.APKSIGNER }}
69+
run: |
70+
openssl base64 -A -d -out keystore.jks <<< "$KEYSTORE_BASE64"
71+
"$APKSIGNER" sign --ks ./keystore.jks --ks-key-alias "$KEY_ALIAS" --ks-pass "pass:$KEYSTORE_PASSWORD" "./apks/Dicio_${VERSION}.apk"
72+
73+
- name: Upload artifacts
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: apks
77+
path: apks
78+
79+
- name: Make sure not to overwrite the APKs of a release that was already released
80+
id: get_release
81+
uses: joutvhu/get-release@v1
82+
with:
83+
tag_name: v${{ env.VERSION }}
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
87+
- name: Create draft release
88+
id: create_release
89+
# if the release exists and is a draft, or the release does not exists,
90+
# proceed with uploading/overwriting artifacts
91+
if: ${{ (steps.get_release.outputs.draft == 'true') || (steps.get_release.outputs.draft == '') }}
92+
uses: softprops/action-gh-release@v1
93+
with:
94+
tag_name: v${{ env.VERSION }}
95+
name: ${{ env.VERSION }}
96+
body_path: __changelog_file__
97+
draft: true
98+
files: |
99+
apks/Dicio_${{ env.VERSION }}.apk

0 commit comments

Comments
 (0)