|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Triggers on tags like v2.18.0, v2.19.0, etc. |
| 7 | + - '[0-9]+.[0-9]+*' # Also supports tags like 2.18.0, 2.19.0, etc. |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + name: Build and Release |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + permissions: |
| 15 | + contents: write # Required to create releases and push tags |
| 16 | + id-token: write # Required for OIDC if using |
| 17 | + pull-requests: read # May be needed for some operations |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 # Need full history for changelog extraction |
| 24 | + |
| 25 | + - name: Set up JDK |
| 26 | + uses: actions/setup-java@v4 |
| 27 | + with: |
| 28 | + java-version: '17' |
| 29 | + distribution: 'temurin' |
| 30 | + |
| 31 | + - name: Setup Gradle |
| 32 | + uses: gradle/gradle-build-action@v2 |
| 33 | + with: |
| 34 | + gradle-version: wrapper # Use wrapper version |
| 35 | + |
| 36 | + - name: Cache Gradle dependencies |
| 37 | + uses: actions/cache@v3 |
| 38 | + with: |
| 39 | + path: | |
| 40 | + ~/.gradle/caches |
| 41 | + ~/.gradle/wrapper |
| 42 | + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}- |
| 45 | + ${{ runner.os }}-gradle- |
| 46 | + |
| 47 | + - name: Extract version from tag |
| 48 | + id: version |
| 49 | + run: | |
| 50 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 51 | + # Tag format: v2.18.0 -> 2.18.0 |
| 52 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 53 | + else |
| 54 | + # Tag format: 2.18.0 -> 2.18.0 |
| 55 | + VERSION=${GITHUB_REF#refs/tags/} |
| 56 | + fi |
| 57 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 58 | + echo "Extracted version: $VERSION" |
| 59 | + |
| 60 | + - name: Update version in gradle.properties |
| 61 | + run: | |
| 62 | + sed -i "s/^version = .*/version = ${{ steps.version.outputs.version }}/" gradle.properties |
| 63 | + cat gradle.properties |
| 64 | + |
| 65 | + - name: Extract changelog for version |
| 66 | + id: changelog |
| 67 | + run: | |
| 68 | + VERSION="${{ steps.version.outputs.version }}" |
| 69 | + echo "Extracting changelog for version: $VERSION" |
| 70 | + |
| 71 | + # Extract changelog section for this version using awk |
| 72 | + # Pattern: from "## VERSION" to next "## " or end of file |
| 73 | + if [ -f CHANGELOG.md ]; then |
| 74 | + CHANGELOG=$(awk -v version="$VERSION" ' |
| 75 | + BEGIN { found=0; in_section=0 } |
| 76 | + /^## / { |
| 77 | + if (in_section) exit # Stop at next version section |
| 78 | + if ($0 ~ "^## " version "$" || $0 ~ "^## " version " ") { |
| 79 | + found=1 |
| 80 | + in_section=1 |
| 81 | + next |
| 82 | + } |
| 83 | + } |
| 84 | + in_section { print } |
| 85 | + ' CHANGELOG.md) |
| 86 | + fi |
| 87 | + |
| 88 | + # If empty, try without the "## " prefix |
| 89 | + if [ -z "$CHANGELOG" ] && [ -f CHANGELOG.md ]; then |
| 90 | + CHANGELOG=$(awk -v version="$VERSION" ' |
| 91 | + BEGIN { found=0; in_section=0 } |
| 92 | + /^## / { |
| 93 | + if (in_section) exit |
| 94 | + if ($0 ~ "^## " version "$" || $0 ~ "^## " version " ") { |
| 95 | + found=1 |
| 96 | + in_section=1 |
| 97 | + next |
| 98 | + } |
| 99 | + } |
| 100 | + in_section { print } |
| 101 | + ' CHANGELOG.md) |
| 102 | + fi |
| 103 | + |
| 104 | + # If still empty, use a default message |
| 105 | + if [ -z "$CHANGELOG" ]; then |
| 106 | + CHANGELOG="See CHANGELOG.md for details." |
| 107 | + fi |
| 108 | + |
| 109 | + # Escape for GitHub output (multiline) |
| 110 | + { |
| 111 | + echo "changelog<<EOF" |
| 112 | + echo "$CHANGELOG" |
| 113 | + echo "EOF" |
| 114 | + } >> $GITHUB_OUTPUT |
| 115 | + |
| 116 | + echo "Changelog extracted (first 200 chars):" |
| 117 | + echo "$CHANGELOG" | head -c 200 |
| 118 | + echo "" |
| 119 | + |
| 120 | + - name: Build plugin |
| 121 | + run: gradle clean build -x test --no-daemon |
| 122 | + |
| 123 | + - name: Validate plugin |
| 124 | + run: gradle validatePlugins --no-daemon |
| 125 | + |
| 126 | + - name: Publish to Maven Central (Sonatype) |
| 127 | + continue-on-error: true |
| 128 | + env: |
| 129 | + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} |
| 130 | + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} |
| 131 | + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} |
| 132 | + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} |
| 133 | + run: | |
| 134 | + gradle publishToSonatype closeStagingRepositories --no-daemon \ |
| 135 | + -Psigning.key="$SIGNING_KEY" \ |
| 136 | + -Psigning.password="$SIGNING_PASSWORD" |
| 137 | + |
| 138 | + - name: Publish to Gradle Plugin Portal |
| 139 | + continue-on-error: true |
| 140 | + env: |
| 141 | + GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} |
| 142 | + GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} |
| 143 | + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} |
| 144 | + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} |
| 145 | + run: | |
| 146 | + gradle publishPlugins --no-daemon \ |
| 147 | + -Psigning.key="$SIGNING_KEY" \ |
| 148 | + -Psigning.password="$SIGNING_PASSWORD" |
| 149 | + |
| 150 | + - name: Create GitHub Release |
| 151 | + uses: softprops/action-gh-release@v1 |
| 152 | + with: |
| 153 | + tag_name: ${{ github.ref }} |
| 154 | + name: Release ${{ steps.version.outputs.version }} |
| 155 | + body: | |
| 156 | + ## Version ${{ steps.version.outputs.version }} |
| 157 | + |
| 158 | + ${{ steps.changelog.outputs.changelog }} |
| 159 | + |
| 160 | + --- |
| 161 | + |
| 162 | + **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.before }}...${{ github.ref }} |
| 163 | + draft: false |
| 164 | + prerelease: false |
| 165 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 166 | + |
0 commit comments