99
1010jobs :
1111 lint :
12- # pull requests are a duplicate of a branch push if they are from within the
13- # same repo. Skip these
14- if : false && github.event_name != 'pull_request' || github.event.pull_request.repository == github.repository
15- runs-on : " ubuntu-latest "
12+ # pull requests are a duplicate of a branch push if within the same repo.
13+ if : github.event_name != 'pull_request' || github.event.pull_request.repository == github.repository
14+ runs-on : ubuntu-latest
15+
1616 steps :
1717 - name : Checkout
1818 uses : actions/checkout@v2
1919
20+ - uses : actions/setup-python@v2
21+ with :
22+ python-version : " 3.10"
23+
2024 - name : Lint
2125 run : |
22- pip install --user .[dev]
26+ touch requirements_dev.txt
27+ python -m pip install --upgrade pip
28+ python -m pip install -r requirements_dev.txt -e .[dev]
2329 tox -e pre-commit,mypy
2430
25- wheel :
26- if : false && github.event_name != 'pull_request' || github.event.pull_request.repository == github.repository
27- strategy :
28- fail-fast : false
29- matrix :
30- os : ["ubuntu-latest"]
31- python : ["3.8"]
32-
33- runs-on : ${{ matrix.os }}
34- steps :
35- - uses : actions/checkout@v2
36-
37- - name : Create Sdist and Wheel
38- # Set SOURCE_DATE_EPOCH from git commit for reproducible build
39- # https://reproducible-builds.org/
40- run : |
41- SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) pipx run build --sdist --wheel
42-
43- - name : Upload Wheel and Sdist as artifacts
44- uses : actions/upload-artifact@v3
45- with :
46- name : dist
47- path : dist
48-
49- - name : Install minimum python version
50- uses : actions/setup-python@v4
51- with :
52- python-version : ${{ matrix.python }}
53-
54- - name : Install wheel in a venv and check cli works
55- # ${GITHUB_REPOSITORY##*/} is the repo name without org
56- # Replace this with the cli command if different to the repo name
57- run : pipx run --python $(which python${{ matrix.python }}) --spec dist/*.whl ${GITHUB_REPOSITORY##*/} --version
58-
5931 test :
60- if : false && github.event_name != 'pull_request' || github.event.pull_request.repository == github.repository
32+ if : github.event_name != 'pull_request' || github.event.pull_request.repository == github.repository
6133 strategy :
6234 fail-fast : false
6335 matrix :
6436 os : ["ubuntu-latest"] # can add windows-latest, macos-latest
6537 python : ["3.8", "3.9", "3.10"]
66- lock : [false]
67-
68- include :
69- # Add an extra Python3.10 runner to use the lockfile
70- - os : " ubuntu-latest"
71- python : " 3.10"
72- lock : true
7338
7439 runs-on : ${{ matrix.os }}
7540 env :
7641 # https://github.com/pytest-dev/pytest/issues/2042
7742 PY_IGNORE_IMPORTMISMATCH : " 1"
78- # enable QT tests with no X Display
79- QT_QPA_PLATFORM : " offscreen"
8043
8144 steps :
8245 - name : Checkout
@@ -89,74 +52,20 @@ jobs:
8952 with :
9053 python-version : ${{ matrix.python }}
9154
92- - name : Install with locked dependencies
93- if : matrix.lock
94- run : |
95- touch requirements.txt
96- touch requirements_dev.txt
97- pip install -r requirements.txt -e .
98- pip freeze --exclude-editable > requirements.txt
99- pip install -r requirements_dev.txt -e .[dev]
100- pip freeze --exclude-editable > requirements_dev.txt
101- # ensure non-zero length requirements.txt
102- echo "# runtime dependencies" >> requirements.txt
103-
10455 - name : Install with latest dependencies
105- if : ${{ ! matrix.lock }}
10656 run : pip install .[dev]
10757
10858 - name : Run tests
10959 run : pytest tests
11060
111- - name : Create requirements_dev.txt
112- run : |
113- pip freeze --exclude-editable > requirements_dev.txt
114-
11561 - name : Upload coverage to Codecov
11662 uses : codecov/codecov-action@v2
11763 with :
118- name : ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.lock }}
64+ name : ${{ matrix.python }}/${{ matrix.os }}
11965 files : cov.xml
12066
121- - name : Upload build files
122- if : matrix.lock
123- uses : actions/upload-artifact@v3
124- with :
125- name : buildfiles
126- path : |
127- requirements.txt
128- requirements_dev.txt
129-
130- release :
131- needs : [lint, wheel, test]
132- runs-on : ubuntu-latest
133- # upload to PyPI and make a release on every tag
134- if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
135- steps :
136- - uses : actions/download-artifact@v3
137- with :
138- path : artifacts
139-
140- - name : Github Release
141- # We pin to the SHA, not the tag, for security reasons.
142- # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
143- uses : softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
144- with :
145- files : |
146- artifacts/dist/*
147- artifacts/buildfiles/*
148- generate_release_notes : true
149- env :
150- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
151-
152- - name : Publish to PyPI
153- env :
154- TWINE_USERNAME : __token__
155- TWINE_PASSWORD : ${{ secrets.pypi_token }}
156- run : pipx run twine upload artifacts/dist/*
157-
158- make-container :
159- # needs: [lint, wheel, test]
67+ container :
68+ if : github.event_name != 'pull_request' || github.event.pull_request.repository == github.repository
16069 runs-on : ubuntu-latest
16170 permissions :
16271 contents : read
@@ -165,11 +74,8 @@ jobs:
16574 steps :
16675 - name : Checkout
16776 uses : actions/checkout@v2
168-
169- # - uses: actions/download-artifact@v3
170- # with:
171- # name: dist
172- # path: dist
77+ with :
78+ fetch-depth : 0
17379
17480 - name : Cache Docker layers
17581 uses : actions/cache@v3
@@ -179,13 +85,13 @@ jobs:
17985 restore-keys : |
18086 ${{ runner.os }}-buildx-
18187
182- # - name: Log in to GitHub Docker Registry
183- # if: github.event_name != 'pull_request'
184- # uses: docker/login-action@v2
185- # with:
186- # registry: ghcr.io
187- # username: ${{ github.actor }}
188- # password: ${{ secrets.GITHUB_TOKEN }}
88+ - name : Log in to GitHub Docker Registry
89+ if : github.event_name != 'pull_request'
90+ uses : docker/login-action@v2
91+ with :
92+ registry : ghcr.io
93+ username : ${{ github.actor }}
94+ password : ${{ secrets.GITHUB_TOKEN }}
18995
19096 - name : Docker meta
19197 id : meta
@@ -195,50 +101,91 @@ jobs:
195101 tags : |
196102 type=ref,event=branch
197103 type=ref,event=tag
198- type=raw,value=latest
199104
200105 - name : Set up Docker Buildx
201106 id : buildx
202107 uses : docker/setup-buildx-action@v2
203108
204- - name : Build runtime image
109+ - name : Build developer image for testing
205110 uses : docker/build-push-action@v3
206111 with :
207- file : .devcontainer/Dockerfile
112+ tags : build:latest
208113 context : .
209- # push: ${{ github.event_name != 'pull_request' }}
210- build-args : BASE=python:3.10-slim
211- tags : ${{ steps.meta.outputs.tags }}
212- labels : ${{ steps.meta.outputs.labels }}
114+ target : build
213115 cache-from : type=local,src=/tmp/.buildx-cache
214116 cache-to : type=local,dest=/tmp/.buildx-cache
215- outputs : type=docker,dest=/tmp/image.tar
117+ load : true
216118
217- - name : show tags
119+ - name : Run tests in the container locked with requirements_dev.txt
218120 run : |
219- echo This is the tags generated by Docker meta
220- echo ${{ steps.meta.outputs.tags }}
121+ docker run --name test build bash /project/tests/container_tests.sh
122+ docker cp test:/project/dist .
123+ docker cp test:/project/requirements.txt .
124+ docker cp test:/project/requirements_dev.txt .
221125
222- - name : Upload container image
223- uses : actions/upload-artifact@v2
126+ - name : Build runtime image
127+ uses : docker/build-push-action@v3
224128 with :
225- name : image
226- path : /tmp/image.tar
129+ push : ${{ github.event_name != 'pull_request' }}
130+ tags : ${{ steps.meta.outputs.tags }}
131+ context : .
132+ labels : ${{ steps.meta.outputs.labels }}
133+ cache-from : type=local,src=/tmp/.buildx-cache
134+ cache-to : type=local,dest=/tmp/.buildx-cache
135+
136+ - name : Upload build files
137+ uses : actions/upload-artifact@v3
138+ with :
139+ name : build_files
140+ path : |
141+ dist
142+ requirements.txt
143+ requirements_dev.txt
227144
228- use-container :
145+ sdist :
146+ needs : container
229147 runs-on : ubuntu-latest
230- needs : make-container
148+
231149 steps :
232- - name : Set up Docker Buildx
233- uses : docker/setup-buildx-action@v1
150+ - name : Checkout
151+ uses : actions/checkout@v2
234152
235- - name : Download artifact
236- uses : actions/download-artifact@v2
153+ - uses : actions/setup-python@v2
237154 with :
238- name : image
239- path : /tmp
155+ python-version : " 3.10"
240156
241- - name : Load Docker image
157+ - uses : actions/download-artifact@v3
158+
159+ - name : Install sdist in a venv and check cli works
160+ # ${GITHUB_REPOSITORY##*/} is the repo name without org
161+ # Replace this with the cli command if different to the repo name
242162 run : |
243- docker load --input /tmp/image.tar
244- docker image ls -a
163+ python -m pip install --upgrade pip
164+ python -m pip install build_files/dist/*.gz
165+ ${GITHUB_REPOSITORY##*/} --version
166+
167+ release :
168+ # upload to PyPI and make a release on every tag
169+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
170+ needs : [lint, container]
171+ runs-on : ubuntu-latest
172+
173+ steps :
174+ - uses : actions/download-artifact@v3
175+
176+ - name : Github Release
177+ # We pin to the SHA, not the tag, for security reasons.
178+ # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
179+ uses : softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
180+ with :
181+ files : |
182+ build_files/*
183+ generate_release_notes : true
184+ env :
185+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
186+
187+ - name : Publish to PyPI
188+ env :
189+ TWINE_USERNAME : __token__
190+ TWINE_PASSWORD : ${{ secrets.pypi_token }}
191+ run : pipx run twine upload artifacts/dist/*
0 commit comments