|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + force-major: |
| 7 | + description: 'Force major version bump' |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: false |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up JDK 21 |
| 24 | + uses: actions/setup-java@v4 |
| 25 | + with: |
| 26 | + java-version: '21' |
| 27 | + distribution: 'temurin' |
| 28 | + |
| 29 | + - name: Setup Gradle |
| 30 | + uses: gradle/actions/setup-gradle@v4 |
| 31 | + |
| 32 | + - name: Calculate next version |
| 33 | + id: version |
| 34 | + run: | |
| 35 | + # Get latest tag |
| 36 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") |
| 37 | + echo "Latest tag: $LATEST_TAG" |
| 38 | +
|
| 39 | + # Parse version |
| 40 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG" |
| 41 | +
|
| 42 | + # Analyze commits since last tag |
| 43 | + COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s" 2>/dev/null || git log --pretty=format:"%s") |
| 44 | + echo "Commits since $LATEST_TAG:" |
| 45 | + echo "$COMMITS" |
| 46 | +
|
| 47 | + # Determine bump type from conventional commits |
| 48 | + BUMP="patch" |
| 49 | + if echo "$COMMITS" | grep -qiE "^feat(\(.+\))?!:|BREAKING CHANGE:"; then |
| 50 | + BUMP="major" |
| 51 | + elif echo "$COMMITS" | grep -qiE "^feat(\(.+\))?:"; then |
| 52 | + BUMP="minor" |
| 53 | + fi |
| 54 | +
|
| 55 | + # Force major if requested |
| 56 | + if [ "${{ inputs.force-major }}" == "true" ]; then |
| 57 | + BUMP="major" |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "Bump type: $BUMP" |
| 61 | +
|
| 62 | + # Apply bump |
| 63 | + case "$BUMP" in |
| 64 | + major) |
| 65 | + MAJOR=$((MAJOR + 1)) |
| 66 | + MINOR=0 |
| 67 | + PATCH=0 |
| 68 | + ;; |
| 69 | + minor) |
| 70 | + MINOR=$((MINOR + 1)) |
| 71 | + PATCH=0 |
| 72 | + ;; |
| 73 | + patch) |
| 74 | + PATCH=$((PATCH + 1)) |
| 75 | + ;; |
| 76 | + esac |
| 77 | +
|
| 78 | + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 79 | + echo "New version: $NEW_VERSION" |
| 80 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 81 | +
|
| 82 | + - name: Create and push tag |
| 83 | + run: | |
| 84 | + git config user.name "github-actions[bot]" |
| 85 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 86 | + git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}" |
| 87 | + git push origin "${{ steps.version.outputs.version }}" |
| 88 | +
|
| 89 | + - name: Build with Gradle |
| 90 | + run: ./gradlew build |
| 91 | + |
| 92 | + - name: Publish to staging |
| 93 | + run: ./gradlew publishAllPublicationsToStagingRepository |
| 94 | + |
| 95 | + - name: Deploy with JReleaser |
| 96 | + uses: jreleaser/release-action@v2 |
| 97 | + with: |
| 98 | + arguments: deploy |
| 99 | + env: |
| 100 | + JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} |
| 101 | + JRELEASER_MAVENCENTRAL_SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} |
| 102 | + JRELEASER_GPG_PASSPHRASE: ${{ secrets.SIGNING_PASSWORD }} |
| 103 | + JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 104 | + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + |
| 106 | + - name: Create GitHub Release |
| 107 | + env: |
| 108 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + run: | |
| 110 | + gh release create "${{ steps.version.outputs.version }}" \ |
| 111 | + --title "v${{ steps.version.outputs.version }}" \ |
| 112 | + --generate-notes |
| 113 | +
|
| 114 | + - name: Upload JReleaser logs |
| 115 | + if: always() |
| 116 | + uses: actions/upload-artifact@v4 |
| 117 | + with: |
| 118 | + name: jreleaser-logs |
| 119 | + path: | |
| 120 | + out/jreleaser/trace.log |
| 121 | + out/jreleaser/output.properties |
0 commit comments