Skip to content

Commit

Permalink
Added GitHub action for automatic release build
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazyphil committed Dec 22, 2022
1 parent ce5b7ce commit 9e9903d
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and Release

on:
push:
tags:
- "v*"

jobs:
apk:
name: Generate APK
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 11

- name: Make Gradle wrapper executable
run: chmod +x ./gradlew

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Build debug APK
uses: gradle/gradle-build-action@v2
with:
arguments: assembleDebug
env:
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}

- name: Extract keystore to disk
run: 'echo "${{ secrets.STORE_FILE }}" | base64 -d > ./release.keystore'
shell: bash

- name: Build release APK
uses: gradle/gradle-build-action@v2
with:
arguments: assembleRelease
env:
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}

- name: Remove keystore from disk
run: rm ./release.keystore

- name: Upload debug APK
uses: actions/upload-artifact@v3
with:
name: apk-debug
path: app/build/outputs/apk/debug/app-debug.apk

- name: Upload release APK
uses: actions/upload-artifact@v3
with:
name: apk
path: app/build/outputs/apk/release/app-release.apk

release:
name: Release APK
needs: apk
runs-on: ubuntu-latest
steps:
- name: Download APK from build
uses: actions/download-artifact@v1
with:
name: apk

- name: Upload Release APK
uses: softprops/action-gh-release@v1
with:
files: apk/*
prerelease: ${{ contains(github.ref_name, '-') }}
fail_on_unmatched_files: true
generate_release_notes: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.iml
.gradle
/keystore.properties
/local.properties
/release.keystore
/.idea/caches
/.idea/libraries
/.idea/modules.xml
Expand Down
24 changes: 24 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@ plugins {
id 'org.jetbrains.kotlin.android'
}

def keystoreProperties = new Properties()
if (System.getenv('CI') != null) {
keystoreProperties.setProperty('build.storePassword', System.getenv('STORE_PASSWORD'))
keystoreProperties.setProperty('build.keyAlias', System.getenv('KEY_ALIAS'))
keystoreProperties.setProperty('build.keyPassword', System.getenv('KEY_PASSWORD'))
}

def keystorePropertiesFile = rootProject.file('keystore.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
signingConfigs {
release {
storeFile file('../release.keystore')
storePassword keystoreProperties['build.storePassword']
keyAlias keystoreProperties['build.keyAlias']
keyPassword keystoreProperties['build.keyPassword']
}
}
compileSdk 32

defaultConfig {
Expand All @@ -18,6 +38,10 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.debug
}
}
compileOptions {
Expand Down

0 comments on commit 9e9903d

Please sign in to comment.