Skip to content

Commit

Permalink
ci(.github/workflows/,docs/): test workflow upload artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
violetbrina committed Dec 19, 2024
1 parent ea440eb commit 390d162
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,26 @@ jobs:
name: execution-report
path: ./test-execution.xml

- name: Save badge env variables
- name: Save badge data as artifact
id: save_badge_env
if: always()
run: |
TEST_COUNT=$(grep -o '<testcase ' test-execution.xml | wc -l)
TEST_PASSED=$((TEST_COUNT - $(grep -o '<failure ' test-execution.xml | wc -l)))
TEST_COLOR=$(if [ "$TEST_PASSED" -eq "$TEST_COUNT" ]; then echo "green"; else echo "red"; fi)
COVERAGE=$(grep -o 'line-rate="[^"]*"' coverage.xml | head -1 | cut -d'"' -f2 | awk '{printf "%.2f", $1 * 100}')
COVERAGE_COLOR=$(if [ "$(echo "$COVERAGE" | cut -d'.' -f1)" -ge 80 ]; then echo "green"; elif [ "$(echo "$COVERAGE" | cut -d'.' -f1)" -ge 50 ]; then echo "orange"; else echo "red"; fi)
echo "TEST_COUNT=$TEST_COUNT" >> $GITHUB_OUTPUT
echo "TEST_PASSED=$TEST_PASSED" >> $GITHUB_OUTPUT
echo "TEST_COLOR=$TEST_COLOR" >> $GITHUB_OUTPUT
echo "COVERAGE=$COVERAGE" >> $GITHUB_OUTPUT
echo "COVERAGE_COLOR=$COVERAGE_COLOR" >> $GITHUB_OUTPUT
echo "TEST_COUNT=$TEST_COUNT" > badge_data.env
echo "TEST_PASSED=$TEST_PASSED" >> badge_data.env
echo "TEST_COLOR=$TEST_COLOR" >> badge_data.env
echo "COVERAGE=$COVERAGE" >> badge_data.env
echo "COVERAGE_COLOR=$COVERAGE_COLOR" >> badge_data.env
- uses: actions/upload-artifact@v4
with:
name: badge-data
path: badge_data.env

- name: Fail if unit tests are not passing
if: ${{ steps.runtests.outputs.rc != 0}}
Expand Down
33 changes: 23 additions & 10 deletions .github/workflows/update-badges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,41 @@ jobs:
sleep 10
done
update-badges:
update_badges:
name: Update Badges
runs-on: ubuntu-latest
needs: wait-for-test

steps:
- uses: actions/checkout@v4
- name: Checkout Repository
uses: actions/checkout@v4

- name: Download Badge Data Artifact
uses: actions/download-artifact@v4
with:
name: badge-data

- name: "Load Badge Data"
run: |
set -a
source badge_data.env
set +a
- name: Update badges.yaml
- name: "Update badges.yaml"
run: |
cat <<EOF > docs/badges.yaml
test-badge:
status: ${{ github.event.workflow_run.output.TEST_PASSED }} / ${{ github.event.workflow_run.output.TEST_COUNT }} passed
color: ${{ github.event.workflow_run.output.TEST_COLOR }}
status: $TEST_PASSED / $TEST_COUNT passed
color: $TEST_COLOR
coverage-badge:
status: ${{ github.event.workflow_run.output.COVERAGE }}
color: ${{ github.event.workflow_run.output.COVERAGE_COLOR }}
status: $COVERAGE
color: $COVERAGE_COLOR
EOF
- name: Commit and push badges.yaml
- name: "Commit and Push Changes"
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add docs/badges.yaml
git commit -m "chore: update badges.yaml with test results and coverage"
git push
6 changes: 3 additions & 3 deletions docs/badges.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test-badge:
status: / passed
color:
color:
coverage-badge:
status:
color:
status:
color:

0 comments on commit 390d162

Please sign in to comment.