Skip to content

[setup] Workflow Setup for Unit Testing #5

[setup] Workflow Setup for Unit Testing

[setup] Workflow Setup for Unit Testing #5

Workflow file for this run

name: Spring Boot Unit Tests
on:
pull_request:
branch_protection_rule:
types: [created, deleted]
check_run:
types:
- created
- rerequested
jobs:
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
max_retries: [1, 2, 3] # Set the maximum number of retries
outputs:
job-status: ${{ steps.run-tests.outputs.job-status }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 20.0.1
uses: actions/setup-java@v1
with:
java-version: 20.0.1
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Restore Gradle build caches
id: gradle-cache-restore
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Run Tests
id: run-tests
run: ./gradlew test --stacktrace
- name: Check if build caches need to be restored again
if: steps.gradle-cache-restore.outputs.cache-hit != 'true' && matrix.max_retries > 0
run: echo "::set-output name=retry::true"
- name: Rerun build job if needed
if: steps.gradle-cache-restore.outputs.cache-hit != 'true' && matrix.max_retries > 0
uses: ./github/workflows/build.yml
- name: Set job status based on the result
if: steps.gradle-cache-restore.outputs.cache-hit != 'true'
run: echo "::set-output name=job-status::failed"
- name: Set job status based on the result
if: steps.gradle-cache-restore.outputs.cache-hit == 'true'
run: echo "::set-output name=job-status::succeeded"