Build, Test and Publish #10
Workflow file for this run
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 | |
on: | |
push: | |
tags: | |
- 'v*' # version tags for PyPI | |
- 'test*' # test tags for TestPyPI | |
jobs: | |
test: | |
name: Run Python Tests | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install . | |
pip install pytest hatch | |
- name: Configure matplotlib backend | |
run: | | |
mkdir -p $HOME/.config/matplotlib | |
echo "backend: Agg" > $HOME/.config/matplotlib/matplotlibrc | |
- name: Run tests | |
run: | | |
python -c "import logomaker; logomaker.run_tests()" | |
publish: | |
name: Build and Publish | |
needs: [test] | |
runs-on: ubuntu-latest | |
# Run publish job it's a tag push starting with v or test | |
# Use v* tags (e.g., v1.0.0) for PyPI releases (must be on master branch) | |
# Use test* tags (e.g., test1.0.0) for TestPyPI releases | |
# if: (startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/tags/test')) | |
steps: | |
- name: Debug | |
run: | | |
echo "github.ref = ${{ github.ref }}" | |
echo "github.event_name = ${{ github.event_name }}" | |
echo "github.sha = ${{ github.sha }}" | |
echo "github.base_ref = ${{ github.base_ref }}" | |
echo "github.ref_type = ${{ github.ref_type }}" | |
echo "github.ref_name = ${{ github.ref_name }}" | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Get all history for branch checking | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build twine hatch | |
- name: Build package | |
run: python -m build | |
- name: Publish to PyPI | |
# Only publish to PyPI when a v* tag is pushed on the master branch | |
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: twine upload dist/* | |
- name: Publish to TestPyPI | |
# Only publish to TestPyPI when a test* tag is pushed | |
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'test') | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ | |
run: twine upload dist/* | |
set-rtd-default: | |
name: Set ReadTheDocs Default Version | |
needs: [publish] | |
runs-on: ubuntu-latest | |
# Only run for PyPI releases (v* tags) | |
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') | |
steps: | |
- name: Wait for ReadTheDocs build | |
# Give RTD some time to detect the new tag and start building | |
run: sleep 60 | |
- name: Set RTD Default Version | |
run: | | |
curl -X PATCH \ | |
-H "Authorization: Token ${{ secrets.RTD_API_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
-d '{"default_version": "latest"}' \ | |
https://readthedocs.org/api/v3/projects/logomaker/ | |