Only deploy PR snapshot to Maven Central when "publish-snapshot" label is set #833
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: maven-ci-build | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| types: [opened, synchronize, reopened, labeled] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| # skip if triggered by a "labeled" event with a label other than "publish-snapshot" | |
| if: github.event_name != 'pull_request' || github.event.action != 'labeled' || github.event.label.name == 'publish-snapshot' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Adopt OpenJDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: adopt | |
| java-version: '21' | |
| cache: maven | |
| server-id: central | |
| server-username: MAVEN_CENTRAL_USER | |
| server-password: MAVEN_CENTRAL_TOKEN | |
| - name: Login to registry.redhat.io | |
| uses: docker/login-action@v3.7.0 | |
| with: | |
| username: ${{ secrets.REDHAT_REGISTRY_USER }} | |
| password: ${{ secrets.REDHAT_REGISTRY_TOKEN }} | |
| registry: registry.redhat.io | |
| - name: Build with Maven | |
| run: | | |
| VERSION=${{ github.event_name == 'pull_request' && format('pr{0}-SNAPSHOT', github.event.pull_request.number) || 'latest-SNAPSHOT' }} | |
| GOAL="deploy" | |
| PROFILES="sonar,release" | |
| if [[ "${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'publish-snapshot') }}" == "true" ]]; then | |
| GOAL="install" | |
| PROFILES="sonar" | |
| fi | |
| mvn ${{ runner.debug && '-X -e' || '' }} -B $GOAL -Drevision=$VERSION -P$PROFILES | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| MAVEN_GPG_KEY: ${{ secrets.OPENAPI_OSSRH_GPG_SECRET_KEY }} | |
| MAVEN_GPG_PASSPHRASE: ${{ secrets.OPENAPI_OSSRH_GPG_SECRET_KEY_PASSWORD }} | |
| MAVEN_CENTRAL_USER: ${{ secrets.OPENAPI_OSSRH_USERNAME }} | |
| MAVEN_CENTRAL_TOKEN: ${{ secrets.OPENAPI_OSSRH_TOKEN }} | |
| - name: Publish doc | |
| if: github.ref == 'refs/heads/main' | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./target/site | |
| destination_dir: latest | |
| user_name: 'github-actions[bot]' | |
| user_email: 'github-actions[bot]@users.noreply.github.com' | |
| full_commit_message: Publish latest doc |