143 lines
4.2 KiB
YAML
143 lines
4.2 KiB
YAML
name: Tests
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
pull_request:
|
|
branches: [master]
|
|
|
|
permissions:
|
|
contents: read
|
|
checks: write
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
cache-key: ${{ steps.cache-key-generator.outputs.key }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up JDK 21
|
|
uses: actions/setup-java@v5
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '21'
|
|
|
|
- name: Generate cache key
|
|
id: cache-key-generator
|
|
run: echo "key=gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cache Gradle dependencies
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: ${{ steps.cache-key-generator.outputs.key }}
|
|
restore-keys: |
|
|
gradle-${{ runner.os }}-
|
|
|
|
- name: Grant execute permission to Gradle wrapper
|
|
run: chmod +x gradlew
|
|
|
|
lint:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up JDK 21
|
|
uses: actions/setup-java@v5
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '21'
|
|
|
|
- name: Restore Gradle cache
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: ${{ needs.build.outputs.cache-key }}
|
|
restore-keys: |
|
|
gradle-${{ runner.os }}-
|
|
|
|
- name: Grant execute permission to Gradle wrapper
|
|
run: chmod +x gradlew
|
|
|
|
- name: Run lint
|
|
# Path scoped to :backend on purpose: :composeApp applies the Android Gradle plugin,
|
|
# which needs an Android SDK to even configure. Keeping every gradlew invocation on a
|
|
# fully-qualified project path (with org.gradle.configureondemand=true) lets CI skip
|
|
# configuring :composeApp entirely, so no Android SDK setup is needed on this runner.
|
|
run: ./gradlew :backend:ktlintCheck
|
|
|
|
- name: Publish ktlint report
|
|
uses: yutailang0119/action-ktlint@v5
|
|
if: always()
|
|
with:
|
|
report-path: backend/build/reports/ktlint/**/*.xml
|
|
continue-on-error: false
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
GRADLE_CACHE_DIR: ${{ github.workspace }}/.gradle-docker-cache
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Install a pinned Docker Compose version
|
|
run: |
|
|
mkdir -p ~/.docker/cli-plugins
|
|
curl -fSL https://github.com/docker/compose/releases/download/v5.1.4/docker-compose-linux-x86_64 \
|
|
-o ~/.docker/cli-plugins/docker-compose
|
|
chmod +x ~/.docker/cli-plugins/docker-compose
|
|
docker compose version
|
|
|
|
- name: Prepare docker secrets
|
|
run: |
|
|
[ -f docker/postgresql.secret ] || echo -n "changeit" > docker/postgresql.secret
|
|
|
|
- name: Generate cache key
|
|
id: cache-key-generator
|
|
run: echo "key=gradle-docker-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Restore Gradle cache (Docker)
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: ${{ env.GRADLE_CACHE_DIR }}
|
|
key: ${{ steps.cache-key-generator.outputs.key }}
|
|
restore-keys: |
|
|
gradle-docker-${{ runner.os }}-
|
|
|
|
- name: Prepare cache directory permissions
|
|
run: |
|
|
mkdir -p "$GRADLE_CACHE_DIR"
|
|
chmod -R 777 "$GRADLE_CACHE_DIR"
|
|
|
|
- name: Run tests in Docker
|
|
run: docker compose -f docker/docker-compose-test.yaml run tests
|
|
|
|
- name: Shut down Docker services
|
|
if: always()
|
|
run: docker compose -f docker/docker-compose-test.yaml down -v
|
|
|
|
- name: Upload test reports
|
|
if: always()
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: test-results
|
|
path: backend/build/reports/tests/test
|
|
|
|
- name: Publish Test Report
|
|
uses: dorny/test-reporter@v3
|
|
if: always()
|
|
with:
|
|
name: JUnit Tests
|
|
path: backend/build/test-results/test/TEST-*.xml
|
|
reporter: java-junit |