Skip to content

Commit

Permalink
Add release workflow (#60)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Goooler authored Jun 18, 2024
1 parent 7133d4f commit 073e990
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
42 changes: 39 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand All @@ -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<AbstractJPackageTask>("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)
}

0 comments on commit 073e990

Please sign in to comment.