Run publish job on push, not merge (#51) #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 8 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '8' | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v2 | |
- name: Set release version | |
run: | | |
# Remove -SNAPSHOT from version | |
sed -i 's/\(version "[0-9.]*\)-SNAPSHOT"/\1"/' build.gradle | |
- name: Publish package | |
env: | |
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | |
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | |
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} | |
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | |
SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | |
run: | | |
./gradlew build uploadArchives | |
- name: Bump version | |
id: bump_version | |
run: | | |
# Get current version without SNAPSHOT | |
CURRENT_VERSION=$(grep "version" build.gradle | sed 's/version "\(.*\)"/\1/') | |
# Split into parts | |
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" | |
# Increment patch version | |
NEXT_PATCH=$((VERSION_PARTS[2] + 1)) | |
# Create new version | |
NEXT_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$NEXT_PATCH-SNAPSHOT" | |
# Update build.gradle | |
sed -i "s/version \".*\"/version \"$NEXT_VERSION\"/" build.gradle | |
# Make the new version available to other steps | |
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
- name: Commit version bump | |
env: | |
NEXT_VERSION: ${{ steps.bump_version.outputs.next_version }} | |
BRANCH_NAME: github_actions | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add --all | |
git commit -m "Prepare version $NEXT_VERSION for development [skip ci]" | |
git pull --rebase origin $BRANCH_NAME | |
git push origin HEAD:$BRANCH_NAME |