Skip to content

Commit 5233e11

Browse files
committed
Create a badge from test results
1 parent 3834def commit 5233e11

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.github/workflows/maven.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,59 @@ jobs:
2525

2626
steps:
2727
- uses: actions/checkout@v4
28+
2829
- name: Set up JDK 17
2930
uses: actions/setup-java@v4
3031
with:
3132
java-version: '17'
3233
distribution: 'temurin'
3334
cache: maven
35+
3436
- name: Build with Maven
3537
run: mvn -B package --file pom.xml
38+
3639
- name: Publish Test Results
3740
uses: EnricoMi/publish-unit-test-result-action@v2
41+
id: test-results
3842
if: always()
3943
with:
4044
files: |
4145
target/surefire-reports/*.xml
4246
47+
- name: Set badge color
48+
shell: bash
49+
run: |
50+
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
51+
success)
52+
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
53+
;;
54+
failure)
55+
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
56+
;;
57+
neutral)
58+
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
59+
;;
60+
esac
61+
62+
- name: Create badge
63+
uses: emibcn/badge-action@808173dd03e2f30c980d03ee49e181626088eee8
64+
with:
65+
label: Tests
66+
status: '${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests }} tests, ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.runs }} runs: ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}'
67+
color: ${{ env.BADGE_COLOR }}
68+
path: badge.svg
69+
70+
- name: Upload badge to Gist
71+
# Upload only for master branch
72+
if: >
73+
github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'master' ||
74+
github.event_name != 'workflow_run' && github.ref == 'refs/heads/master'
75+
uses: andymckay/append-gist-action@6e8d64427fe47cbacf4ab6b890411f1d67c07f3e
76+
with:
77+
token: ${{ secrets.GIST_TOKEN }}
78+
gistURL: https://gist.github.com/mperor/8c7b2545d44372da8b8153cae323b205
79+
file: badge.svg
80+
4381
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
4482
#- name: Update dependency graph
4583
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# JAVA Interview Tasks and Questions
22

3+
[![Java CI with Maven](https://github.com/mperor/java-interview-tasks/actions/workflows/maven.yml/badge.svg)](https://github.com/mperor/java-interview-tasks/actions/workflows/maven.yml)
4+
[![Test Results](https://gist.githubusercontent.com/mperor/8c7b2545d44372da8b8153cae323b205/raw/badge.svg)](src/test/java/pl/mperor/interview/tasks)
5+
36
This project contains a collection of tasks sourced from various online platforms under the name *"job interview
47
questions"* or *"coding challenges for Java developers"*.
58
The task descriptions are provided within the [test folder](src/test/java/pl/mperor/interview/tasks) as Javadoc comments

0 commit comments

Comments
 (0)