set up releases #3
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: Maven Central Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| jobs: | |
| publish: | |
| name: Publish to Maven Central | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Important for versioning extension to work correctly | |
| - name: Set up git for versioning | |
| run: | | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "GitHub Actions" | |
| # Make sure we're on a proper branch, not in detached HEAD state | |
| if [[ -z $(git symbolic-ref --short -q HEAD) ]]; then | |
| echo "In detached HEAD state, creating temporary branch" | |
| git checkout -b temp-branch | |
| fi | |
| # Debug git info | |
| echo "Current commit hash: $(git rev-parse --short HEAD)" | |
| echo "Current branch: $(git symbolic-ref --short -q HEAD || echo 'DETACHED')" | |
| - name: Set up JDK 8 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 8 | |
| distribution: "temurin" | |
| cache: maven | |
| server-id: ossrh | |
| server-username: OSSRH_USERNAME | |
| server-password: OSSRH_PASSWORD | |
| settings-path: ${{ github.workspace }}/.mvn/settings.xml | |
| - name: Install GPG key | |
| run: | | |
| echo "${{ secrets.GPG_PRIVATE_KEY }}" | base64 --decode | gpg --batch --import | |
| gpg --list-secret-keys --keyid-format LONG | |
| # Determine if this is a tag push (release) or branch push (snapshot) | |
| - name: Set release type | |
| id: release_type | |
| run: | | |
| echo "GitHub ref: $GITHUB_REF" | |
| if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
| echo "IS_RELEASE=true" >> $GITHUB_ENV | |
| echo "This is a release build from tag ${GITHUB_REF#refs/tags/}" | |
| else | |
| echo "IS_RELEASE=false" >> $GITHUB_ENV | |
| echo "This is a snapshot build from branch ${GITHUB_REF#refs/heads/}" | |
| fi | |
| # Build and test | |
| - name: Build and test | |
| run: mvn clean verify -DskipTests | |
| # For releases | |
| - name: Deploy release to Maven Central | |
| if: env.IS_RELEASE == 'true' | |
| run: | | |
| mvn deploy -P sonatype -DskipTests \ | |
| -s ${{ github.workspace }}/.github/settings.xml | |
| env: | |
| OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
| OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | |
| GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
| # For snapshots | |
| - name: Deploy snapshot to Maven Central | |
| if: env.IS_RELEASE == 'false' | |
| run: | | |
| mvn deploy -DskipTests \ | |
| -s ${{ github.workspace }}/.github/settings.xml | |
| env: | |
| OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
| OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | |
| GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |