Skip to content

Commit

Permalink
Rework CI to only upload artifacts for PR builds
Browse files Browse the repository at this point in the history
CI now performs build checks on pushes to the master branch only.
For pull requests, the dev variant of the app is built and artifacts are uploaded for ease of testing and side-by-side installation. PR builds use autogenerated debug signing keys, resulting in different keys being used for each build on purpose to ensure they cannot be installed over each other, avoiding any possible conflict between two PRs.
  • Loading branch information
nickbeth committed Feb 27, 2024
1 parent 812b1d7 commit d5d6e67
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 130 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# A workflow to verify the build on every push to the master branch
name: Build

on:
push:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Restore CCache
uses: hendrikmuhs/ccache-action@v1.2
with:
max-size: 3Gi

- name: Restore Gradle Cache
uses: actions/cache@v4
with:
path: ~/.gradle/
key: ${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}-${{ hashFiles('app/**/*.xml') }}-${{ hashFiles('app/**.kt', 'app/**.java') }}
restore-keys: |
${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}-${{ hashFiles('app/**/*.xml') }}-
${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}-
${{ runner.os }}-gradle-
- name: Install Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # Temurin should come pre-installed on GitHub-hosted runners
java-version: '17'

- name: Install Ninja Build
run: |
sudo apt-get install -y ninja-build
ln -s /usr/bin/ninja .
- name: Android Assemble
env:
CMAKE_C_COMPILER_LAUNCHER: "ccache"
CMAKE_CXX_COMPILER_LAUNCHER: "ccache"
CCACHE_COMPILERCHECK: "string:${{ env.NDK_VERSION }}" # Use NDK version instead of compiler timestamp
run: ./gradlew --no-daemon --stacktrace --build-cache --parallel --configure-on-demand assembleMainlineRelease
113 changes: 0 additions & 113 deletions .github/workflows/ci.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/pr_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# A workflow to build and upload APKs for pull requests
name: PR Build

on:
pull_request:
types: [ opened, synchronize, reopened ]
branches: [ master ]

# Only allow the latest build to run for a given PR, and cancel any previous builds
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Restore CCache
uses: hendrikmuhs/ccache-action@v1.2
with:
max-size: 3Gi

- name: Restore Gradle Cache
uses: actions/cache@v4
with:
path: ~/.gradle/
key: ${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}-${{ hashFiles('app/**/*.xml') }}-${{ hashFiles('app/**.kt', 'app/**.java') }}
restore-keys: |
${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}-${{ hashFiles('app/**/*.xml') }}-
${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle') }}-
${{ runner.os }}-gradle-
- name: Install Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # Temurin should come pre-installed on GitHub-hosted runners
java-version: '17'

- name: Install Ninja Build
run: |
sudo apt-get install -y ninja-build
ln -s /usr/bin/ninja .
- name: Android Assemble
env:
CMAKE_C_COMPILER_LAUNCHER: "ccache"
CMAKE_CXX_COMPILER_LAUNCHER: "ccache"
CCACHE_COMPILERCHECK: "string:${{ env.NDK_VERSION }}" # Use NDK version instead of compiler timestamp
PR_NUMBER: ${{ github.event.number }}
run: ./gradlew --no-daemon --stacktrace --build-cache --parallel --configure-on-demand assembleDevRelease assembleDevReldebug

- name: Rename APKs
run: |
mv app/build/outputs/apk/dev/release/app-dev-release.apk strato-pr${{ github.event.number }}-release.apk
mv app/build/outputs/apk/dev/reldebug/app-dev-reldebug.apk strato-pr${{ github.event.number }}-reldebug.apk
- name: Upload Release APK
uses: actions/upload-artifact@v4
with:
name: strato-pr${{ github.event.number }}-release.apk
path: strato-pr${{ github.event.number }}-release.apk

- name: Upload Debug APK
uses: actions/upload-artifact@v4
with:
name: strato-pr${{ github.event.number }}-reldebug.apk
path: strato-pr${{ github.event.number }}-reldebug.apk
29 changes: 12 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ idea.module {
excludeDirs.add(file("libraries/boost"))
}

project.ext.isBuildSigned = (System.getenv("CI") == "true") && (System.getenv("IS_BUILD_SIGNED") == "true")

android {
namespace 'org.stratoemu.strato'
compileSdk 34
Expand Down Expand Up @@ -58,15 +56,6 @@ android {
jniLibs.useLegacyPackaging = true
}

signingConfigs {
ci {
storeFile file(System.getenv("SIGNING_STORE_PATH") ?: "${System.getenv("user.home")}/keystore.jks")
storePassword System.getenv("SIGNING_STORE_PASSWORD")
keyAlias System.getenv("SIGNING_KEY_ALIAS")
keyPassword System.getenv("SIGNING_KEY_PASSWORD")
}
}

buildTypes {
release {
debuggable true
Expand All @@ -78,7 +67,7 @@ android {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig = isBuildSigned ? signingConfigs.ci : signingConfigs.debug
signingConfig signingConfigs.debug
manifestPlaceholders["emulationProcess"] = ":emulationProcess"
}

Expand All @@ -91,14 +80,14 @@ android {
}
minifyEnabled false
shrinkResources false
signingConfig = isBuildSigned ? signingConfigs.ci : signingConfigs.debug
signingConfig signingConfigs.debug
}

debug {
debuggable true
minifyEnabled false
shrinkResources false
signingConfig = isBuildSigned ? signingConfigs.ci : signingConfigs.debug
signingConfig signingConfigs.debug
}
}

Expand Down Expand Up @@ -188,8 +177,10 @@ kapt {
* Returns the version name based on the current git state
* If HEAD is a tag, the tag name is used as the version name
* e.g. `1.0.0`
* If HEAD is not a tag, the tag name, the branch name and the short commit hash are used
* If HEAD is not a tag, the closest tag name, the branch name and the short commit hash are used
* e.g. `1.0.0-master-ab00cd11`
* If PR_NUMBER is set, prPR_NUMBER is used instead of the branch name
* e.g. `1.0.0-pr123-ab00cd11`
*/
def getGitVersionName() {
def versionName = '0.0.0'
Expand Down Expand Up @@ -248,13 +239,17 @@ def getGitShortHash() {
}

/**
* Returns the current branch name
* Returns the current branch name, or prPR_NUMBER if PR_NUMBER is set
*/
def getGitBranch() {
def branch = 'unk'

try {
branch = 'git rev-parse --abbrev-ref HEAD'.execute([], project.rootDir).text.trim()
def prNumber = System.getenv('PR_NUMBER') ?: ''
if (!prNumber.isEmpty())
branch = 'pr' + prNumber
else
branch = 'git rev-parse --abbrev-ref HEAD'.execute([], project.rootDir).text.trim()
} catch (Exception e) {
logger.error(e.toString() + ': defaulting to dummy branch ' + branch)
}
Expand Down

0 comments on commit d5d6e67

Please sign in to comment.