Skip to content

Commit 19fcaa9

Browse files
authored
Add github Action to trigger unit test
- Trigger unit test when code push to `main` branch - Trigger unit test when PR created
1 parent d624cf1 commit 19fcaa9

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/github-actions.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Unit Tests
2+
3+
# Trigger the workflow on pull request creation, pull request update, or push to main branch.
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
# Checkout the repository
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
21+
# Set up JDK 11 for Kotlin/Java projects (you can adjust the version if necessary)
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@v3
24+
with:
25+
distribution: 'temurin'
26+
java-version: '17'
27+
28+
# Cache Gradle dependencies (Optional, but improves build speed)
29+
- name: Cache Gradle packages
30+
uses: actions/cache@v3
31+
with:
32+
path: ~/.gradle/caches
33+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
34+
restore-keys: |
35+
${{ runner.os }}-gradle-
36+
37+
# Run unit tests
38+
- name: Run Unit Tests
39+
run: ./gradlew test
40+
41+
# Archive test results for inspection (optional step to store test reports)
42+
- name: Archive test results
43+
if: always()
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: test-results
47+
path: build/test-results/test/
48+
49+
# Publish test results to the pull request (Optional)
50+
- name: Publish Test Results
51+
if: always()
52+
uses: mikepenz/action-junit-report@v3
53+
with:
54+
report_paths: '**/build/test-results/test/TEST-*.xml'
55+
check_name: 'Unit Test Results'
56+
fail_on_failure: true

0 commit comments

Comments
 (0)