Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ jobs:
build:
strategy:
matrix:
os: [ macos-15-intel, macos-latest ]
os: [ macos-15-intel, macos-latest, windows-latest ]
include:
- os: macos-15-intel
outputDirName: dmg
- os: macos-latest
outputDirName: dmg
- os: windows-latest
outputDirName: msi
runs-on: ${{ matrix.os }}
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
Expand All @@ -20,13 +28,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: gradle/actions/setup-gradle@v3
- run: ./gradlew build
- run: ./gradlew packageAndRenameReleaseDistributionForCurrentOS
- uses: actions/upload-artifact@v4
with:
name: distribution-${{ matrix.os }}
if-no-files-found: error
path: |
build/compose/binaries/main-release/dmg/kotlin-explorer-*.dmg
build/compose/binaries/main-release/${{ matrix.outputDirName }}/*

release:
runs-on: ubuntu-latest
Expand All @@ -38,7 +46,11 @@ jobs:
- 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 }}" --draft --generate-notes
uses: softprops/action-gh-release@v2
with:
files: |
distribution-*/*.dmg
distribution-*/*.msi
draft: true
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
59 changes: 36 additions & 23 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@file:Suppress("UnstableApiUsage")

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
import kotlin.io.path.listDirectoryEntries
import java.nio.file.Files
import java.nio.file.StandardCopyOption

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand All @@ -19,6 +20,7 @@ repositories {

version = "1.6.6"
val baseName = "Kotlin Explorer"
val distributionBaseName = "kotlin-explorer"

kotlin {
jvm {
Expand Down Expand Up @@ -84,7 +86,7 @@ compose.desktop {
nativeDistributions {
modules("jdk.unsupported")

targetFormats(TargetFormat.Dmg, TargetFormat.Exe)
targetFormats(TargetFormat.Dmg, TargetFormat.Msi)

packageVersion = version.toString()
packageName = baseName
Expand All @@ -106,32 +108,43 @@ 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) {
val packageAndRenameReleaseDistributionForCurrentOS by tasks.registering {
group = "distribution"
description = "Rename the DMG file"
description = "Packages and renames release distributions for the current OS"
dependsOn("packageReleaseDistributionForCurrentOS")
doLast { renameReleaseDistributionForCurrentOS() }
}

val packageReleaseDmg = tasks.named<AbstractJPackageTask>("packageReleaseDmg")
// build/compose/binaries/main-release/dmg/*.dmg
val fromFile = packageReleaseDmg.map { task ->
task.destinationDir.asFile.get().toPath().listDirectoryEntries("$baseName*.dmg").single()
private fun renameReleaseDistributionForCurrentOS() {
val os = DefaultNativePlatform.getCurrentOperatingSystem()
val arch = DefaultNativePlatform.getCurrentArchitecture()

val osName = when {
os.isMacOsX -> "macos"
os.isWindows -> "windows"
else -> os.internalOs.familyName
}

from(fromFile)
into(fromFile.map { it.parent })
rename {
"kotlin-explorer-$currentArch-$version.dmg"
val archName = when {
arch.isAmd64 -> "x64"
arch.isArm64 -> "arm64"
else -> arch.name
}
}

tasks.assemble {
dependsOn(renameDmg)
}
compose.desktop.application.nativeDistributions.targetFormats.forEach { targetFormat ->
if (!targetFormat.isCompatibleWithCurrentOS) return@forEach

val distributionPath = layout.buildDirectory.get()
.dir("compose/binaries/main-release/${targetFormat.outputDirName}")
.file("$baseName-$version${targetFormat.fileExt}")
.asFile.toPath()

val newDistributionPath = distributionPath
.resolveSibling("$distributionBaseName-$osName-$archName-$version${targetFormat.fileExt}")

Files.move(distributionPath, newDistributionPath, StandardCopyOption.REPLACE_EXISTING)
}
}
Loading