diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 818cb7f..eeb1de7 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -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 diff --git a/.github/workflows/build-number.yml b/.github/workflows/build-number.yml new file mode 100644 index 0000000..abe5fa6 --- /dev/null +++ b/.github/workflows/build-number.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 61453fd..55548e1 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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: diff --git a/.github/workflows/desktop-web.yml b/.github/workflows/desktop-web.yml index 1f8dc58..a99fe3c 100644 --- a/.github/workflows/desktop-web.yml +++ b/.github/workflows/desktop-web.yml @@ -11,6 +11,9 @@ concurrency: cancel-in-progress: true jobs: + build-number: + uses: ./.github/workflows/build-number.yml + Build-Desktop: runs-on: ubuntu-latest diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 48b0a1e..27acf95 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -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 @@ -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 diff --git a/.run/android.run.xml b/.run/android.run.xml deleted file mode 100644 index 4c76b02..0000000 --- a/.run/android.run.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 09a408f..d09da0f 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -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 { diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 1b251df..eea3714 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -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 { @@ -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() } } } diff --git a/gradle.properties b/gradle.properties index 3d8d5b1..69fd7b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 @@ -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 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a818a05..05ec6db 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } @@ -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" } @@ -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" } diff --git a/scripts/build-number.sh b/scripts/build-number.sh new file mode 100755 index 0000000..8542b3a --- /dev/null +++ b/scripts/build-number.sh @@ -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" \ No newline at end of file