-
Notifications
You must be signed in to change notification settings - Fork 11
113 lines (104 loc) · 5.49 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# This workflow will test the module and then upload to PyPi, when triggered by the creation of a new GitHub Release
# It uses the Python Package GitHub Actions workflow.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# and https://www.youtube.com/watch?v=l6fV09z5XHk
# and https://py-pkgs.org/08-ci-cd#uploading-to-testpypi-and-pypi
name: ci-cd
# Build only on creation of new releases
on:
# push: # build on every commit push
# pull_request: # build on every pull request
release: # build on every releases
types:
- published # use published, not released and prereleased, because prereleased is not triggered if created from a draft: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
jobs:
testbuild:
name: Unit test and building
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["*"] # check the list of versions: https://github.com/actions/python-versions/releases and https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md -- note that "*" represents the latest stable version of Python
os: [ ubuntu-latest, windows-latest, macos-latest ] # jobs that run on Windows and macOS runners that GitHub hosts consume minutes at 2 and 10 times the rate that jobs on Linux runners consume respectively. But it's free for public OSS repositories.
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
# You can test your matrix by printing the current Python version
- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
#python -m pip install pytest pytest-cov # done in setup.cfg for Py2 or pyproject.toml for Py3
#if [ ${{ matrix.python-version }} <= 3.7 ]; then python -m pip install 'coverage<4'; else python -m pip install coverage; fi
#if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install this module
#if: ${{ matrix.python-version >= 3 }} # does not work on dynamic versions, see: https://github.com/actions/setup-python/issues/644
# Do not import testmeta, they make the build fails somehow, because some dependencies are unavailable on Py2
run: |
#python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --upgrade --editable .[test] --verbose --use-pep517
# Here we do NOT build against test.pypi.org but only the real pypi because we want to test before shipping whether users with a normal pypi version can install our package!
python -m pip install --upgrade --editable .[test] --verbose --use-pep517
- name: Test with pytest
run: |
coverage run --branch -m pytest . -v
coverage report -m
- name: Build source distribution and wheel
run: |
python -m pip install --upgrade build
python -sBm build
- name: Save dist/ content for reuse in other GitHub Workflow blocks
uses: actions/upload-artifact@v3
with:
path: dist/*
upload_test_pypi: # Upload to TestPyPi first to ensure that the release is OK (we will try to download it and install it afterwards), as recommended in https://py-pkgs.org/08-ci-cd#uploading-to-testpypi-and-pypi
name: Upload to TestPyPi
needs: [testbuild]
runs-on: ubuntu-latest
steps:
- name: Unpack default artifact into dist/
uses: actions/[email protected]
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- name: Upload to TestPyPi
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
# To test: repository_url: https://test.pypi.org/legacy/ # and also change token: ${{ secrets.PYPI_API_TOKEN }} to secrets.TEST_PYPI_API_TOKEN # for more infos on registering and using TestPyPi, read: https://py-pkgs.org/08-ci-cd#uploading-to-testpypi-and-pypi -- remove the repository_url to upload to the real PyPi
- name: Test install from TestPyPI
run: |
python -m pip install --upgrade pip
pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
pyFileFixity
upload_pypi: # Upload to the real PyPi if everything else worked before, as suggested in: https://py-pkgs.org/08-ci-cd#uploading-to-testpypi-and-pypi
name: Upload to the real PyPi
needs: [testbuild, upload_test_pypi]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Test install from PyPI
run: |
python -m pip install --upgrade pip
pip uninstall pyFileFixity -y
pip install --upgrade pyFileFixity