Skip to content

Tests for PR 145

Tests for PR 145 #24

Workflow file for this run

name: Test PRs
run-name: Tests for PR ${{ github.event.pull_request.number }}
on:
pull_request:
types:
- synchronize
- opened
- ready_for_review
- reopened
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
tests-to-run: ${{ steps.test.outputs.tests-to-run }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'microsoft'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
# Runs the collect-tests shell script and sets the output variable
- name: Determine tests to run
id: test
run: |
#!/bin/bash
./.github/scripts/collect-tests.sh
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'microsoft'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
- name: Build
run: ./gradlew --info -s -x assemble
test:
name: Test
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
test: ${{ fromJSON(needs.setup.outputs.tests-to-run) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'microsoft'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
- name: Test
run: ./gradlew --info -s ${{ matrix.test }}
# Always upload test results
- name: Merge Test Reports
if: success() || failure()
run: npx junit-report-merger junit.xml "**/TEST-*.xml"
- name: Format test run name as artifact name
id: format-artifact-name
# Use the GITHUB_OUTPUT mechanic to set the output variable
run: |
# We have two cases here, one with a gradle task path, there we replace the : with a - and strip the leading -
# The other case is complexer, again we replace the : with a - and strip the leading - but now we also remove the ' --tests ' part
# Remove the '"' from the string and replace the '.' with a '-'
NAME=$(echo "${{ matrix.test }}" | sed 's/:/-/g' | sed 's/^-//' | sed 's/ --tests /-/g' | sed 's/"//g' | sed 's/\./-/g')
# Check if the GITHUB_OUTPUT is set
if [ -z "$GITHUB_OUTPUT" ]; then
# We do not have github output, then use the set output command
echo "::set-output name=artifact-name::$NAME"
exit 0
fi
echo "artifact-name=$NAME" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
if-no-files-found: ignore
name: test-results-${{ steps.format-artifact-name.outputs.artifact-name }}
path: junit.xml
retention-days: 1
process-test-data:
runs-on: ubuntu-latest
needs: test
if: success() || failure()
steps:
- uses: actions/checkout@v3
- name: Download reports' artifacts
uses: actions/download-artifact@v4
with:
pattern: test-results-**
path: downloaded_artifacts
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/*.xml'
- name: Merge Test Reports
if: success() || failure()
run: npx junit-report-merger junit.xml "**/*.xml"
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results
path: junit.xml