diff --git a/.github/workflows/build-linux-x64.yml b/.github/workflows/build-linux-x64.yml deleted file mode 100644 index 40c3e5d..0000000 --- a/.github/workflows/build-linux-x64.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build and Release linuxX64 - -on: - workflow_dispatch: - inputs: - version: - required: true - type: string - description: Set the version for the release in the format v1.0.0 - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: write - discussions: write - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - - name: Install dependencies - run: sudo apt-get install libcurl4-openssl-dev # note: apt-get install libcurl4-gnutls-dev doesn't work as the ktor documentation says - - - name: Build - run: ./gradlew build - - - name: Rename artifact - run: mv build/bin/native/releaseExecutable/KTSynologyDDNSCloudflareMultidomain.kexe build/bin/native/releaseExecutable/KTSynologyDDNSCloudflareMultidomainLinuxX64.kexe - - - name: Upload linuxX64 artifact - uses: actions/upload-artifact@v4 - with: - name: linuxX64-kexe - path: build/bin/native/releaseExecutable/*.kexe - - - name: Release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ github.event.inputs.version }} - files: build/bin/native/releaseExecutable/KTSynologyDDNSCloudflareMultidomainLinuxX64.kexe - generate_release_notes: true - make_latest: true \ No newline at end of file diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..5779ea6 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,50 @@ +name: Build and Release + +on: + workflow_dispatch: + inputs: + version: + required: true + type: string + description: Set the version for the release in the format v1.0.0 + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + discussions: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build linuxX64 and linuxArm64 artifacts + env: + DOCKER_CLI_EXPERIMENTAL: enabled + run: | + docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile --output type=local,dest=./build_output . + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: kexe-artifacts + path: | + build_output/KTSynologyDDNSCloudflareMultidomainLinuxX64.kexe + build_output/KTSynologyDDNSCloudflareMultidomainLinuxArm64.kexe + + - name: Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ github.event.inputs.version }} + files: | + build_output/KTSynologyDDNSCloudflareMultidomainLinuxX64.kexe + build_output/KTSynologyDDNSCloudflareMultidomainLinuxArm64.kexe + generate_release_notes: true + make_latest: true \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0daaed7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: Build + +on: + pull_request: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + discussions: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build linuxX64 and linuxArm64 artifacts + env: + DOCKER_CLI_EXPERIMENTAL: enabled + run: | + docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile --output type=local,dest=./build_output . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2465abf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Use a base image with Gradle 8.4 and JDK 21 +FROM gradle:8.4-jdk21 as builder + +# Set the working directory inside the container +WORKDIR /workspace + +# Copy the entire project into the working directory +COPY . . + +# Ensure that gradlew has execute permissions +RUN chmod +x ./gradlew + +# Install any additional dependencies needed for the build (e.g., libcurl) +RUN apt-get update && apt-get install -y libcurl4-openssl-dev + +# Create output directory for artifacts +RUN mkdir -p /workspace/build_output + +# Build for linux64 and rename the artifact +RUN ./gradlew build -PtargetPlatform=linuxX64 && \ + mv build/bin/native/releaseExecutable/KTSynologyDDNSCloudflareMultidomain.kexe /workspace/build_output/KTSynologyDDNSCloudflareMultidomainLinuxX64.kexe + +# Build for linuxArm64 and rename the artifact +RUN ./gradlew build -PtargetPlatform=linuxArm64 && \ + mv build/bin/native/releaseExecutable/KTSynologyDDNSCloudflareMultidomain.kexe /workspace/build_output/KTSynologyDDNSCloudflareMultidomainLinuxArm64.kexe \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index b71692f..3ba6201 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,14 +14,20 @@ repositories { kotlin { val hostOs = System.getProperty("os.name") val isArm64 = System.getProperty("os.arch") == "aarch64" - val isMingwX64 = hostOs.startsWith("Windows") - val nativeTarget = when { - hostOs == "Mac OS X" && isArm64 -> macosArm64("native") - hostOs == "Mac OS X" && !isArm64 -> macosX64("native") - hostOs == "Linux" && isArm64 -> linuxArm64("native") - hostOs == "Linux" && !isArm64 -> linuxX64("native") - isMingwX64 -> mingwX64("native") - else -> throw GradleException("Host OS is not supported in Kotlin/Native.") + + val targetPlatform: String? = project.findProperty("targetPlatform") as? String + + val nativeTarget = when (targetPlatform ?: "") { + "macosArm64" -> macosArm64("native") + "linuxArm64" -> linuxArm64("native") + "linuxX64" -> linuxX64("native") + "" -> when { + hostOs == "Mac OS X" && isArm64 -> macosArm64("native") + hostOs == "Linux" && isArm64 -> linuxArm64("native") + hostOs == "Linux" && !isArm64 -> linuxX64("native") + else -> throw GradleException("Host OS is not supported in Kotlin/Native.") + } + else -> throw GradleException("Unsupported target platform: $targetPlatform") } nativeTarget.apply { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4b533d8..9b1db58 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] kotlin = "2.0.20" -ktor = "3.0.0-rc-1" +ktor = "3.0.0" serialization = "1.6.3" [libraries]