From 073e990351aa87a0d62e7103b42ee8254558c015 Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Tue, 18 Jun 2024 13:22:27 -0400 Subject: [PATCH] Add release workflow (#60) * Rename output dmg ```sh ./gradlew build ... ls build/compose/binaries/main/dmg kotlin-explorer-x64-1.4.3.dmg ``` * Build on macos-latest * Upload dists * Try macos-12 * Add release workflow * Don't release in forks * Tweak rename task * Limit uploading step for tags only --- .github/workflows/presubmit.yml | 31 +++++++++++++++++++++++- build.gradle.kts | 42 ++++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 2a7ef4e6..c7e40495 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -4,13 +4,20 @@ on: push: branches: - main + tags: + - '**' pull_request: branches: - main jobs: build: - runs-on: ubuntu-latest + strategy: + matrix: + # macos-12 is for the x64 (intel) architecture + # https://github.com/actions/runner-images?tab=readme-ov-file#available-images + os: [ macos-12, macos-latest ] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 @@ -19,3 +26,25 @@ jobs: java-version: 17 - uses: gradle/actions/setup-gradle@v3 - run: ./gradlew build + - uses: actions/upload-artifact@v4 + if: startsWith(github.ref, 'refs/tags/') + with: + name: distribution-${{ matrix.os }} + if-no-files-found: error + path: | + build/compose/binaries/main/dmg/kotlin-explorer-*.dmg + + release: + runs-on: ubuntu-latest + if: github.repository_owner == 'romainguy' && startsWith(github.ref, 'refs/tags/') + needs: build + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + - name: Create release and upload dists + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "${{ github.ref_name }}" **/*.dmg -t "${{ github.ref_name }}" --generate-notes diff --git a/build.gradle.kts b/build.gradle.kts index e2b386c5..5c331e35 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ @file:Suppress("UnstableApiUsage") import org.jetbrains.compose.desktop.application.dsl.TargetFormat +import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask +import kotlin.io.path.listDirectoryEntries plugins { alias(libs.plugins.kotlin.multiplatform) @@ -15,6 +17,9 @@ repositories { maven("https://packages.jetbrains.team/maven/p/kpm/public/") } +version = "1.4.3" +val baseName = "Kotlin Explorer" + kotlin { jvm { @Suppress("OPT_IN_USAGE") @@ -73,9 +78,9 @@ compose.desktop { targetFormats(TargetFormat.Dmg) - packageVersion = "1.4.3" - packageName = "Kotlin Explorer" - description = "Kotlin Explorer" + packageVersion = version.toString() + packageName = baseName + description = baseName vendor = "Romain Guy" licenseFile = rootProject.file("LICENSE") @@ -87,3 +92,34 @@ compose.desktop { } } } + +val currentArch: String = when (val osArch = System.getProperty("os.arch")) { + "x86_64", "amd64" -> "x64" + "aarch64" -> "arm64" + else -> error("Unsupported OS arch: $osArch") +} + +/** + * TODO: workaround for https://github.com/JetBrains/compose-multiplatform/issues/4976. + */ +val renameDmg by tasks.registering(Copy::class) { + group = "distribution" + description = "Rename the DMG file" + + val packageDmg = tasks.named("packageDmg") + // build/compose/binaries/main/dmg/*.dmg + val fromFile = packageDmg.map { + it.appImage.get().dir("../dmg").asFile.toPath() + .listDirectoryEntries("$baseName*.dmg").single() + } + + from(fromFile) + into(fromFile.map { it.parent }) + rename { + "kotlin-explorer-$currentArch-$version.dmg" + } +} + +tasks.assemble { + dependsOn(renameDmg) +}