diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ebf4365..127c2b7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 @@ -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 }} diff --git a/build.gradle.kts b/build.gradle.kts index 409903a..69e19eb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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) @@ -19,6 +20,7 @@ repositories { version = "1.6.6" val baseName = "Kotlin Explorer" +val distributionBaseName = "kotlin-explorer" kotlin { jvm { @@ -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 @@ -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("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) + } +} \ No newline at end of file