From a8e69ab129da9678bee75a62e63f397ebf0947b3 Mon Sep 17 00:00:00 2001 From: Jorge Antonio Diaz-Benito Soriano Date: Mon, 15 Apr 2024 17:12:28 +0200 Subject: [PATCH] Build on each XCode version available on the runner --- .../attachXcFrameworkAndChecksum/action.yml | 44 +++++++++++++++ .github/workflows/build.yml | 28 +++++++++- .github/workflows/publish.yml | 55 +++++++++++-------- README.md | 5 +- build.gradle.kts | 6 +- 5 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 .github/actions/attachXcFrameworkAndChecksum/action.yml diff --git a/.github/actions/attachXcFrameworkAndChecksum/action.yml b/.github/actions/attachXcFrameworkAndChecksum/action.yml new file mode 100644 index 00000000..14af122f --- /dev/null +++ b/.github/actions/attachXcFrameworkAndChecksum/action.yml @@ -0,0 +1,44 @@ +name: Setup Gradle and run a task on all modules that have it +description: Includes setting up JDK +inputs: + target: + description: The release to attach to + required: true + xcodeversion: + description: The Xcode version to configure before compiling + required: true +runs: + using: composite + steps: + - uses: actions/checkout@v3.5.3 + - uses: maxim-lobanov/setup-xcode@v1.6.0 + with: + xcode-version: ${{ inputs.xcodeversion }} + - uses: ./.github/actions/runGradleTask + with: + task: :library:assembleLibraryReleaseXCFramework + - run: zip -r Library.xcframework.zip library/build/XCFrameworks/release/library.xcframework + - uses: actions/download-artifact@v4.1.4 + with: + name: upload_url + - run: echo UPLOAD_URL=$(cat upload_url | sed "s/{?name,label}/?name=Library-${{ inputs.target }}-xcodebuild-${{ matrix.xcodeversion }}.xcframework.zip/") >> $GITHUB_ENV + - run: | + curl -s \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@Library.xcframework.zip" \ + $UPLOAD_URL + - run: echo $(swift package compute-checksum Library.xcframework.zip) > checksum + - run: echo UPLOAD_URL=$(cat upload_url | sed "s/{?name,label}/?name=Library-${{ inputs.target }}-xcodebuild-${{ matrix.xcodeversion }}.xcframework.zip.checksum/") >> $GITHUB_ENV + - run: | + curl -s \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@checksum" \ + $UPLOAD_URL diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 373ac8fc..a857496e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,10 +4,36 @@ on: branches: - '**' jobs: - root: + generate-build-matrix: runs-on: macos-14-xlarge + outputs: + xcodeversions: ${{ steps.generate.outputs.xcodeversions }} + steps: + - id: generate + run: | + version_list=() + for XCODE_INSTALL in $(ls /Applications | grep Xcode); do + version_list+=("$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" /Applications/$XCODE_INSTALL/Contents/Info.plist)") + done + unique_version_list=( $(printf "%s\n" ${version_list[@]} | sort -n -u) ) + jsonString="$(jq -c --null-input '$ARGS.positional' --args -- "${unique_version_list[@]}")" + echo "xcodeversions=$jsonString" >> $GITHUB_OUTPUT + build: + runs-on: macos-14-xlarge + needs: [ generate-build-matrix ] + strategy: + matrix: + xcodeversion: ${{ fromJSON(needs.generate-build-matrix.outputs.xcodeversions) }} steps: - uses: actions/checkout@v3.5.3 + - uses: maxim-lobanov/setup-xcode@v1.6.0 + with: + xcode-version: ${{ matrix.xcodeversion }} - uses: ./.github/actions/runGradleTask with: task: build + barrier-build: + runs-on: ubuntu-22.04 + needs: [ build ] + steps: + - run: exit 0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 29213c6d..66403319 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,6 +8,8 @@ permissions: packages: write env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +concurrency: + group: ${{ github.ref_name }} jobs: ensure-tag-is-on-main: runs-on: ubuntu-22.04 @@ -17,6 +19,15 @@ jobs: ref: main fetch-depth: 0 - run: exit $(git merge-base --is-ancestor $GITHUB_REF_NAME HEAD) + jvm-maven-github: + runs-on: macos-14-xlarge + needs: [ ensure-tag-is-on-main ] + steps: + - uses: actions/checkout@v3.5.3 + - uses: ./.github/actions/runGradleTask + with: + preTaskString: -Pversion=$GITHUB_REF_NAME + task: library:publishKotlinMultiplatformPublicationToGithubPackagesRepository create-github-release: runs-on: ubuntu-22.04 needs: [ ensure-tag-is-on-main ] @@ -27,34 +38,30 @@ jobs: with: name: upload_url path: upload_url - jvm-maven-github: + generate-build-matrix: runs-on: macos-14-xlarge needs: [ ensure-tag-is-on-main ] + outputs: + xcodeversions: ${{ steps.generate.outputs.xcodeversions }} steps: - - uses: actions/checkout@v3.5.3 - - uses: ./.github/actions/runGradleTask - with: - preTaskString: -Pversion=$GITHUB_REF_NAME - task: library:publishKotlinMultiplatformPublicationToGithubPackagesRepository + - id: generate + run: | + version_list=() + for XCODE_INSTALL in $(ls /Applications | grep Xcode); do + version_list+=("$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" /Applications/$XCODE_INSTALL/Contents/Info.plist)") + done + unique_version_list=( $(printf "%s\n" ${version_list[@]} | sort -n -u) ) + jsonString="$(jq -c --null-input '$ARGS.positional' --args -- "${unique_version_list[@]}")" + echo "xcodeversions=$jsonString" >> $GITHUB_OUTPUT attach-xcframework-to-github-release: runs-on: macos-14-xlarge - needs: [ create-github-release ] + needs: [ create-github-release, generate-build-matrix ] + strategy: + fail-fast: false + matrix: + xcodeversion: ${{ fromJSON(needs.generate-build-matrix.outputs.xcodeversions) }} steps: - - uses: actions/checkout@v3.5.3 - - uses: ./.github/actions/runGradleTask + - uses: ./.github/actions/attachXcFrameworkAndChecksum with: - task: :library:assembleLibraryReleaseXCFramework - - run: zip -r Library.xcframework.zip library/build/XCFrameworks/release/library.xcframework - - uses: actions/download-artifact@v4.1.4 - with: - name: upload_url - - run: echo UPLOAD_URL=$(cat upload_url | sed "s/{?name,label}/?name=Library-${GITHUB_REF_NAME}.xcframework.zip/") >> $GITHUB_ENV - - run: | - curl -s \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Content-Type: application/octet-stream" \ - --data-binary "@Library.xcframework.zip" \ - $UPLOAD_URL + target: ${{ github.ref_name }} + xcodeversion: ${{ matrix.xcodeversion }} diff --git a/README.md b/README.md index d7dc761c..0ef79f5d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,10 @@ dependencies { SwiftPM ```swift -.package(url: "https://github.com/tidal-music/network-time-package.swift.git", .from("$VERSION")) +.binaryTarget( + url: "https://github.com/tidal-music/network-time/downloads/$VERSION/Library-$VERSION-xcodebuild-${XCODEVERSION}.xcframework.zip", + checksum: "Contents of https://github.com/tidal-music/network-time/downloads/$VERSION/Library-$VERSION-xcodebuild-$XCODEVERSION.xcframework.zip.checksum" +) ``` diff --git a/build.gradle.kts b/build.gradle.kts index 9bdb5845..e8f24b98 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,12 +4,12 @@ buildscript { google() } dependencies { - val kotlinVersion = "1.9.20" - classpath("org.jetbrains.dokka:dokka-gradle-plugin:$kotlinVersion") + val kotlinVersion = "1.9.23" + classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") // Should be $kotlinVersion when possible classpath(kotlin("gradle-plugin", version = kotlinVersion)) classpath(kotlin("serialization", version = kotlinVersion)) classpath("com.android.tools.build:gradle:8.1.4") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.10") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.6.1") } }