Skip to content

Commit

Permalink
Add version code generation in CI (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-powell authored Jan 10, 2024
1 parent b700f10 commit a57e91a
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 64 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
39 changes: 39 additions & 0 deletions .github/workflows/build-number.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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
permissions:
contents: write
outputs:
build_number: ${{ steps.build-number.outputs.BUILD_NUMBER }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Generate build number
id: build-number
env:
INPUT_GITHUB_TOKEN: ${{ inputs.token }}
INPUT_SHA: ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha }}
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
5 changes: 4 additions & 1 deletion .github/workflows/desktop-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ concurrency:
cancel-in-progress: true

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

Build-Desktop:
runs-on: ubuntu-latest

needs: build-number
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand Down
29 changes: 16 additions & 13 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ 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
needs: build-number
steps:
- name: Check Xcode version
run: /usr/bin/xcodebuild -version
Expand Down Expand Up @@ -61,6 +65,8 @@ jobs:
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
cp $DISTRO_PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
echo "copied provisioning profiles"
ls ~/Library/MobileDevice/Provisioning\ Profiles
- name: set up JDK 17
uses: actions/setup-java@v4
Expand All @@ -74,6 +80,12 @@ jobs:
with:
gradle-home-cache-cleanup: true

# Update build number with the one generated from build-number.yml
- uses: yanamura/ios-bump-version@v1
with:
build-number: ${{ needs.build-number.outputs.build-number }}
project-path: iosApp

- 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 Expand Up @@ -109,13 +121,4 @@ jobs:
mkdir -p ./private_keys
echo "$IOS_APPSTORE_PRIVATE_KEY" | sed 's/[^A-Za-z0-9+/=]//g' | base64 --decode -o "./private_keys/AuthKey_$APPSTORE_API_KEY_ID.p8"
xcrun altool --validate-app -f ${{ runner.temp }}/Tidy.ipa -t ios --apiKey "$APPSTORE_API_KEY_ID" --apiIssuer ${{ secrets.IOS_APPSTORE_ISSUER_ID }}
xcrun altool --upload-app -f ${{ runner.temp }}/Tidy.ipa -t ios --apiKey "$APPSTORE_API_KEY_ID" --apiIssuer ${{ secrets.IOS_APPSTORE_ISSUER_ID }}
# - name: Upload app to TestFlight
# if: github.event_name == 'push'
# uses: apple-actions/upload-testflight-build@v1
# with:
# app-path: $RUNNER_TEMP/Tidy.ipa
# issuer-id: ${{ secrets.IOS_APPSTORE_ISSUER_ID }}
# api-key-id: ${{ secrets.IOS_APPSTORE_API_KEY_ID }}
# api-private-key: $RUNNER_TEMP/appstore_private_key.p8
xcrun altool --upload-app -f ${{ runner.temp }}/Tidy.ipa -t ios --apiKey "$APPSTORE_API_KEY_ID" --apiIssuer ${{ secrets.IOS_APPSTORE_ISSUER_ID }}
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.2" }
sqldelight-coroutines-extensions = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
Expand Down
12 changes: 12 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
path = "Preview Content";
sourceTree = "<group>";
};
406824592B3B644800E19DB0 /* New Group */ = {
isa = PBXGroup;
children = (
);
path = "New Group";
sourceTree = "<group>";
};
42799AB246E5F90AF97AA0EF /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand All @@ -43,6 +50,7 @@
7555FF72242A565900829871 = {
isa = PBXGroup;
children = (
406824592B3B644800E19DB0 /* New Group */,
AB1DB47929225F7C00F7AF9C /* Configuration */,
7555FF7D242A565900829871 /* iosApp */,
7555FF7C242A565900829871 /* Products */,
Expand Down Expand Up @@ -303,9 +311,11 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1.0.0;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = EY47F36LGH;
DYLIB_CURRENT_VERSION = 1.0.0;
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../composeApp/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
INFOPLIST_FILE = iosApp/Info.plist;
Expand Down Expand Up @@ -336,9 +346,11 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1.0.0;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = EY47F36LGH;
DYLIB_CURRENT_VERSION = 1.0.0;
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../composeApp/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
INFOPLIST_FILE = iosApp/Info.plist;
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 -x

TAGS=$(git show-ref --tags)

function getBuildNumberTag {
set +e
echo "$TAGS"| grep "${1:-}" | grep -oE 'build-number-[[:digit:]]+' | grep -oE '[[:digit:]]+' | sort -nr | head -1
set -e
}

CURRENT_BUILD_NUMBER=$(getBuildNumberTag "$INPUT_SHA")

OUT=$(echo "$TAGS" | grep -oE 'build-number-[[:digit:]]+')
echo "$OUT"

if [[ -z "${CURRENT_BUILD_NUMBER}" ]]; then
echo "No build number found for current SHA $INPUT_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" | sed -e 's,^\(.*://\).*,\1,g')
GITHUB_URL_HOST=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^.*://\(.*\),\1,g')

echo "Pushing build number tag build-number-$CURRENT_BUILD_NUMBER to Github ($GITHUB_REF)."

git push "${GITHUB_URL_PROTOCOL}${INPUT_GITHUB_TOKEN}@${GITHUB_URL_HOST}/${GITHUB_REPOSITORY}.git" --tags
else
echo "Found build number $CURRENT_BUILD_NUMBER for current SHA $INPUT_SHA."
echo "Skipping tag creation."
fi

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

0 comments on commit a57e91a

Please sign in to comment.