Skip to content

Fix GitHub release creation token parameter #5

Fix GitHub release creation token parameter

Fix GitHub release creation token parameter #5

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*' # Triggers on tags like v2.24, v2.25, etc.
- '[0-9]+.[0-9]+*' # Also supports tags like 2.24, 2.25, etc.
jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
permissions:
contents: write # Required to create releases and push tags
id-token: write # Required for OIDC if using
pull-requests: read # May be needed for some operations
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for changelog extraction
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper # Use wrapper version
- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}-
${{ runner.os }}-gradle-
- name: Extract version from tag
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
# Tag format: v2.24 -> 2.24
VERSION=${GITHUB_REF#refs/tags/v}
else
# Tag format: 2.24 -> 2.24
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Update version in gradle.properties
run: |
sed -i "s/^version = .*/version = ${{ steps.version.outputs.version }}/" gradle.properties
cat gradle.properties
- name: Extract changelog for version
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Extracting changelog for version: $VERSION"
# Extract changelog section for this version using awk
# Pattern: from "## VERSION" to next "## " or end of file
CHANGELOG=$(awk -v version="$VERSION" '
BEGIN { found=0; in_section=0 }
/^## / {
if (in_section) exit # Stop at next version section
if ($0 ~ "^## " version "$" || $0 ~ "^## " version " ") {
found=1
in_section=1
next
}
}
in_section { print }
' CHANGELOG.md)
# If empty, try without the "## " prefix
if [ -z "$CHANGELOG" ]; then
CHANGELOG=$(awk -v version="$VERSION" '
BEGIN { found=0; in_section=0 }
/^## / {
if (in_section) exit
if ($0 ~ "^## " version "$" || $0 ~ "^## " version " ") {
found=1
in_section=1
next
}
}
in_section { print }
' CHANGELOG.md)
fi
# If still empty, use a default message
if [ -z "$CHANGELOG" ]; then
CHANGELOG="See CHANGELOG.md for details."
fi
# Escape for GitHub output (multiline)
{
echo "changelog<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> $GITHUB_OUTPUT
echo "Changelog extracted (first 200 chars):"
echo "$CHANGELOG" | head -c 200
echo ""
- name: Build plugin
run: gradle clean build -x test --no-daemon
- name: Validate plugin
run: gradle validatePlugins --no-daemon
- name: Publish to Maven Central (Sonatype)
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
gradle publishToSonatype closeStagingRepositories --no-daemon \
-Psigning.key="$SIGNING_KEY" \
-Psigning.password="$SIGNING_PASSWORD"
- name: Publish to Gradle Plugin Portal
env:
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
gradle publishPlugins --no-daemon \
-Psigning.key="$SIGNING_KEY" \
-Psigning.password="$SIGNING_PASSWORD"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: Release ${{ steps.version.outputs.version }}
body: |
## Version ${{ steps.version.outputs.version }}
${{ steps.changelog.outputs.changelog }}
---
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.before }}...${{ github.ref }}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}