-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Working on reusable workflows. Associate with Make real build #10. * Still trying to get reusable workflows working. Make real build #10 * More attempts at this reusable job stuff. Make real build #10 * So much for reusability. :( Make real build #10. * Gave up on trying to Don't Repeat Yourself as GitHub actions don't support common sense reuse. Oh well. Associated with Make real build #10. * Added uploading of coverage data and counting the unit tests. Now to test. Associate with Make real build #10. * Working on getting coverage data uploaded. Associate Make real build #10. * Still working on trying to upload coverage data. Associate Make real build #10. * Now with unique names for each OS coverage file. * Removed #pragma no cover lines to test coverage. Associated with Make real build #10. * Added the cov-report-job. Now the testing starts. Associated with Make real build #10. * Had to add emojis! The coverage numbers even surprized me on the first run! 🤯🤯 * Updated text and links in the readme. Associated with Make real build #10. * Added first badge to test. Make real build #10. * Had indenting wrong. Not impressed with YAML so far. Also forgot to use the right GitHub environment variable. * Forgot gist id. Make real build #10. * Added unit test badge. Make real build #10. * Updated README with the new badges. Make real build #10. * Updated more README text. * Renamed the documentation build and deploy file to have consistent naming between code and docs. * Badges only updated on the main branch. Updated comments to reflect the correct badge.
- Loading branch information
1 parent
b14ea79
commit 39c8008
Showing
6 changed files
with
171 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,165 @@ | ||
# My attempt at creating the tbp CI action. | ||
# Use this tool to lint files: https://rhysd.github.io/actionlint/ | ||
# A huge shout out of appreciation to Ned Batchelder! I learned and leaned | ||
# heavily on GitHub Action code from his excellent scriv project. | ||
# https://github.com/nedbat/scriv | ||
# I'm an idiot standing on the shoulder of a giant. Thanks, Ned! | ||
name: Code CI | ||
|
||
# Only trigger on the main branch | ||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab, which is | ||
# kind of important for developing this action! | ||
pull_request: | ||
branches: ["main"] | ||
# Allows you to run this workflow manually from the Actions tab, which is | ||
# kind of important for developing this action as well as testing on any | ||
# branch. | ||
workflow_dispatch: | ||
|
||
jobs: | ||
# I really want to break this up into multiple jobs, but I have no idea how. | ||
setup-python_job: | ||
name: lint-test-cov | ||
|
||
# The first job is to type check and is to type check and lint the project. | ||
# I'll do that on Ubuntu and won't proceed if this fails. | ||
lint-types-job: | ||
name: "Type and Lint Checks" | ||
runs-on: ubuntu-latest | ||
steps: | ||
# You have to love copying and pasting the same 11 lines into each job. | ||
# I tried to make these a reusable job, but GitHub Actions wants to | ||
# force you to ARY: Always Repeat Yourself. 😹😹 | ||
- name: "Checkout Code" | ||
uses: actions/checkout@v4 | ||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: 'pip' | ||
- name: "Install Dependencies" | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install .[dev] | ||
# The unique part starts here. | ||
- name: "Check Types" | ||
run: mypy --config-file pyproject.toml src/ tests/ | ||
- name: Ruff Lint | ||
run: ruff check --config ./pyproject.toml src/ tests/ | ||
- name: Pylint Lint | ||
run: pylint --rcfile pyproject.toml src/ tests/ | ||
|
||
|
||
test-cov-job: | ||
name: "Tests and Coverage" | ||
runs-on: ${{ matrix.os }} | ||
needs: lint-types-job | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
python-version: ["3.12"] | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
# Repeat ourselves again. | ||
- name: "Checkout Code" | ||
uses: actions/checkout@v4 | ||
- name: "Set up Python ${{ matrix.python-version }}" | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: 'pip' | ||
- name: Display OS version | ||
run: | | ||
python3 -c 'import platform; print(f"{platform.system()} - {platform.release()}")' | ||
- name: Install Dependencies | ||
# I'm not sure if I need the 'python -m pip install --editable .' | ||
# there, but I'll play it safe. | ||
- name: "Install Dependencies" | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install .[dev] | ||
python -m pip install --editable . | ||
- name: Check Types | ||
run: mypy --config-file pyproject.toml src/ tests/ | ||
- name: Ruff Lint | ||
run: ruff check --config ./pyproject.toml src/ tests/ | ||
- name: Pylint Lint | ||
run: pylint --rcfile pyproject.toml src/ tests/ | ||
- name: Test and Coverage | ||
# The unique part of this job. | ||
- name: "Test and Coverage" | ||
# Generate the coverage data for this operating system. | ||
# The default name for the file is ".coverage", which is the same for | ||
# all operating systems and makes combining them later a little hard. | ||
# This uses the COVERAGE_FILE environment variable to give each their | ||
# own name. | ||
env: | ||
COVERAGE_FILE: ".coverage.${{ matrix.os }}" | ||
run: | | ||
coverage run -m pytest --maxfail=1 -console_output_style=classic --junit-xml=.test-results.xml | ||
- name: "Count Unit Tests" | ||
# Count the number of unit tests for the badge. | ||
# Note, I had no idea bash could not handle spaces arounf the '=' in | ||
# the export command. | ||
if: runner.os == 'Linux' | ||
run: | | ||
export TOTAL_UNIT_TESTS=$(python ./tools/num_pytest_tests.py .test-results.xml) | ||
echo "total_unit_tests=$TOTAL_UNIT_TESTS" >> $GITHUB_ENV | ||
echo "## Total Unit Tests: :trophy: ${TOTAL_UNIT_TESTS} :1st_place_medal:" >> $GITHUB_STEP_SUMMARY | ||
- name: "Make Unit Tests Badge" | ||
# The unit test badge is only updated on tbp and for the main branch. | ||
if: runner.os == 'Linux' && (github.repository == 'John-Robbins/tbp') && (github.ref == 'refs/heads/main') | ||
# https://gist.github.com/John-Robbins/bd5e145f62ac1cf199a458977b8e1f16 | ||
uses: schneegans/dynamic-badges-action@v1.7.0 | ||
with: | ||
# GIST_BADGES_SECRET is a GitHub personal access token with scope "gist". | ||
auth: ${{ secrets.GIST_BADGES_SECRET }} | ||
gistID: bd5e145f62ac1cf199a458977b8e1f16 | ||
filename: unittestsbadge.json | ||
label: Unit Tests | ||
message: ${{ env.total_unit_tests }} | ||
minColorRange: 200 | ||
maxColorRange: 290 | ||
valColorRange: ${{ env.total_unit_tests }} | ||
style: "flat-square" | ||
- name: "Upload Coverage Data" | ||
# Upload the coverage data for the coverage-job | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: covdata-${{ matrix.os }} | ||
path: .coverage* | ||
|
||
|
||
cov-report-job: | ||
name: "Coverage Reports" | ||
runs-on: ubuntu-latest | ||
needs: test-cov-job | ||
steps: | ||
# Repeat ourselves again. | ||
- name: "Checkout Code" | ||
uses: actions/checkout@v4 | ||
- name: "Set up Python 3.12" | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: 'pip' | ||
- name: "Install Dependencies" | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install .[dev] | ||
# The unique part of this job. | ||
- name: "Download Coverage Data" | ||
# Gather all those operating system coverage files. | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: covdata-* | ||
merge-multiple: true | ||
- name: "Combine and Report" | ||
# Get the code coverage data. | ||
run: | | ||
coverage combine | ||
coverage report --precision=2 --show-missing --sort=Cover --skip-covered | ||
coverage json | ||
export TOTAL_COVERAGE=$(python -c "import json;print(round(float(json.load(open('coverage.json'))['totals']['percent_covered']),2))") | ||
echo "total_coverage=$TOTAL_COVERAGE" >> $GITHUB_ENV | ||
echo "## Total coverage: :fire: ${TOTAL_COVERAGE}% :fireworks:" >> $GITHUB_STEP_SUMMARY | ||
- name: "Make Coverage Badge" | ||
# Code coverage is only updated on tbp and the main branch. | ||
if: (github.repository == 'John-Robbins/tbp') && (github.ref == 'refs/heads/main') | ||
# https://gist.github.com/John-Robbins/bd5e145f62ac1cf199a458977b8e1f16 | ||
uses: schneegans/dynamic-badges-action@v1.7.0 | ||
with: | ||
# GIST_BADGES_SECRET is a GitHub personal access token with scope "gist". | ||
auth: ${{ secrets.GIST_BADGES_SECRET }} | ||
gistID: bd5e145f62ac1cf199a458977b8e1f16 | ||
filename: covbadge.json | ||
label: Coverage | ||
message: ${{ env.total_coverage }}% | ||
minColorRange: 50 | ||
maxColorRange: 90 | ||
valColorRange: ${{ env.total_coverage }} | ||
style: "flat-square" | ||
|
||
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,5 @@ asciinema | |
prime-decomp | ||
Otten | ||
IntelliSense | ||
Batchelder | ||
scriv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters