Trigger publish on unprefixed version tags + manual dispatch #1
Workflow file for this run
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 | |
| # Mirrors the testingbot-java release flow: publish on a version tag, sign with GPG, | |
| # push to Maven Central (Central Portal), and attach artifacts to a GitHub Release. | |
| # This repo additionally publishes to the Gradle Plugin Portal (the primary way users | |
| # apply a Gradle plugin). | |
| # | |
| # Triggers on version tags with or without a leading "v" (e.g. 0.1.0 or v0.1.0), and | |
| # can also be started manually from the Actions tab (workflow_dispatch), which publishes | |
| # whatever VERSION_NAME is set in gradle.properties. | |
| on: | |
| push: | |
| tags: [ 'v*', '[0-9]*' ] | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: read | |
| jobs: | |
| publish: | |
| name: Publish to Gradle Plugin Portal and Maven Central | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| contents: write # create the GitHub Release | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Set up Gradle | |
| uses: gradle/actions/setup-gradle@v6 | |
| - name: Verify the tag matches VERSION_NAME | |
| if: github.ref_type == 'tag' | |
| run: | | |
| VERSION=$(grep '^VERSION_NAME=' gradle.properties | cut -d= -f2) | |
| TAG=${GITHUB_REF_NAME#v} | |
| echo "gradle.properties VERSION_NAME=$VERSION, tag=$TAG" | |
| if [ "$VERSION" != "$TAG" ]; then | |
| echo "::error::Release tag ($TAG) does not match VERSION_NAME ($VERSION)." | |
| exit 1 | |
| fi | |
| - name: Build and test | |
| run: ./gradlew build --stacktrace | |
| - name: Publish to Gradle Plugin Portal | |
| run: ./gradlew publishPlugins --stacktrace | |
| env: | |
| GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} | |
| GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} | |
| - name: Publish to Maven Central | |
| run: ./gradlew publishToMavenCentral --stacktrace | |
| env: | |
| # Reuses the same org secrets as testingbot-java. | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} | |
| - name: Create GitHub Release | |
| if: github.ref_type == 'tag' | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| files: build/libs/*.jar | |
| generate_release_notes: true |