Skip to content

Java release with Gradle #42

Java release with Gradle

Java release with Gradle #42

Workflow file for this run

name: Java release with Gradle
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Decode GPG key
run: echo "${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}" | base64 --decode > ./secring.gpg
- name: Create gradle.properties
run: |
echo "signing.keyId=${{ secrets.SIGNING_KEY_ID }}" >> gradle.properties
echo "signing.password=${{ secrets.SIGNING_PASSWORD }}" >> gradle.properties
echo "signing.secretKeyRingFile=./secring.gpg" >> gradle.properties
echo "ossrhUsername=${{ secrets.OSSRH_USERNAME }}" >> gradle.properties
echo "ossrhPassword=${{ secrets.OSSRH_PASSWORD }}" >> gradle.properties
- name: Publish package
run: ./gradlew publishMavenJavaPublicationToSonaTypeRepository
- name: Tag and update version
run: |
# Extract current version from build.gradle
VERSION=$(grep "version = " build.gradle | awk -F\' '{print $2}')
echo "Current version: $VERSION"
# Create and push the tag for the current version
git tag "v$VERSION"
git push origin "v$VERSION"
# Increment version for the next cycle
NEW_VERSION=$(echo $VERSION | awk -F. '{$NF = $NF + 1;} 1' OFS=.)
echo "New version: $NEW_VERSION"
# Update build.gradle with the new version
sed -i "s/version = '$VERSION'/version = '$NEW_VERSION'/" build.gradle
# Commit the change
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add build.gradle
git commit -m "Increment version to $NEW_VERSION [skip ci]"
# Push the commit
git push origin HEAD:${{ github.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}