66 schedule :
77 # Run every Monday at 8am to check latest versions of dependencies
88 - cron : " 0 8 * * WED"
9+ env :
10+ # The target python version, which must match the Dockerfile version
11+ CONTAINER_PYTHON : " 3.11"
912
1013jobs :
1114 lint :
@@ -17,29 +20,28 @@ jobs:
1720 - name : Checkout
1821 uses : actions/checkout@v3
1922
20- - name : Setup python
21- uses : actions/setup-python@v4
23+ - name : Install python packages
24+ uses : ./.github/ actions/install_requirements
2225 with :
23- python-version : " 3.x"
26+ requirements_file : requirements-dev-3.x.txt
27+ install_options : -e .[dev]
2428
2529 - name : Lint
26- run : |
27- .github/workflows/pip_install.sh lint -e .[dev]
28- tox -e pre-commit,mypy
29-
30- - name : Upload lockfiles
31- uses : actions/upload-artifact@v3
32- with :
33- name : lockfiles
34- path : lockfiles
30+ run : tox -e pre-commit,mypy
3531
3632 test :
3733 if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
3834 strategy :
3935 fail-fast : false
4036 matrix :
4137 os : ["ubuntu-latest"] # can add windows-latest, macos-latest
42- python : ["3.8", "3.9", "3.10", "3.11"]
38+ python : ["3.9", "3.10", "3.11"]
39+ install : ["-e .[dev]"]
40+ # Make one version be non-editable to test both paths of version code
41+ include :
42+ - os : " ubuntu-latest"
43+ python : " 3.8"
44+ install : " .[dev]"
4345
4446 runs-on : ${{ matrix.os }}
4547 env :
@@ -55,62 +57,61 @@ jobs:
5557 - name : Checkout
5658 uses : actions/checkout@v3
5759 with :
60+ # Need this to get version number from last tag
5861 fetch-depth : 0
5962
60- - name : Setup python ${{ matrix.python }}
61- uses : actions/setup-python@v4
63+ - name : Install python packages
64+ uses : ./.github/ actions/install_requirements
6265 with :
63- python-version : ${{ matrix.python }}
64-
65- - name : Install with latest dependencies
66- run : .github/workflows/pip_install.sh test-${{ matrix.python }}-${{ matrix.os }} .[dev]
66+ python_version : ${{ matrix.python }}
67+ requirements_file : requirements-test-${{ matrix.os }}-${{ matrix.python }}.txt
68+ install_options : ${{ matrix.install }}
6769
6870 - name : Run tests
69- run : pytest tests
71+ run : pytest
7072
7173 - name : Upload coverage to Codecov
7274 uses : codecov/codecov-action@v3
7375 with :
7476 name : ${{ matrix.python }}/${{ matrix.os }}
7577 files : cov.xml
7678
77- - name : Upload lockfiles
78- uses : actions/upload-artifact@v3
79- with :
80- name : lockfiles
81- path : lockfiles
82-
8379 dist :
8480 if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
8581 runs-on : " ubuntu-latest"
8682
8783 steps :
88- - name : Checkout Source
84+ - name : Checkout
8985 uses : actions/checkout@v3
9086 with :
87+ # Need this to get version number from last tag
9188 fetch-depth : 0
9289
93- - name : Build Sdist and wheel
90+ - name : Build sdist and wheel
9491 run : |
9592 export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
9693 pipx run build
9794
98- - name : Test module --version works using the installed wheel
99- run : |
100- touch requirements.txt
101- pip install -r requirements.txt dist/*.whl
102- # If more than one module in src/ replace with module name to test
103- python -m $(ls src | head -1) --version
104-
105- - name : Check for packaging errors
106- run : pipx run twine check dist/*
107-
10895 - name : Upload sdist and wheel as artifacts
10996 uses : actions/upload-artifact@v3
11097 with :
11198 name : dist
11299 path : dist
113100
101+ - name : Check for packaging errors
102+ run : pipx run twine check dist/*
103+
104+ - name : Install python packages
105+ uses : ./.github/actions/install_requirements
106+ with :
107+ python_version : ${{env.CONTAINER_PYTHON}}
108+ requirements_file : requirements.txt
109+ install_options : dist/*.whl
110+
111+ - name : Test module --version works using the installed wheel
112+ # If more than one module in src/ replace with module name to test
113+ run : python -m $(ls src | head -1) --version
114+
114115 container :
115116 needs : [lint, dist, test]
116117 runs-on : ubuntu-latest
@@ -124,11 +125,11 @@ jobs:
124125 uses : actions/checkout@v3
125126
126127 # image names must be all lower case
127- - run : |
128- echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
128+ - name : Generate image repo name
129+ run : echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
129130
130- # obtain the python wheel from the dist step
131- - uses : actions/download-artifact@v3
131+ - name : Download wheel and lockfiles
132+ uses : actions/download-artifact@v3
132133
133134 - name : Log in to GitHub Docker Registry
134135 if : github.event_name != 'pull_request'
@@ -154,6 +155,8 @@ jobs:
154155 - name : Build runtime image
155156 uses : docker/build-push-action@v3
156157 with :
158+ build-args : |
159+ PIP_OPTIONS=-r lockfiles/requirements.txt dist/*.whl
157160 push : ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
158161 load : ${{ ! (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }}
159162 tags : ${{ steps.meta.outputs.tags }}
@@ -162,17 +165,7 @@ jobs:
162165 cache-to : type=gha,mode=max
163166
164167 - name : Test cli works in runtime image
165- # check that the latest tag can run with --version parameter
166- run : |
167- docker run ${{ env.IMAGE_REPOSITORY }} --version
168- mkdir -p lockfiles
169- docker run --entrypoint pip ${{ env.IMAGE_REPOSITORY }} freeze > lockfiles/requirements.txt
170-
171- - name : Upload lockfiles
172- uses : actions/upload-artifact@v3
173- with :
174- name : lockfiles
175- path : lockfiles
168+ run : docker run ${{ env.IMAGE_REPOSITORY }} --version
176169
177170 release :
178171 # upload to PyPI and make a release on every tag
@@ -183,6 +176,10 @@ jobs:
183176 steps :
184177 - uses : actions/download-artifact@v3
185178
179+ - name : Fixup blank lockfiles
180+ # Github release artifacts can't be blank
181+ run : for f in lockfiles/*; [ -s $f ] || echo '# No requirements' >> $f; done
182+
186183 - name : Github Release
187184 # We pin to the SHA, not the tag, for security reasons.
188185 # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
0 commit comments