Skip to content

Commit

Permalink
Add build-and-test action (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jskov authored Jan 17, 2024
1 parent 7f980c4 commit 02df451
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build and Test
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Define BUILD_LABEL
env:
INPUT: ${{ github.head_ref || github.ref_name }}
run: |
echo "BUILD_LABEL=${INPUT//\//_}" >> $GITHUB_ENV
# - name: Echo env
# run: env | sort

- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4
# 1.1.0

# From https://docs.sonarqube.org/latest/analysis/github-integration/
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Set build version
# Cannot use ${BUILD_LABEL} with gradle-build-action, so stuff version
# into gradle.properties
run: sed -i 's/^version.*/version = '${BUILD_LABEL}'/;' ./gradle.properties

- name: Run tests
uses: gradle/gradle-build-action@982da8e78c05368c70dac0351bb82647a9e9a5d2
# 2.11.1
with:
# Only write to the cache for builds on the 'main' branch (default - but here for documentation)
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
arguments: check javadoc publish -s
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 comments on commit 02df451

Please sign in to comment.