Skip to content

Update

Update #77

Workflow file for this run

name: build
on:
push:
branches:
- '**'
paths-ignore:
- '**.md'
pull_request:
branches:
- '**'
paths-ignore:
- '**.md'
jobs:
prep:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.init.outputs.version }}
release: ${{ steps.init.outputs.release }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Init
id: init
run: |
VERSION=$(grep "version" gradle.properties | cut -d'=' -f2)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "release=true" >> $GITHUB_OUTPUT
else
echo "release=false" >> $GITHUB_OUTPUT
fi
snapshot:
needs: prep
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java:
- 17
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Java ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
java-package: jdk
distribution: 'zulu'
-
name: Cache deps
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
-
name: Build
run: |
./gradlew clean build
-
name: Archive artifact
if: success() && matrix.java == '17'
uses: actions/upload-artifact@v4
with:
name: snapshot
path: build/libs/*.jar
release:
needs: prep
if: github.event_name != 'pull_request' && needs.prep.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Java
uses: actions/setup-java@v4
with:
java-version: 17
java-package: jdk
distribution: 'zulu'
-
name: Cache deps
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
-
name: Set up Git
run: |
git config user.name GitHub
git config user.email [email protected]
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Release
if: success()
run: |
./gradlew clean release \
-Prelease.useAutomaticVersion=true \
-Prelease.releaseVersion=${{ needs.prep.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Archive artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: release
path: build/libs/*.jar
-
name: GitHub Release
uses: softprops/action-gh-release@v1
if: success()
with:
name: ${{ needs.prep.outputs.version }}
tag_name: ${{ needs.prep.outputs.version }}
draft: true
files: |
build/libs/*.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
sonar:
needs: prep
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Java
uses: actions/setup-java@v4
with:
java-version: 17
java-package: jdk
distribution: 'zulu'
-
name: Cache deps
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
-
name: Test and Sonar
if: ${{ env.SONAR_TOKEN != null }}
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
./gradlew test sonar \
-Dsonar.gradle.skipCompile=true \
-Dsonar.pullrequest.provider=github \
-Dsonar.pullrequest.github.repository=${{ github.repository }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=${SONAR_ORG_KEY} \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.pullrequest.key=${{ github.event.number }} \
-Dsonar.pullrequest.base=${{ github.base_ref }}
elif [ "${{ needs.prep.outputs.release }}" = 'true' ]; then
./gradlew test sonar \
-Dsonar.gradle.skipCompile=true \
-Dsonar.pullrequest.provider=github \
-Dsonar.pullrequest.github.repository=${{ github.repository }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=${SONAR_ORG_KEY} \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.projectVersion=${{ needs.prep.outputs.version }}
else
./gradlew test sonar \
-Dsonar.gradle.skipCompile=true \
-Dsonar.pullrequest.provider=github \
-Dsonar.pullrequest.github.repository=${{ github.repository }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=${SONAR_ORG_KEY} \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.branch.name=${GITHUB_REF##*/}
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_ORG_KEY: ${{ secrets.SONAR_ORG_KEY }}
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}