|
| 1 | +name: Maven plugin release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + java-version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + secrets: |
| 10 | + DEPS_TOKEN: |
| 11 | + required: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: plugin-release-${{ github.repository }}-${{ github.ref }} |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +defaults: |
| 21 | + run: |
| 22 | + shell: bash |
| 23 | + |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 27 | + runs-on: ubuntu-24.04 |
| 28 | + timeout-minutes: 20 |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v7 |
| 31 | + with: |
| 32 | + persist-credentials: false |
| 33 | + |
| 34 | + - uses: actions/setup-java@v6 |
| 35 | + with: |
| 36 | + distribution: temurin |
| 37 | + java-version: ${{ inputs.java-version }} |
| 38 | + |
| 39 | + - name: Validate release version |
| 40 | + env: |
| 41 | + TAG: ${{ github.ref_name }} |
| 42 | + run: | |
| 43 | + [[ "$TAG" =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]] || { |
| 44 | + echo '::error::Expected vMAJOR.MINOR or vMAJOR.MINOR.PATCH, with an optional prerelease suffix.' |
| 45 | + exit 1 |
| 46 | + } |
| 47 | + [[ "${TAG^^}" != *SNAPSHOT* ]] || exit 1 |
| 48 | +
|
| 49 | + - name: Install shared plugin dependencies |
| 50 | + uses: TF-Minecraft/TLibs/.github/actions/setup-plugins@4f7a3545063cb2e8d06a034687c817ab863f0835 |
| 51 | + with: |
| 52 | + mode: pinned |
| 53 | + private-token: ${{ secrets.DEPS_TOKEN }} |
| 54 | + |
| 55 | + - name: Prepare pinned dependencies |
| 56 | + env: |
| 57 | + GH_TOKEN: ${{ secrets.DEPS_TOKEN }} |
| 58 | + run: | |
| 59 | + if [[ -f .github/scripts/prepare-release.sh ]]; then |
| 60 | + bash .github/scripts/prepare-release.sh |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Set version from tag and build |
| 64 | + id: maven |
| 65 | + env: |
| 66 | + TAG: ${{ github.ref_name }} |
| 67 | + run: | |
| 68 | + mvn -B --no-transfer-progress -P'!deploy-live' org.codehaus.mojo:versions-maven-plugin:2.22.0:set \ |
| 69 | + -DnewVersion="${TAG#v}" -DgenerateBackupPoms=false |
| 70 | + mvn -B --no-transfer-progress -P'!deploy-live' help:evaluate \ |
| 71 | + -Dexpression=project.build.finalName -Doutput="$RUNNER_TEMP/final-name" |
| 72 | + final_name=$(cat "$RUNNER_TEMP/final-name") |
| 73 | + [[ "$final_name" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || exit 1 |
| 74 | + echo "jar=target/$final_name.jar" >> "$GITHUB_OUTPUT" |
| 75 | + mvn -B --no-transfer-progress -P'!deploy-live' clean verify -DskipTests=false -Dmaven.test.skip=false |
| 76 | +
|
| 77 | + - name: Stage only the release JAR |
| 78 | + env: |
| 79 | + ARTIFACT_PATH: ${{ steps.maven.outputs.jar }} |
| 80 | + TAG: ${{ github.ref_name }} |
| 81 | + run: | |
| 82 | + python3 .github/scripts/plugin-artifact.py \ |
| 83 | + --jar "$ARTIFACT_PATH" --version "${TAG#v}" \ |
| 84 | + --stage "$RUNNER_TEMP/plugin-release" \ |
| 85 | + --dependencies .build/plugin-dependencies.json |
| 86 | +
|
| 87 | + - uses: actions/upload-artifact@v7 |
| 88 | + with: |
| 89 | + name: plugin-release-${{ github.sha }} |
| 90 | + path: ${{ runner.temp }}/plugin-release/ |
| 91 | + if-no-files-found: error |
| 92 | + retention-days: 30 |
| 93 | + |
| 94 | + publish: |
| 95 | + needs: build |
| 96 | + runs-on: ubuntu-24.04 |
| 97 | + timeout-minutes: 5 |
| 98 | + permissions: |
| 99 | + contents: write |
| 100 | + steps: |
| 101 | + - uses: actions/download-artifact@v8 |
| 102 | + with: |
| 103 | + name: plugin-release-${{ github.sha }} |
| 104 | + path: release |
| 105 | + |
| 106 | + - name: Create draft release |
| 107 | + working-directory: release |
| 108 | + env: |
| 109 | + GH_TOKEN: ${{ github.token }} |
| 110 | + GH_REPO: ${{ github.repository }} |
| 111 | + TAG: ${{ github.ref_name }} |
| 112 | + run: | |
| 113 | + sha256sum --check SHA256SUMS |
| 114 | + flags=() |
| 115 | + if [[ "$TAG" == *-* ]]; then flags+=(--prerelease); fi |
| 116 | + gh api --method POST "repos/$GH_REPO/releases/generate-notes" \ |
| 117 | + -f tag_name="$TAG" --jq .body > "$RUNNER_TEMP/release-changes.md" |
| 118 | + python3 - <<'PY' |
| 119 | + import os, re |
| 120 | + from pathlib import Path |
| 121 | + from urllib.parse import quote |
| 122 | + temp = Path(os.environ['RUNNER_TEMP']) |
| 123 | + changes = (temp / 'release-changes.md').read_text().strip() |
| 124 | + changes = re.sub(r"^## What's Changed\s*", '', changes) |
| 125 | + changes = re.sub(r'^(#{1,5}) ', r'\1# ', changes, flags=re.MULTILINE) |
| 126 | + lines = ['## Changes', '', changes or 'Initial release.', '', '## Downloads', ''] |
| 127 | + assets = sorted([*Path('.').glob('*.jar'), *Path('.').glob('*.tar.gz')]) |
| 128 | + assets += [Path('SHA256SUMS'), Path('build.json')] |
| 129 | + base = f"https://github.com/{os.environ['GH_REPO']}/releases/download/{quote(os.environ['TAG'], safe='')}/" |
| 130 | + for asset in assets: |
| 131 | + if not asset.is_file(): |
| 132 | + raise SystemExit(f'Missing release asset: {asset}') |
| 133 | + description = {'SHA256SUMS': ' — SHA-256 checksums.', 'build.json': ' — Build metadata.'}.get(asset.name, '') |
| 134 | + lines.append(f'- [`{asset.name}`]({base}{quote(asset.name)}){description}') |
| 135 | + (temp / 'release-notes.md').write_text('\n'.join(lines) + '\n') |
| 136 | + PY |
| 137 | + gh release create "$TAG" ./*.jar SHA256SUMS build.json \ |
| 138 | + --verify-tag --draft --title "$TAG" --notes-file "$RUNNER_TEMP/release-notes.md" "${flags[@]}" |
0 commit comments