Initial commit for Github actions #6
Workflow file for this run
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: Build & Test | |
on: | |
push: | |
branches: [ main, master ] | |
pull_request: | |
branches: [ main, master ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: snapshot | |
steps: | |
- uses: actions/checkout@v3 | |
- 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 | |
with: | |
cache-read-only: false | |
gradle-home-cache-cleanup: true | |
- name: Build | |
run: ./gradlew build | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: build/ | |
publish: | |
needs: build | |
# if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- uses: actions/checkout@v3 | |
- 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: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
path: build/ | |
# - 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: | | |
echo "${{ secrets.SIGNING_KEY }}" | base64 -d > signing.gpg | |
./gradlew uploadArchives -Psigning.secretKeyRingFile=$(pwd)/signing.gpg -Psigning.keyId=$SIGNING_KEY_ID -Psigning.password=$SIGNING_PASSWORD | |
- 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 }} | |
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 push |