Skip to content

Commit

Permalink
Add version code generation in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-powell authored and github-actions[bot] committed Jan 9, 2024
1 parent f5c0ca3 commit 493d7ca
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ concurrency:
cancel-in-progress: true

jobs:
build-number:
uses: ./.github/workflows/build-number.yml

build-debug:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/build-number.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Number

on:
workflow_call:
outputs:
build-number:
description: "The build number generated from git tags on current SHA."
value: ${{ jobs.build.outputs.build-number }}
inputs:
token:
description: 'GitHub token or PAT token'
required: false
default: ${{ github.token }}
type: string

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
outputs:
build_number: ${{ steps.build-number.outputs.build_number }}
steps:
- uses: actions/checkout@v4
- name: Generate build number
id: build-number
env:
INPUT_GITHUB_TOKEN: ${{ inputs.token }}
run: |
./scripts/build-number.sh
5 changes: 4 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
jobs:
build-number:
uses: ./.github/workflows/build-number.yml

check:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/desktop-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ concurrency:
cancel-in-progress: true

jobs:
build-number:
uses: ./.github/workflows/build-number.yml

Build-Desktop:
runs-on: ubuntu-latest

Expand Down
23 changes: 20 additions & 3 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ on:
push:
branches:
- main
- ios-upload-testflight # TODO: this is a temporary branch for testing (REMOVE)
- ci-version-code # TODO: this is a temporary branch for testing (REMOVE)
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
jobs:
build-number:
uses: ./.github/workflows/build-number.yml

build:
runs-on: macos-latest
steps:
- name: Check Xcode version
Expand Down Expand Up @@ -74,6 +77,20 @@ jobs:
with:
gradle-home-cache-cleanup: true

# DEBUG: print out all environment variables
- name: Output Run ID
run: echo ${{ github.run_id }}
- name: Output Run Number
run: echo ${{ github.run_number }}
- name: Output Run Attempt
run: echo ${{ github.run_attempt }}



- name: Generate Version Code
run: |
echo "VERSION_CODE=$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
- name: Build Artifact with Xcode
run: xcodebuild -project iosApp/iosApp.xcodeproj -scheme iosApp -configuration Debug -destination generic/platform=iOS -archivePath $RUNNER_TEMP/Tidy.xcarchive archive

Expand Down
39 changes: 0 additions & 39 deletions .run/android.run.xml

This file was deleted.

2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.greenmiststudios.tidy"
version = "${libs.versions.version}-SNAPSHOT"
version = "${project.properties["tidy.version_name"]?.toString()}-SNAPSHOT"

@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
kotlin {
Expand Down
6 changes: 3 additions & 3 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ android {
applicationId = "com.greenmiststudios.tidy"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = libs.versions.versionCode.get().toInt()
versionName = libs.versions.version.get()
versionCode = project.properties["tidy.version_code"]?.toString()?.toInt() ?: 1
versionName = project.properties["tidy.version_name"]?.toString()
}
packaging {
resources {
Expand Down Expand Up @@ -114,7 +114,7 @@ compose.desktop {
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "com.greenmiststudios.tidy"
packageVersion = libs.versions.version.get()
packageVersion = project.properties["tidy.version_name"]?.toString()
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
tidy.version_name=1.0.0
tidy.version_code=1

kotlin.code.style=official
xcodeproj=iosApp
kotlin.native.binary.memoryModel=experimental

org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4096M"
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dkotlin.daemon.jvm.options\="-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g"
org.gradle.configuration-cache=true
# Use this flag carefully, in case some of the plugins are not fully compatible.
org.gradle.configuration-cache.problems=warn
org.gradle.configureondemand=true
org.gradle.java.installations.fromEnv=JDK_17
org.gradle.daemon=true
Expand All @@ -15,6 +20,7 @@ java.modularToolchainVersion=17
#Android
android.nonTransitiveRClass=true
android.useAndroidX=true
android.enableJetifier=false

#Compose
org.jetbrains.compose.experimental.jscanvas.enabled=true
Expand Down
8 changes: 3 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ androidx-compose = "1.5.4"
android-compileSdk = "34"
android-targetSdk = "34"
android-minSdk = "24"
version = "1.0.0"
versionCode = "1"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand All @@ -24,6 +22,9 @@ sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
spotless = { id = "com.diffplug.spotless", version = "6.23.3" }

[libraries]
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.6.1" }
androidx-core = { module = "androidx.core:core-ktx", version = "1.12.0" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.8.2" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" }
ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-core-wasm = { module = "io.ktor:ktor-client-core-wasm", version.ref = "ktor" }
Expand All @@ -36,9 +37,6 @@ koin-compose = { module = "io.insert-koin:koin-compose", version = "1.1.2" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version = "1.7.3" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.6.1" }
androidx-core = { module = "androidx.core:core-ktx", version = "1.12.0" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.8.2" }
material-compose = { module = "androidx.compose.material3:material3", version = "1.2.0-beta01" }
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version = "1.3.1" }
sqldelight-coroutines-extensions = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
Expand Down
45 changes: 45 additions & 0 deletions scripts/build-number.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set +e
set -x

git pull --tags

function getBuildNumberTag {
git show-ref --tags | grep "${1:-}" | grep -oE "build-number-(\d+)" | grep -oE "\d+" | sort -nr | head -1
}

CURRENT_BUILD_NUMBER=$(getBuildNumberTag "$GITHUB_SHA")

if [[ -z "${CURRENT_BUILD_NUMBER}" ]]; then
echo "No build number found for current SHA $GITHUB_SHA."

# Get the latest build number
LATEST_BUILD_NUMBER=$(getBuildNumberTag)

if [[ -z "${LATEST_BUILD_NUMBER}" ]]; then
echo "No build number found in tags. Please create a tag with the format 'build-number-1' on main branch."
exit 1
fi

CURRENT_BUILD_NUMBER="$((LATEST_BUILD_NUMBER + 1))"
git tag "build-number-$CURRENT_BUILD_NUMBER"

git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

GITHUB_URL_PROTOCOL="$(echo "$GITHUB_SERVER_URL" | grep :// | sed -e's,^\(.*://\).*,\1,g')"

REMOTE_REPO="${GITHUB_URL_PROTOCOL}//oauth2:${INPUT_GITHUB_TOKEN}@${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
PUSH_PARAMETERS="${REMOTE_REPO}"
echo "$GITHUB_URL_PROTOCOL"
echo "Pushing build number tag build-number-$CURRENT_BUILD_NUMBER to Github ($GITHUB_REF)."

git push "$PUSH_PARAMETERS" --tags
else
echo "Found build number $CURRENT_BUILD_NUMBER for current SHA $GITHUB_SHA."
echo "Skipping tag creation."
fi

set -e

echo "BUILD_NUMBER=$CURRENT_BUILD_NUMBER" > "$GITHUB_ENV"

0 comments on commit 493d7ca

Please sign in to comment.