Repository navigation
Release #2
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: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version (e.g., 2.0.0 or 2.0.0-SNAPSHOT)' | |
| required: true | |
| type: string | |
| dry_run: | |
| description: 'Dry run (skip actual publishing)' | |
| required: false | |
| type: boolean | |
| default: false | |
| # Restrict to repository owner only | |
| jobs: | |
| release: | |
| name: Publish to Maven Central | |
| runs-on: ubuntu-latest | |
| if: github.actor == github.repository_owner | |
| permissions: | |
| contents: write # For creating releases and tags | |
| steps: | |
| - name: Validate version format | |
| id: version | |
| run: | | |
| VERSION="${{ inputs.version }}" | |
| if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then | |
| echo "::error::Invalid version format: $VERSION" | |
| echo "Expected format: X.Y.Z or X.Y.Z-suffix (e.g., 2.0.0, 2.0.0-SNAPSHOT, 2.0.0-beta01)" | |
| exit 1 | |
| fi | |
| if [[ "$VERSION" == *"SNAPSHOT"* ]]; then | |
| echo "is_snapshot=true" >> $GITHUB_OUTPUT | |
| echo "Version $VERSION is a SNAPSHOT" | |
| else | |
| echo "is_snapshot=false" >> $GITHUB_OUTPUT | |
| echo "Version $VERSION is a release" | |
| fi | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Full history for changelog generation | |
| - name: Validate Gradle Wrapper | |
| uses: gradle/wrapper-validation-action@v3 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| - name: Run checks | |
| run: ./gradlew check --stacktrace | |
| # SNAPSHOT: publish without releasing (no staging close) | |
| - name: Publish SNAPSHOT to Maven Central | |
| if: ${{ !inputs.dry_run && steps.version.outputs.is_snapshot == 'true' }} | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
| ORG_GRADLE_PROJECT_VERSION_NAME: ${{ inputs.version }} | |
| run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache --stacktrace | |
| # Release: publish and release (close staging) | |
| - name: Publish Release to Maven Central | |
| if: ${{ !inputs.dry_run && steps.version.outputs.is_snapshot == 'false' }} | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
| ORG_GRADLE_PROJECT_VERSION_NAME: ${{ inputs.version }} | |
| run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache --stacktrace | |
| - name: Publish (Dry Run) | |
| if: ${{ inputs.dry_run }} | |
| env: | |
| ORG_GRADLE_PROJECT_VERSION_NAME: ${{ inputs.version }} | |
| run: | | |
| echo "Dry run: Would publish version ${{ inputs.version }} to Maven Central" | |
| ./gradlew publishToMavenLocal --stacktrace | |
| echo "Published to Maven Local successfully (dry run)" | |
| # Only create tag and GitHub release for non-SNAPSHOT versions | |
| - name: Create Git Tag | |
| if: ${{ !inputs.dry_run && steps.version.outputs.is_snapshot == 'false' }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then | |
| echo "Tag v${{ inputs.version }} already exists, skipping tag creation" | |
| else | |
| git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}" | |
| git push origin "v${{ inputs.version }}" | |
| fi | |
| - name: Create GitHub Release | |
| if: ${{ !inputs.dry_run && steps.version.outputs.is_snapshot == 'false' }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ inputs.version }} | |
| name: v${{ inputs.version }} | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: ${{ contains(inputs.version, '-') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| run: | | |
| VERSION="${{ inputs.version }}" | |
| IS_SNAPSHOT="${{ steps.version.outputs.is_snapshot }}" | |
| DRY_RUN="${{ inputs.dry_run }}" | |
| if [[ "$DRY_RUN" == "true" ]]; then | |
| echo "## Dry Run Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "Version **$VERSION** was validated and built successfully." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "To perform the actual publish, run this workflow again with 'Dry run' unchecked." >> $GITHUB_STEP_SUMMARY | |
| elif [[ "$IS_SNAPSHOT" == "true" ]]; then | |
| echo "## SNAPSHOT Published" >> $GITHUB_STEP_SUMMARY | |
| echo "Version **$VERSION** has been published to Maven Central Snapshots." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- Maven Central: \`com.ms-square:debugoverlay:$VERSION\`" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "## Release Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "Version **$VERSION** has been released!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- Maven Central: \`com.ms-square:debugoverlay:$VERSION\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- GitHub Release: [v$VERSION](https://github.com/${{ github.repository }}/releases/tag/v$VERSION)" >> $GITHUB_STEP_SUMMARY | |
| fi |