Auto-release to Maven Central on version tags (#237) #130
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| push: | |
| tags: | |
| - "v[0-9]+.[0-9]+.[0-9]+" | |
| - "v[0-9]+.[0-9]+.[0-9]+-*" | |
| branches: | |
| - main | |
| - develop | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| name: Publish to Maven Central | |
| runs-on: ubuntu-latest | |
| environment: Main | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./.github/actions/setup-build-env | |
| - name: Determine version | |
| id: version | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| # Release: strip the leading "v" from the tag (e.g. v1.0.0 -> 1.0.0) | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| else | |
| # SNAPSHOT: read baseline from gradle.properties and append -SNAPSHOT | |
| BASE=$(grep "^VERSION_NAME=" gradle.properties | cut -d= -f2 | sed 's/-SNAPSHOT//') | |
| VERSION="${BASE}-SNAPSHOT" | |
| fi | |
| echo "VERSION_NAME=${VERSION}" | tee -a "$GITHUB_OUTPUT" | |
| - name: Publish to Maven Central | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_KEY_ID }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_KEY_PASSWORD }} | |
| ORG_GRADLE_PROJECT_VERSION_NAME: ${{ steps.version.outputs.VERSION_NAME }} | |
| # On a version tag: pass -PmavenCentralAutomaticPublishing=true so the Vanniktech plugin | |
| # releases the Central deployment automatically (no manual staging promote needed). | |
| # On SNAPSHOT branch pushes: plain upload to the snapshots repo, no auto-release. | |
| # --no-configuration-cache for release-pipeline debuggability (runs once per tag, CC savings are zero). | |
| run: | | |
| AUTO="" | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| AUTO="-PmavenCentralAutomaticPublishing=true" | |
| fi | |
| ./gradlew --no-daemon publishToMavenCentral $AUTO --no-configuration-cache | |
| publish-xcframework: | |
| name: Publish XCFramework to GitHub Release | |
| # Only runs for version tags — not for SNAPSHOT pushes to main. | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: macos-latest | |
| permissions: | |
| contents: write # Required to upload release assets and update Package.swift | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - uses: gradle/actions/setup-gradle@v6 | |
| - name: Build XCFramework | |
| run: ./gradlew --no-daemon :core:zipXCFramework | |
| - name: Compute checksum | |
| id: checksum | |
| run: | | |
| CHECKSUM=$(swift package compute-checksum core/build/xcframeworks/FeaturedCore.xcframework.zip) | |
| echo "CHECKSUM=${CHECKSUM}" | tee -a "$GITHUB_OUTPUT" | |
| - name: Create or update GitHub Release and upload XCFramework | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Create the release if it doesn't already exist (idempotent) | |
| gh release create "${{ github.ref_name }}" \ | |
| --title "${{ github.ref_name }}" \ | |
| --generate-notes \ | |
| 2>/dev/null || true | |
| gh release upload "${{ github.ref_name }}" \ | |
| core/build/xcframeworks/FeaturedCore.xcframework.zip \ | |
| --clobber | |
| - name: Update Package.swift checksum and URL | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| CHECKSUM: ${{ steps.checksum.outputs.CHECKSUM }} | |
| run: | | |
| ASSET_URL="https://github.com/AndroidBroadcast/Featured/releases/download/${TAG}/FeaturedCore.xcframework.zip" | |
| sed -i '' \ | |
| -e "s|url: \".*FeaturedCore.xcframework.zip\"|url: \"${ASSET_URL}\"|" \ | |
| -e "s|checksum: \"[0-9a-f]*\"|checksum: \"${CHECKSUM}\"|" \ | |
| Package.swift | |
| - name: Commit updated Package.swift | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Package.swift | |
| git diff --cached --quiet && echo "No changes to commit" && exit 0 | |
| git commit -m "chore: update Package.swift checksum for ${{ github.ref_name }}" | |
| # Fetch latest main first to reduce push conflicts | |
| git fetch origin main | |
| git push origin HEAD:main |