diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f61bf57c..f56b68fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,23 +74,25 @@ jobs: with: # The API removal check reads the dumps at the last release tag. fetch-depth: 0 - # publish.yml runs this on macOS, whose awk, sort and comm are BSD's. Running it here - # too means a difference shows on a pull request rather than first on a release tag. - - name: Check nothing the last release published was removed - run: bash scripts/check-api-removals.sh - uses: actions/setup-java@v6 with: distribution: 'zulu' java-version: '21' - uses: gradle/actions/setup-gradle@v6 + # publish.yml runs this on macOS, whose awk, sort and comm are BSD's. Running it here + # too means a difference shows on a pull request rather than first on a release tag. + # It asks Gradle for VERSION_NAME, so it runs once Java and Gradle are set up. + - name: Check nothing the last release published was removed + run: bash scripts/check-api-removals.sh # macos-15 defaults to Xcode 16.4, whose iOS SDK predates UIViewLayoutRegion — a # symbol Compose Multiplatform's ui-uikit references. Kotlin/Native static caches # link whole modules rather than tree-shaking, so any iOS *test executable* fails to # link without a 26.x SDK (the static framework link survives because an archive - # never resolves external symbols). The image ships several Xcodes; take the newest. + # never resolves external symbols). The image ships several Xcodes; take the newest + # release, by the version in each app's Info.plist, skipping betas and release candidates. - name: Select the newest installed Xcode run: | - XCODE=$(ls -d /Applications/Xcode_*.app | sort -V | tail -1) + XCODE="$(bash scripts/newest-xcode.sh)" echo "Using $XCODE" sudo xcode-select -s "$XCODE/Contents/Developer" xcodebuild -version @@ -106,7 +108,7 @@ jobs: run: ./gradlew publishToMavenLocal - name: Check each module published its six targets run: | - VERSION="$(sed -n 's/^VERSION_NAME=//p' gradle.properties)" + VERSION="$(./gradlew -q printVersionName)" for module in color color-compose colorpicker-foundation colorpicker-material3; do for suffix in "" -android -jvm -wasm-js -iosarm64 -iossimulatorarm64; do pom="$HOME/.m2/repository/codes/side/$module$suffix/$VERSION/$module$suffix-$VERSION.pom" @@ -120,4 +122,6 @@ jobs: # depends on colorpicker-material3 alone, as an app does, and links a dynamic iOS framework against what # was just published, which resolves every native symbol the libraries need. - name: Link an app against the published artifacts - run: ./gradlew -p tools/consumer compileKotlinJvm linkDebugFrameworkIosSimulatorArm64 -PpickerVersion="$(sed -n 's/^VERSION_NAME=//p' gradle.properties)" + run: | + VERSION="$(./gradlew -q printVersionName)" + ./gradlew -p tools/consumer compileKotlinJvm linkDebugFrameworkIosSimulatorArm64 -PpickerVersion="$VERSION" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 477f5092..4bc1ee39 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -55,10 +55,11 @@ jobs: # symbol Compose Multiplatform's ui-uikit references. Kotlin/Native static caches # link whole modules rather than tree-shaking, so any iOS *test executable* fails to # link without a 26.x SDK (the static framework link survives because an archive - # never resolves external symbols). The image ships several Xcodes; take the newest. + # never resolves external symbols). The image ships several Xcodes; take the newest + # release, by the version in each app's Info.plist, skipping betas and release candidates. - name: Select the newest installed Xcode run: | - XCODE=$(ls -d /Applications/Xcode_*.app | sort -V | tail -1) + XCODE="$(bash scripts/newest-xcode.sh)" echo "Using $XCODE" sudo xcode-select -s "$XCODE/Contents/Developer" xcodebuild -version @@ -66,12 +67,13 @@ jobs: # The version lives in gradle.properties, not in the tag. Publishing the wrong one # is unrecoverable because Maven Central is immutable, so refuse to start on a - # mismatch rather than redeploying an already-released coordinate. + # mismatch rather than redeploying an already-released coordinate. Gradle reads the + # version, so this compares the tag with what the publication will carry. - name: Check the tag matches VERSION_NAME if: startsWith(github.ref, 'refs/tags/v') run: | TAG_VERSION="${GITHUB_REF_NAME#v}" - PROJECT_VERSION="$(sed -n 's/^VERSION_NAME=//p' gradle.properties)" + PROJECT_VERSION="$(./gradlew -q printVersionName)" echo "tag=$TAG_VERSION gradle.properties=$PROJECT_VERSION" if [ "$TAG_VERSION" != "$PROJECT_VERSION" ]; then echo "::error::Tag $GITHUB_REF_NAME does not match VERSION_NAME=$PROJECT_VERSION. Bump VERSION_NAME and retag." @@ -98,7 +100,7 @@ jobs: # command line so gradle.properties is never edited just to test. - name: Publish to Maven Central run: | - VERSION="$(sed -n 's/^VERSION_NAME=//p' gradle.properties)" + VERSION="$(./gradlew -q printVersionName --no-configuration-cache)" if [ "${{ inputs.snapshot }}" = "true" ]; then # VERSION_NAME may be a snapshot already; it must not publish as -SNAPSHOT-SNAPSHOT. VERSION="${VERSION%-SNAPSHOT}" diff --git a/build.gradle.kts b/build.gradle.kts index d9a3bd22..bfe956e9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,3 +28,13 @@ apiValidation { enabled = true } } + +// CI and scripts/check-api-removals.sh ask Gradle for the version rather than reading gradle.properties themselves, +// so they get the one the modules publish: the file read as Gradle reads it, or a -PVERSION_NAME override. +// They run `./gradlew -q printVersionName` with -q first: the wrapper sees -q only before the first word that isn't an +// option (a task name, or an option's value such as -I's), and without it writes its download progress to stdout too. +tasks.register("printVersionName") { + description = "Prints VERSION_NAME, the version every library module publishes." + val versionName = providers.gradleProperty("VERSION_NAME") + doLast { println(versionName.get()) } +} diff --git a/scripts/check-api-removals.sh b/scripts/check-api-removals.sh index bb65adf5..45d041b1 100755 --- a/scripts/check-api-removals.sh +++ b/scripts/check-api-removals.sh @@ -30,7 +30,12 @@ git rev-parse --verify --quiet "$ref^{commit}" > /dev/null || { echo "Comparing the API dumps against $ref." # Only a vX.Y.Z tag says which major version it was; any other ref is compared without the exemption. -current_major="$(sed -n 's/^VERSION_NAME=\([0-9]*\).*/\1/p' gradle.properties)" +# Gradle reads VERSION_NAME as the build that publishes it does; its major is the digits it starts with. +version_name="$(./gradlew -q printVersionName)" || { + echo "::error::Gradle could not print VERSION_NAME." >&2 + exit 2 +} +current_major="${version_name%%[!0-9]*}" ref_version="${ref#v}" ref_major="${ref_version%%.*}" if [[ "$ref_major" =~ ^[0-9]+$ ]] && [ "$current_major" -gt "$ref_major" ]; then diff --git a/scripts/newest-xcode.sh b/scripts/newest-xcode.sh new file mode 100755 index 00000000..2cda242c --- /dev/null +++ b/scripts/newest-xcode.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# Prints the path of the newest released Xcode in /Applications, or in the directory given. +# +# An app's version is the CFBundleShortVersionString in its Info.plist, compared number by number, so 26.10 is newer +# than 26.9 whatever the app is called. A beta or a release candidate is skipped: the runner images name one +# Xcode_26.1_beta_3.app or Xcode_26.3_Release_Candidate.app, and a beta's LicenseInfo.plist says Beta too. Symlinks +# are skipped, so the release-looking names the images give a beta (Xcode_26.1.app) are not taken for a release; each +# release is listed under its own name. +# +# Usage: scripts/newest-xcode.sh [dir] +set -euo pipefail + +dir="${1:-/Applications}" + +plist_value() { + /usr/libexec/PlistBuddy -c "Print :$1" "$2" 2> /dev/null +} + +lowercase() { + printf '%s' "$1" | tr '[:upper:]' '[:lower:]' +} + +# One line per released Xcode: its major, minor and patch, then its path, tab-separated. The loop is a function, not +# written inside $(...): macOS's bash 3.2 misparses a case pattern's ) there. +releases() { + local app version + for app in "$dir"/Xcode*.app; do + if [ ! -d "$app" ] || [ -L "$app" ]; then + continue + fi + case "$(lowercase "$(basename "$app")")" in + *beta* | *release_candidate*) continue ;; + esac + case "$(lowercase "$(plist_value licenseType "$app/Contents/Resources/LicenseInfo.plist" || true)")" in + *beta*) continue ;; + esac + version="$(plist_value CFBundleShortVersionString "$app/Contents/Info.plist" || true)" + if [[ "$version" =~ ^([0-9]+)(\.([0-9]+))?(\.([0-9]+))?$ ]]; then + printf '%s\t%s\t%s\t%s\n' "${BASH_REMATCH[1]}" "${BASH_REMATCH[3]:-0}" "${BASH_REMATCH[5]:-0}" "$app" + fi + done +} + +tab="$(printf '\t')" +newest="$(releases | sort -t "$tab" -k1,1n -k2,2n -k3,3n | tail -n 1 | cut -f 4)" +if [ -z "$newest" ]; then + echo "::error::No released Xcode with a version in its Info.plist is in $dir." >&2 + exit 1 +fi +echo "$newest"