|
| 1 | +name: Manual Build Release to Maven Central |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + auto-release: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: write |
| 11 | + packages: write |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 # Need full history for git tags |
| 18 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + |
| 20 | + - name: Get latest tag and increment version |
| 21 | + id: version |
| 22 | + run: | |
| 23 | + # Configure git |
| 24 | + git config user.name "github-actions[bot]" |
| 25 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 26 | +
|
| 27 | + # Get the latest tag matching semantic versioning |
| 28 | + LATEST_TAG=$(git tag -l "v[0-9]*.[0-9]*.[0-9]*" --sort=-v:refname | head -n 1) |
| 29 | +
|
| 30 | + if [ -z "$LATEST_TAG" ]; then |
| 31 | + echo "No existing tags found, starting with v0.0.1" |
| 32 | + NEW_VERSION="0.0.1" |
| 33 | + NEW_TAG="v0.0.1" |
| 34 | + else |
| 35 | + echo "Latest tag: $LATEST_TAG" |
| 36 | +
|
| 37 | + # Extract version without 'v' prefix |
| 38 | + VERSION=${LATEST_TAG#v} |
| 39 | +
|
| 40 | + # Split version into major.minor.patch |
| 41 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 42 | +
|
| 43 | + # Strip any pre-release suffix from patch before incrementing (e.g., "0-alpha" -> "0") |
| 44 | + PATCH=${PATCH%%-*} |
| 45 | +
|
| 46 | + # Increment patch version |
| 47 | + PATCH=$((PATCH + 1)) |
| 48 | +
|
| 49 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 50 | + NEW_TAG="v$NEW_VERSION" |
| 51 | + fi |
| 52 | +
|
| 53 | + echo "New version: $NEW_VERSION" |
| 54 | + echo "New tag: $NEW_TAG" |
| 55 | +
|
| 56 | + # Export to GitHub env |
| 57 | + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 58 | + echo "TAG=$NEW_TAG" >> $GITHUB_ENV |
| 59 | +
|
| 60 | + # Create and push the tag |
| 61 | + git tag -a "$NEW_TAG" -m "Auto-release $NEW_VERSION" |
| 62 | + git push origin "$NEW_TAG" |
| 63 | +
|
| 64 | + echo "Created and pushed tag: $NEW_TAG" |
| 65 | +
|
| 66 | + - name: Set up JDK 21 |
| 67 | + uses: actions/setup-java@v4 |
| 68 | + with: |
| 69 | + java-version: '21' |
| 70 | + distribution: 'temurin' |
| 71 | + cache: 'gradle' |
| 72 | + |
| 73 | + - name: Setup Gradle |
| 74 | + uses: gradle/actions/setup-gradle@v3 |
| 75 | + |
| 76 | + - name: Verify version matches tag |
| 77 | + run: | |
| 78 | + GRADLE_VERSION=$(./gradlew properties -q | grep "^version:" | awk '{print $2}') |
| 79 | + echo "Gradle version: $GRADLE_VERSION" |
| 80 | + echo "Expected version: $VERSION" |
| 81 | + if [ "$GRADLE_VERSION" != "$VERSION" ]; then |
| 82 | + echo "ERROR: Gradle version ($GRADLE_VERSION) does not match tag version ($VERSION)" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Build and test |
| 87 | + run: ./gradlew clean build test |
| 88 | + |
| 89 | + - name: Import GPG key |
| 90 | + env: |
| 91 | + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 92 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 93 | + run: | |
| 94 | + echo "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --import |
| 95 | + # Test signing capability |
| 96 | + echo "test" | gpg --clearsign --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" > /dev/null |
| 97 | + echo "GPG key imported and tested successfully" |
| 98 | +
|
| 99 | + - name: Configure GPG for signing |
| 100 | + run: | |
| 101 | + # Configure gpg for non-interactive signing |
| 102 | + echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf |
| 103 | + echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf |
| 104 | + gpg-connect-agent reloadagent /bye |
| 105 | +
|
| 106 | + - name: Publish to Maven Central |
| 107 | + env: |
| 108 | + CENTRAL_PORTAL_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }} |
| 109 | + CENTRAL_PORTAL_PASSWORD: ${{ secrets.CENTRAL_PORTAL_PASSWORD }} |
| 110 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 111 | + GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} |
| 112 | + run: | |
| 113 | + # Export GPG_TTY for passphrase |
| 114 | + export GPG_TTY=$(tty) |
| 115 | +
|
| 116 | + # Create gradle.properties with GPG credentials |
| 117 | + cat > ~/.gradle/gradle.properties << EOF |
| 118 | + signing.gnupg.keyName=$GPG_KEY_ID |
| 119 | + signing.gnupg.passphrase=$GPG_PASSPHRASE |
| 120 | + EOF |
| 121 | +
|
| 122 | + chmod 600 ~/.gradle/gradle.properties |
| 123 | +
|
| 124 | + # Publish to Maven Central via Central Portal |
| 125 | + ./gradlew publishAggregationToCentralPortal \ |
| 126 | + --no-daemon \ |
| 127 | + --stacktrace |
| 128 | +
|
| 129 | + - name: Build distribution archives |
| 130 | + run: | |
| 131 | + ./gradlew :hofmann-rfc:jar :hofmann-rfc:javadocJar :hofmann-rfc:sourcesJar |
| 132 | + ./gradlew :hofmann-server:jar :hofmann-server:javadocJar :hofmann-server:sourcesJar |
| 133 | + ./gradlew :hofmann-client:jar :hofmann-client:javadocJar :hofmann-client:sourcesJar |
| 134 | + ./gradlew :hofmann-dropwizard:jar :hofmann-dropwizard:javadocJar :hofmann-dropwizard:sourcesJar |
| 135 | + ./gradlew :hofmann-springboot:jar :hofmann-springboot:javadocJar :hofmann-springboot:sourcesJar |
| 136 | +
|
| 137 | + - name: Create GitHub Release |
| 138 | + uses: softprops/action-gh-release@v2 |
| 139 | + with: |
| 140 | + tag_name: ${{ env.TAG }} |
| 141 | + name: Release ${{ env.VERSION }} |
| 142 | + body: | |
| 143 | + ## Hofmann Elimination ${{ env.VERSION }} |
| 144 | +
|
| 145 | + **Auto-released** on merge to main. |
| 146 | +
|
| 147 | + ### Maven Central |
| 148 | +
|
| 149 | + Sample dependency for Maven: |
| 150 | +
|
| 151 | + ```xml |
| 152 | + <dependency> |
| 153 | + <groupId>com.codeheadsystems</groupId> |
| 154 | + <artifactId>hofmann-rfc</artifactId> |
| 155 | + <version>${{ env.VERSION }}</version> |
| 156 | + </dependency> |
| 157 | + ``` |
| 158 | +
|
| 159 | + ```gradle |
| 160 | + implementation("com.codeheadsystems:hofmann-rfc:${{ env.VERSION }}") |
| 161 | + ``` |
| 162 | +
|
| 163 | + ### Modules Published |
| 164 | + - `com.codeheadsystems:hofmann-rfc:${{ env.VERSION }}` |
| 165 | + - `com.codeheadsystems:hofmann-server:${{ env.VERSION }}` |
| 166 | + - `com.codeheadsystems:hofmann-client:${{ env.VERSION }}` |
| 167 | + - `com.codeheadsystems:hofmann-dropwizard:${{ env.VERSION }}` |
| 168 | + - `com.codeheadsystems:hofmann-springboot:${{ env.VERSION }}` |
| 169 | +
|
| 170 | + ### What's Changed |
| 171 | + See commits since last release for details. |
| 172 | +
|
| 173 | + **Note:** Artifacts may take up to 2 hours to appear in Maven Central after release. |
| 174 | + files: | |
| 175 | + hofmann-rfc/build/libs/*.jar |
| 176 | + hofmann-server/build/libs/*.jar |
| 177 | + hofmann-client/build/libs/*.jar |
| 178 | + hofmann-dropwizard/build/libs/*.jar |
| 179 | + hofmann-springboot/build/libs/*.jar |
| 180 | + draft: false |
| 181 | + prerelease: false |
| 182 | + generate_release_notes: true |
| 183 | + env: |
| 184 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 185 | + |
| 186 | + - name: Notify on failure |
| 187 | + if: failure() |
| 188 | + run: | |
| 189 | + echo "::error::Auto-release failed! Check logs for details." |
0 commit comments