Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷Add dynamic status badge using schneegans/dynamic-badges-action #35

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
os: ${{ fromJson(needs.set_variables.outputs.os) }}
python-version: ${{ fromJson(needs.set_variables.outputs.versions_python) }}
runs-on: ${{ matrix.os }}
outputs:
test_status: ${{ steps.set_status.outputs.status }}
steps:
- name: Checkout repository
uses: actions/checkout@v4.2.2
Expand Down Expand Up @@ -131,7 +133,58 @@ jobs:

- name: Run pytest
id: pytest
continue-on-error: true
shell: bash
run: |
output="$(poetry run pytest)"
echo "${output}"
poetry run pytest

- name: Set test status
id: set_status
if: always()
shell: bash
run: |
if [ "${{ job.status }}" == "cancelled" ]; then
echo "status=cancelled" >> "$GITHUB_OUTPUT"
elif [ "${{ job.status }}" == "skipped" ]; then
echo "status=skipped" >> "$GITHUB_OUTPUT"
elif [ "${{ steps.pytest.outcome }}" == "failure" ]; then
echo "status=failing" >> "$GITHUB_OUTPUT"
elif [ "${{ steps.pytest.outcome }}" == "success" ]; then
echo "status=passing" >> "$GITHUB_OUTPUT"
else
echo "status=pending" >> "$GITHUB_OUTPUT"
fi

update_badge:
needs: run_tests
runs-on: ubuntu-latest
if: always()
steps:
- name: Set color
id: set_color
shell: bash
run: |
status="${{ needs.run_tests.outputs.test_status }}"
if [ "$status" == "passing" ]; then
echo "color=2ea44f" >> "$GITHUB_OUTPUT"
elif [ "$status" == "failing" ]; then
echo "color=cf222e" >> "$GITHUB_OUTPUT"
elif [ "$status" == "pending" ]; then
echo "color=dbab09" >> "$GITHUB_OUTPUT"
else
echo "color=808080" >> "$GITHUB_OUTPUT"
fi

- name: Create badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: 26cb492ab0cfff920c516a622b2bfa44
filename: python-test-badge.json
label: Python Test
message: ${{ needs.run_tests.outputs.test_status }}
color: ${{ steps.set_color.outputs.color }}
labelColor: "24292f"
style: "flat"
namedLogo: "github"
logoColor: "white"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

| Languages | Test Status |
|-------|-------|
| [![Python](https://img.shields.io/badge/Python-3776AB?style=flat&logo=python&logoColor=white)](.github/workflows/python_test.yml) | [![Python Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/python_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/python_test.yml) |
| [![Python](https://img.shields.io/badge/Python-3776AB?style=flat&logo=python&logoColor=white)](.github/workflows/python_test.yml) | [![Python Test](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/7rikazhexde/26cb492ab0cfff920c516a622b2bfa44/raw/python-test-badge.json&cacheSeconds=0)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/python_test.yml) |
| [![Node.js](https://img.shields.io/badge/Node.js-339933?style=flat&logo=node.js&logoColor=white)](.github/workflows/nodejs_test.yml) | [![Node.js Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/nodejs_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/nodejs_test.yml) |
| [![Ruby](https://img.shields.io/badge/Ruby-CC342D?style=flat&logo=ruby&logoColor=white)](.github/workflows/ruby_test.yml) | [![Ruby Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/ruby_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/ruby_test.yml) |
| [![Go](https://img.shields.io/badge/Go-00ADD8?style=flat&logo=go&logoColor=white)](.github/workflows/go_test.yml) | [![Go Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/go_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/go_test.yml) |
Expand Down
Loading