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

split github workflows into test.yml and publish.yml #165

Merged
merged 1 commit into from
Nov 29, 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
Original file line number Diff line number Diff line change
@@ -1,54 +1,30 @@
# This workflow does the following:
#
# - run tests and lint with a variety of Python versions on windows, linux and macos [1]
# - build the tufup package [2]
# - publish to test.pypi.org [2]
# - publish to pypi.org [2]
# - run tests
# - build the tufup package [1]
# - publish to test.pypi.org [1]
# - publish to pypi.org [1]
#
# Notes:
#
# - to skip the workflow, add [skip ci] to the commit message [3]
# - to skip the workflow, add [skip ci] to the commit message [2]
#
# References
#
# [1]: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# [2]: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# [3]: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
# [1]: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# [2]: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs


name: Python package
name: build and publish

on:
release:
types: [created]

on: [push, workflow_dispatch]

jobs:
test:
# based on [1]
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
# see currently supported releases: https://devguide.python.org/versions/
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with ruff
run: |
pip install ruff
ruff check --output-format=github .
- name: Test with unittest
run: |
python -m unittest

# re-use test workflow
uses: ./.github/workflows/test.yml
build:
# based on [2]
needs: test
Expand Down Expand Up @@ -77,27 +53,25 @@ jobs:
fi
fi
- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
# based on [2]
# based on [1]
# to install from test.pypi:
# pip install tufup --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple
needs: [test, build]
runs-on: ubuntu-latest
# only publish to test.pypi on tag pushes
if: startsWith(github.ref, 'refs/tags/')
environment:
name: testpypi
url: https://test.pypi.org/p/tufup
permissions:
id-token: write
steps:
- name: Download the distribution packages
uses: actions/download-artifact@v4.1.7
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand All @@ -108,19 +82,17 @@ jobs:

publish-to-pypi:
# this requires manual confirmation on github
# based on [2]
# based on [1]
needs: [test, build, publish-to-testpypi]
runs-on: ubuntu-latest
# only publish to pypi on tag pushes
if: startsWith(github.ref, 'refs/tags/')
environment:
name: pypi
url: https://pypi.org/p/tufup
permissions:
id-token: write
steps:
- name: Download the distribution packages
uses: actions/download-artifact@v4.1.7
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This workflow does the following:
#
# - run tests and lint with a variety of Python versions on windows, linux and macos [1]
#
# Notes:
#
# - to skip the workflow, add [skip ci] to the commit message [2]
# - the workflow is reusable [3]
#
# References
#
# [1]: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# [2]: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
# [3]: https://docs.github.com/en/actions/sharing-automations/reusing-workflows

name: lint and unittest

on:
- push
- pull_request
# enable manual trigger
- workflow_dispatch
# make reusable
- workflow_call

jobs:
test:
# based on [1]
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
# see currently supported releases: https://devguide.python.org/versions/
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with ruff
run: |
pip install ruff
ruff check --output-format=github .
- name: Test with unittest
run: |
python -m unittest
Loading