|
| 1 | +# Written by DocSpring/docspring's api_clients/scripts/generate from api_clients/github_workflows/java/release.yml: |
| 2 | +# change it there. |
| 3 | +# |
| 4 | +# Builds the package on every push and pull request. A v* tag (pushed by the monorepo's api_clients/scripts/release) |
| 5 | +# also signs it and publishes it to Maven Central, in the release environment, and waits until Maven Central serves |
| 6 | +# it. Maven Central has no trusted publishing: the release environment's secrets hold a Central Portal user token |
| 7 | +# (MAVEN_CENTRAL_USERNAME, MAVEN_CENTRAL_PASSWORD) and the signing key (MAVEN_GPG_PRIVATE_KEY, MAVEN_GPG_PASSPHRASE). |
| 8 | +# OpenAPI Generator's maven.yml runs the package's tests. |
| 9 | +name: Release |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: ['**'] |
| 14 | + tags: ['v*'] |
| 15 | + pull_request: |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 25 | + with: |
| 26 | + persist-credentials: false |
| 27 | + - uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 |
| 28 | + with: |
| 29 | + distribution: temurin |
| 30 | + java-version: '17' |
| 31 | + cache: maven |
| 32 | + # The runner's Maven is 3.10, which puts maven-metadata-local.xml and _remote.repositories in the bundle the |
| 33 | + # Central publishing plugin (0.10.0) uploads, and Central rejects it. Maven 3.9 doesn't. |
| 34 | + - name: Install Maven 3.9.16 |
| 35 | + run: | |
| 36 | + curl -fsSL -o "$RUNNER_TEMP/maven.tar.gz" https://archive.apache.org/dist/maven/maven-3/3.9.16/binaries/apache-maven-3.9.16-bin.tar.gz |
| 37 | + echo "831a8591fe20c8243b1dbe7d71e3244f31d1665b0804b2e825e38cbbe5ce0cafb8338851f90780735568773e0a6cd07bbec107cda0b896b008b861075358b6f6 $RUNNER_TEMP/maven.tar.gz" | sha512sum -c - |
| 38 | + tar -xzf "$RUNNER_TEMP/maven.tar.gz" -C "$RUNNER_TEMP" |
| 39 | + echo "$RUNNER_TEMP/apache-maven-3.9.16/bin" >> "$GITHUB_PATH" |
| 40 | + - name: Check the tag matches the package version |
| 41 | + if: github.ref_type == 'tag' |
| 42 | + run: | |
| 43 | + VERSION="$(mvn -B -q help:evaluate -Dexpression=project.version -DforceStdout)" |
| 44 | + if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then |
| 45 | + echo "::error::The tag is $GITHUB_REF_NAME, but the package version is $VERSION" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + - run: mvn -B -ntp -DskipTests -DskipITs package |
| 49 | + |
| 50 | + publish: |
| 51 | + needs: build |
| 52 | + if: github.ref_type == 'tag' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + environment: release |
| 55 | + steps: |
| 56 | + # Maven builds, signs and uploads the package from the source in one deploy |
| 57 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 58 | + with: |
| 59 | + persist-credentials: false |
| 60 | + - uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 |
| 61 | + with: |
| 62 | + distribution: temurin |
| 63 | + java-version: '17' |
| 64 | + server-id: central |
| 65 | + server-username: MAVEN_CENTRAL_USERNAME |
| 66 | + server-password: MAVEN_CENTRAL_PASSWORD |
| 67 | + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 68 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 69 | + # The runner's Maven is 3.10, which puts maven-metadata-local.xml and _remote.repositories in the bundle the |
| 70 | + # Central publishing plugin (0.10.0) uploads, and Central rejects it. Maven 3.9 doesn't. |
| 71 | + - name: Install Maven 3.9.16 |
| 72 | + run: | |
| 73 | + curl -fsSL -o "$RUNNER_TEMP/maven.tar.gz" https://archive.apache.org/dist/maven/maven-3/3.9.16/binaries/apache-maven-3.9.16-bin.tar.gz |
| 74 | + echo "831a8591fe20c8243b1dbe7d71e3244f31d1665b0804b2e825e38cbbe5ce0cafb8338851f90780735568773e0a6cd07bbec107cda0b896b008b861075358b6f6 $RUNNER_TEMP/maven.tar.gz" | sha512sum -c - |
| 75 | + tar -xzf "$RUNNER_TEMP/maven.tar.gz" -C "$RUNNER_TEMP" |
| 76 | + echo "$RUNNER_TEMP/apache-maven-3.9.16/bin" >> "$GITHUB_PATH" |
| 77 | + # The sign-artifacts profile signs with the imported key, and the Central publishing plugin publishes the upload |
| 78 | + # once Central has validated it (autoPublish) |
| 79 | + - run: mvn -B -ntp -DskipTests -DskipITs -P sign-artifacts -DperformRelease=true clean deploy |
| 80 | + env: |
| 81 | + MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} |
| 82 | + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} |
| 83 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 84 | + |
| 85 | + verify: |
| 86 | + needs: publish |
| 87 | + runs-on: ubuntu-latest |
| 88 | + timeout-minutes: 75 |
| 89 | + steps: |
| 90 | + # Maven Central can take an hour to serve a published release |
| 91 | + - name: Wait until Maven Central serves the version |
| 92 | + run: | |
| 93 | + VERSION="${GITHUB_REF_NAME#v}" |
| 94 | + for _ in $(seq 120); do |
| 95 | + if curl -fsS -o /dev/null "https://repo1.maven.org/maven2/com/docspring/DocSpring/$VERSION/DocSpring-$VERSION.pom"; then |
| 96 | + echo "Maven Central serves com.docspring:DocSpring $VERSION" |
| 97 | + exit 0 |
| 98 | + fi |
| 99 | + sleep 30 |
| 100 | + done |
| 101 | + echo "::error::Maven Central doesn't serve com.docspring:DocSpring $VERSION after an hour" |
| 102 | + exit 1 |
0 commit comments