|
| 1 | +# This workflow automates the release process when a draft release is created |
| 2 | +# on GitHub. It uses Maven release plugin to manage versions and deploys to |
| 3 | +# Maven Central |
| 4 | +# |
| 5 | +# Usage: |
| 6 | +# 1. Create a new draft release in GitHub UI with tag format: vX.Y.Z |
| 7 | +# (e.g., v1.2.0) |
| 8 | +# - Select the target branch (typically main) |
| 9 | +# 2. This workflow will automatically: |
| 10 | +# - Use Maven release:prepare to update versions and create release commit |
| 11 | +# - Use Maven release:perform to build and deploy artifacts to Maven Central |
| 12 | +# - Create the tag to point to release commit |
| 13 | +# - Push commits back to the originating branch |
| 14 | +# - Publish the GitHub release (mark draft as non-draft) |
| 15 | +name: Automated Release Debug |
| 16 | + |
| 17 | +on: |
| 18 | + release: |
| 19 | + types: [created] # Only fire when a release is created |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write # Required to push commits, update tags and edit releases |
| 23 | + |
| 24 | +jobs: |
| 25 | + release: |
| 26 | + # Only run for draft releases; ignore non-draft created events |
| 27 | + if: github.event.release.draft |
| 28 | + |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Validate release tag format |
| 33 | + id: validate_tag |
| 34 | + run: | |
| 35 | + TAG_NAME="${{ github.event.release.tag_name }}" |
| 36 | + echo "Release tag: $TAG_NAME" |
| 37 | +
|
| 38 | + # Validate tag format (should be vX.Y.Z) |
| 39 | + if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 40 | + echo "::error::Invalid tag format. Expected format: vX.Y.Z (e.g., v1.2.0)" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
| 44 | + # Remove 'v' prefix to get the version number |
| 45 | + VERSION="${TAG_NAME#v}" |
| 46 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 47 | + echo "Extracted version: $VERSION" |
| 48 | +
|
| 49 | + - name: Determine target branch |
| 50 | + id: target_branch |
| 51 | + run: | |
| 52 | + # Use target_commitish to determine the originating branch |
| 53 | + TARGET="${{ github.event.release.target_commitish }}" |
| 54 | +
|
| 55 | + # If target_commitish is empty or a SHA, default to main |
| 56 | + if [[ -z "$TARGET" ]] || [[ "$TARGET" =~ ^[0-9a-f]{40}$ ]]; then |
| 57 | + TARGET="main" |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "target_branch=${TARGET}" >> "$GITHUB_OUTPUT" |
| 61 | + echo "Target branch: $TARGET" |
| 62 | +
|
| 63 | + - name: Generate GitHub App Token |
| 64 | + id: generate_token |
| 65 | + uses: actions/create-github-app-token@v2 |
| 66 | + with: |
| 67 | + app-id: ${{ secrets.APP_ID }} |
| 68 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 69 | + |
| 70 | + - name: Checkout repository |
| 71 | + uses: actions/checkout@v6 |
| 72 | + with: |
| 73 | + ref: ${{ steps.target_branch.outputs.target_branch }} |
| 74 | + fetch-depth: 0 |
| 75 | + token: ${{ steps.generate_token.outputs.token }} |
| 76 | + |
| 77 | + - name: Pre-build condition checks |
| 78 | + run: | |
| 79 | + TAG_NAME="${{ github.event.release.tag_name }}" |
| 80 | +
|
| 81 | + echo "Performing pre-build condition checks..." |
| 82 | +
|
| 83 | + # Fetch latest state from remote |
| 84 | + git fetch origin --tags |
| 85 | +
|
| 86 | + # Check if a tag exists |
| 87 | + if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME$"; then |
| 88 | + echo "::error::Tag $TAG_NAME already exists on remote." |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | +
|
| 92 | + echo "Pre-build checks passed. No issues detected." |
| 93 | + |
| 94 | + - name: Set up JDK 25 |
| 95 | + uses: actions/setup-java@v5 |
| 96 | + with: |
| 97 | + java-version: "25" |
| 98 | + distribution: "temurin" |
| 99 | + cache: maven |
| 100 | + cache-dependency-path: | |
| 101 | + pom.xml |
| 102 | + xapi-model/pom.xml |
| 103 | + xapi-client/pom.xml |
| 104 | + xapi-model-spring-boot-starter/pom.xml |
| 105 | + server-id: central |
| 106 | + server-username: MAVEN_USERNAME |
| 107 | + server-password: MAVEN_PASSWORD |
| 108 | + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 109 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 110 | + |
| 111 | + - name: Configure Git |
| 112 | + run: | |
| 113 | + git config user.name "github-actions[bot]" |
| 114 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 115 | +
|
0 commit comments