Merge pull request #4 from avr2002/feat/pytest #19
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
name: Build, Test, and Publish | |
# triggers: whenever there is new changes pulled/pushed on this | |
# repo under given conditions, run the below jobs | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
push: | |
branches: | |
- main | |
# Manually trigger a workflow | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch | |
workflow_dispatch: | |
jobs: | |
check-verison-txt: | |
runs-on: ubuntu-latest | |
steps: | |
# github actions checksout, clones our repo, and checks out the branch we're working in | |
- uses: actions/checkout@v3 | |
with: | |
# Number of commits to fetch. 0 indicates all history for all branches and tags | |
# fetching all tags so to aviod duplicate version tagging in 'Tag with the Release Version' | |
fetch-depth: 0 | |
# tagging the release version to avoid duplicate releases | |
- name: Tag with the Release Version | |
run: | | |
git tag $(cat version.txt) | |
lint-format-and-static-code-checks: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
# caching dependencies | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/.pre-commit-config.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install pre-commit | |
run: | | |
pip install pre-commit | |
- name: Lint, Format, and Other Static Code Quality Check | |
run: | | |
/bin/bash -x run.sh lint:ci | |
build-wheel-and-sdist: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-build | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install build CLI | |
run: | | |
pip install build | |
- name: Build Python Package | |
run: | | |
/bin/bash -x run.sh build | |
# uploading the built package to publish in the publish workflow | |
# https://github.com/actions/upload-artifact | |
- name: Upload wheel and sdist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheel-and-sdist-artifact | |
path: ./dist/* | |
execute-tests: | |
needs: | |
- build-wheel-and-sdist | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
- name: Download wheel and sdist | |
uses: actions/download-artifact@v4 | |
with: | |
name: wheel-and-sdist-artifact | |
path: ./dist/ | |
- name: Install test dependencies | |
run: | | |
pip install pytest pytest-cov ./dist/*.whl | |
- name: Testing the build wheel | |
run: | | |
/bin/bash -x run.sh test:ci | |
publish: | |
needs: | |
- check-verison-txt | |
- lint-format-and-static-code-checks | |
- build-wheel-and-sdist | |
- execute-tests | |
runs-on: ubuntu-latest | |
# only publish when the workflow is run/pushed in main branch | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
# downloading the built package in 'build-wheel-and-sdist' workflow to publish | |
# https://github.com/actions/download-artifact | |
- name: Download wheel and sdist | |
uses: actions/download-artifact@v4 | |
with: | |
name: wheel-and-sdist-artifact | |
path: ./dist/ | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-twine | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install twine CLI | |
run: | | |
pip install twine | |
- name: Publish to Test PyPI | |
# setting -x in below publish:test will not leak any secrets as they are masked in github | |
run: | | |
/bin/bash -x run.sh publish:test | |
env: | |
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }} | |
- name: Publish to Prod PyPI | |
run: | | |
/bin/bash -x run.sh publish:prod | |
env: | |
PROD_PYPI_TOKEN: ${{ secrets.PROD_PYPI_TOKEN }} | |
# make sure to give change Workflow permissions to 'read and write' | |
# in GitHub settings 'Actions/General' | |
- name: Push Tags | |
run: | | |
git push origin --tags | |
# https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log | |
dump_contexts_to_log: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: Dump job context | |
env: | |
JOB_CONTEXT: ${{ toJson(job) }} | |
run: echo "$JOB_CONTEXT" | |
- name: Dump steps context | |
env: | |
STEPS_CONTEXT: ${{ toJson(steps) }} | |
run: echo "$STEPS_CONTEXT" | |
- name: Dump runner context | |
env: | |
RUNNER_CONTEXT: ${{ toJson(runner) }} | |
run: echo "$RUNNER_CONTEXT" | |
- name: Dump strategy context | |
env: | |
STRATEGY_CONTEXT: ${{ toJson(strategy) }} | |
run: echo "$STRATEGY_CONTEXT" | |
- name: Dump matrix context | |
env: | |
MATRIX_CONTEXT: ${{ toJson(matrix) }} | |
run: echo "$MATRIX_CONTEXT" | |
- name: Dump Secrets | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
run: echo "$SECRETS_CONTEXT" | |
- name: Dump Variables | |
run: echo "${{ toJson(vars) }}" |