Merge pull request #18 from Code-Sakura/release/v1.3.2 #89
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: deploy maven central | |
| # This workflow handles deployment to Maven Central | |
| # Deployment occurs automatically in two scenarios: | |
| # 1. When code is merged to the main branch | |
| # 2. When a PR is opened or updated to merge to the main branch | |
| # For releases, use branch naming convention: release/vx.x.x (e.g., release/v1.0.0) | |
| # The version number will be extracted from the branch name | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, edited] | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| if: github.ref != 'refs/heads/main' | |
| uses: ./.github/workflows/test.yml | |
| cd: | |
| # Run on main branch or when a PR is targeting the main branch | |
| if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Import GPG key | |
| uses: crazy-max/ghaction-import-gpg@v5 | |
| with: | |
| gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | |
| - name: Set up Java | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Validate Gradle wrapper | |
| uses: gradle/wrapper-validation-action@v1 | |
| - name: Display version info | |
| run: | | |
| echo "Branch name from GITHUB_REF_NAME: $GITHUB_REF_NAME" | |
| echo "Branch name from GITHUB_HEAD_REF: $GITHUB_HEAD_REF" | |
| ./gradlew -q printVersion | |
| - name: Publish package | |
| uses: gradle/gradle-build-action@v2 | |
| with: | |
| arguments: | | |
| -PmavenCentralUsername=${{ secrets.MAVEN_USERNAME }} | |
| -PmavenCentralPassword=${{ secrets.MAVEN_PASSWORD }} | |
| -PsigningInMemoryKeyId=${{ secrets.MAVEN_GPG_KEY_ID }} | |
| -PsigningInMemoryPassword=${{ secrets.MAVEN_GPG_PASSPHRASE }} | |
| allTests publishAndReleaseToMavenCentral | |
| env: | |
| MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | |
| MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | |
| - name: Auto-merge PR on successful deployment | |
| if: success() | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GIT_TOKEN }} | |
| script: | | |
| const pr = context.payload.pull_request; | |
| if (pr) { | |
| await github.rest.pulls.merge({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number, | |
| merge_method: 'merge' | |
| }); | |
| console.log(`PR #${pr.number} has been automatically merged after successful deployment`); | |
| } | |
| ##### |