Build and Release #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Release | |
on: | |
workflow_dispatch: | |
inputs: | |
beta: | |
type: boolean | |
description: Is beta? | |
draft: | |
type: boolean | |
description: Is draft? | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Setup Android SDK | |
uses: android-actions/[email protected] | |
- name: Extract Version From Gradle File | |
id: extract_version_from_gradle | |
run: | | |
# Extract versionName and versionCode | |
versionName=$(grep -oP '(?<=versionName = ")[^"]*' app/build.gradle.kts) | |
versionCode=$(grep -oP '(?<=versionCode = )\\d+' app/build.gradle.kts) | |
echo "Extracted versionName: $versionName" # Debug print | |
echo "Extracted versionCode: $versionCode" # Debug print | |
# If extraction fails, exit with an error | |
if [ -z "$versionName" ]; then | |
echo "Error: versionName not found" | |
exit 1 | |
fi | |
if [ -z "$versionCode" ]; then | |
echo "Error: versionCode not found" | |
exit 1 | |
fi | |
# Converting versionCode from numeric to semantic version | |
major=$((versionCode / 100)) | |
minor=$(((versionCode / 10) % 10)) | |
patch=$((versionCode % 10)) | |
semanticVersion="v$major.$minor.$patch" | |
echo "Derived semanticVersion: $semanticVersion" # Debug print | |
echo "versionName=$versionName" >> $GITHUB_ENV | |
echo "versionCode=$versionCode" >> $GITHUB_ENV | |
echo "VERSION_NAME=$versionName" >> $GITHUB_OUTPUT | |
echo "VERSION_CODE=$semanticVersion" >> $GITHUB_OUTPUT | |
echo "semanticVersion=$semanticVersion" >> $GITHUB_ENV | |
- name: Extract Version | |
id: extract_version | |
run: | | |
VERSION=${{ steps.extract_version_from_gradle.outputs.VERSION_NAME }} | |
SEMANTIC_VERSION=${{ steps.extract_version_from_gradle.outputs.VERSION_CODE }} | |
echo "version=$VERSION" | |
echo "semanticVersion=$SEMANTIC_VERSION" | |
if [ ${{ github.event.inputs.beta }} == true ]; then BETA=true; else BETA=false; fi | |
echo "beta=$BETA" >> $GITHUB_OUTPUT | |
TAG="v$VERSION" | |
echo "tag=$TAG" >> $GITHUB_OUTPUT | |
- name: Build Signed APK | |
run: | | |
echo "${{ secrets.keystore }}" | base64 -d > $GITHUB_WORKSPACE/signing-key.jks | |
chmod +x ./gradlew | |
./gradlew packageReleaseUniversalApk -Pandroid.injected.signing.store.file=$GITHUB_WORKSPACE/signing-key.jks -Pandroid.injected.signing.store.password=${{ secrets.keystore_password }} -Pandroid.injected.signing.key.alias=${{ secrets.key_alias }} -Pandroid.injected.signing.key.password=${{ secrets.key_password }} | |
sha256sum app/build/outputs/apk/from_bundle/release/app-release-universal.apk | cut -d " " -f 1 > app-release-universal.apk.sha256 | |
gpg --batch --pinentry-mode loopback --passphrase "${{ secrets.PGP_PASSPHRASE }}" --sign --detach-sig app-release-universal.apk.sha256 | |
- name: Create Tag | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GH_ACCESS_TOKEN }} | |
custom_tag: "${{ steps.extract_version.outputs.tag }}" | |
tag_prefix: "" | |
- name: Release | |
uses: ncipollo/release-action@v1 | |
with: | |
token: ${{ secrets.GH_ACCESS_TOKEN }} | |
tag: "${{ steps.extract_version.outputs.tag }}" | |
prerelease: "${{ steps.extract_version.outputs.beta }}" | |
draft: "${{ github.event.inputs.draft }}" | |
artifacts: app/build/outputs/apk/from_bundle/release/app-release-universal.apk | |
generateReleaseNotes: true |