|
89 | 89 | done |
90 | 90 | echo "::error::Could not sync $RELEASE_TAG back to scalar-next after 3 attempts." |
91 | 91 | exit 1 |
| 92 | + publish: |
| 93 | + needs: release-please |
| 94 | + # `!cancelled()` keeps publishing even when the back-sync to the integration branch |
| 95 | + # failed: a raced integration branch must not block the release from reaching its |
| 96 | + # registry. |
| 97 | + if: ${{ !cancelled() && needs.release-please.outputs.release_created == 'true' }} |
| 98 | + runs-on: ubuntu-latest |
| 99 | + # Job-level permissions replace the workflow's release-cutting grants with the publish |
| 100 | + # floor. OIDC trusted publishing verifies this run's claims, which name this workflow |
| 101 | + # file — register release-please.yml as the trusted publisher on the registry. |
| 102 | + permissions: |
| 103 | + contents: read |
| 104 | + id-token: write |
| 105 | + packages: write |
| 106 | + env: |
| 107 | + VERSIONING_POLICY: manual |
| 108 | + steps: |
| 109 | + # Publishing runs inline — a top-level job of this same run — rather than dispatching |
| 110 | + # sdk-release.yml: workflow_dispatch resolves the target workflow on the repository's |
| 111 | + # default branch only, so a dispatch would 404 whenever the release line is any other |
| 112 | + # branch, while OIDC trusted publishing accepts this job because it stays top-level |
| 113 | + # (never a reusable-workflow call). The release-please job cut the tag earlier in this |
| 114 | + # run; checking it out publishes exactly the released commit, not the branch head that |
| 115 | + # triggered the workflow. |
| 116 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 117 | + with: |
| 118 | + ref: ${{ needs.release-please.outputs.tag_name }} |
| 119 | + - uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 |
| 120 | + with: |
| 121 | + distribution: temurin |
| 122 | + java-version: "21" |
| 123 | + # `enhanced` (the default) is proprietary — free for public repos, a free preview for |
| 124 | + # private. `basic` is MIT `actions/cache` but keeps no restore keys: a dependency change |
| 125 | + # rebuilds the cache cold. |
| 126 | + - uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0 |
| 127 | + with: |
| 128 | + cache-provider: basic |
| 129 | + - run: ./gradlew build |
| 130 | + - name: Publish to Maven Central |
| 131 | + run: | |
| 132 | + GROUP_PATH="$(echo 'com.scalar' | tr '.' '/')" |
| 133 | + VERSION="$(sed -n 's/^[[:space:]]*version = "\(.*\)"$/\1/p' build.gradle.kts | head -n1)" |
| 134 | + if curl -sf -A "scalar-sdk-release" -o /dev/null "https://repo1.maven.org/maven2/${GROUP_PATH}/scalar-java/${VERSION}/scalar-java-${VERSION}.pom"; then |
| 135 | + echo "com.scalar:scalar-java:${VERSION} already on Maven Central, skipping" |
| 136 | + else |
| 137 | + ./gradlew publishToMavenCentral --no-configuration-cache |
| 138 | + fi |
| 139 | + env: |
| 140 | + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME || secrets.SONATYPE_USERNAME }} |
| 141 | + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD || secrets.SONATYPE_PASSWORD }} |
| 142 | + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_GPG_PRIVATE_KEY || secrets.GPG_SIGNING_KEY }} |
| 143 | + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_GPG_PASSPHRASE || secrets.GPG_SIGNING_PASSWORD }} |
0 commit comments