@@ -20,21 +20,29 @@ jobs:
2020 - name : Setup python
2121 uses : actions/setup-python@v4
2222 with :
23- python-version : " 3.10 "
23+ python-version : " 3.x "
2424
2525 - name : Lint
2626 run : |
27- touch requirements_dev .txt requirements.txt
28- pip install -r requirements.txt -r requirements_dev .txt -e .[dev]
27+ touch requirements-lint .txt requirements.txt
28+ pip install -r requirements.txt -r requirements-lint .txt -e .[dev]
2929 tox -e pre-commit,mypy
30+ mkdir -p lockfiles
31+ pip freeze > lockfiles/requirements-lint.txt
32+
33+ - name : Upload lockfiles
34+ uses : actions/upload-artifact@v3
35+ with :
36+ name : lockfiles
37+ path : lockfiles
3038
3139 test :
3240 if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
3341 strategy :
3442 fail-fast : false
3543 matrix :
3644 os : ["ubuntu-latest"] # can add windows-latest, macos-latest
37- python : ["3.8", "3.9", "3.10"]
45+ python : ["3.8", "3.9", "3.10", "3.11" ]
3846
3947 runs-on : ${{ matrix.os }}
4048 env :
5866 python-version : ${{ matrix.python }}
5967
6068 - name : Install with latest dependencies
61- run : pip install .[dev]
69+ run : |
70+ pip install .[dev]
71+ mkdir -p lockfiles
72+ pip freeze > lockfiles/requirements-test-${{ matrix.python }}-${{ matrix.os }}.txt
6273
6374 - name : Run tests
6475 run : pytest tests
@@ -69,18 +80,65 @@ jobs:
6980 name : ${{ matrix.python }}/${{ matrix.os }}
7081 files : cov.xml
7182
72- container :
83+ - name : Upload lockfiles
84+ uses : actions/upload-artifact@v3
85+ with :
86+ name : lockfiles
87+ path : lockfiles
88+
89+ dist :
7390 if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
91+ runs-on : " ubuntu-latest"
92+
93+ steps :
94+ - name : Checkout Source
95+ uses : actions/checkout@v3
96+ with :
97+ fetch-depth : 0
98+
99+ - name : Build Sdist and wheel
100+ run : |
101+ export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
102+ pipx run build
103+
104+ # ${GITHUB_REPOSITORY##*/} is the repo name without org
105+ # Replace this with the cli command if different to the repo name
106+ - name : Test cli works using the wheel installed in local python
107+ run : |
108+ touch requirements.txt
109+ pip install -r requirements.txt dist/*.whl
110+ ${GITHUB_REPOSITORY##*/} --version
111+
112+ - name : Test Publish to PyPI
113+ env :
114+ TWINE_USERNAME : __token__
115+ TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
116+ run : pipx run twine check dist/*
117+
118+ - name : Upload sdist and wheel as artifacts
119+ uses : actions/upload-artifact@v3
120+ with :
121+ name : dist
122+ path : dist
123+
124+ container :
125+ needs : [lint, dist, test]
74126 runs-on : ubuntu-latest
127+
75128 permissions :
76129 contents : read
77130 packages : write
78131
79132 steps :
80133 - name : Checkout
81134 uses : actions/checkout@v3
82- with :
83- fetch-depth : 0
135+
136+ # image names must be all lower case
137+ - run : |
138+ echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
139+
140+ # obtain the python wheel from the dist step
141+ - uses : actions/download-artifact@v3
84142
85143 - name : Log in to GitHub Docker Registry
86144 if : github.event_name != 'pull_request'
@@ -94,75 +152,51 @@ jobs:
94152 id : meta
95153 uses : docker/metadata-action@v4
96154 with :
97- images : ghcr.io/ ${{ github.repository }}
155+ images : ${{ env.IMAGE_REPOSITORY }}
98156 tags : |
99- type=ref,event=branch
100157 type=ref,event=tag
158+ type=raw,value=latest
101159
102160 - name : Set up Docker Buildx
103161 id : buildx
104162 uses : docker/setup-buildx-action@v2
105163
106- - name : Build developer image for testing
107- uses : docker/build-push-action@v3
108- with :
109- tags : build:latest
110- context : .
111- target : build
112- load : true
113-
114- - name : Run tests in the container locked with requirements_dev.txt
115- run : |
116- docker run --name test build bash /project/.github/workflows/container_tests.sh
117- docker cp test:/project/dist .
118- docker cp test:/project/lockfiles .
119- docker cp test:/project/cov.xml .
120-
121- - name : Upload coverage to Codecov
122- uses : codecov/codecov-action@v3
123- with :
124- name : 3.10-locked/ubuntu-latest
125- files : cov.xml
126-
127164 - name : Build runtime image
128165 uses : docker/build-push-action@v3
129166 with :
130- push : ${{ github.event_name != 'pull_request' }}
167+ push : ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
168+ load : ${{ ! (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }}
131169 tags : ${{ steps.meta.outputs.tags }}
132170 context : .
133- labels : ${{ steps.meta.outputs.labels }}
171+ cache-from : type=gha
172+ cache-to : type=gha,mode=max
134173
135174 - name : Test cli works in runtime image
136- # check that the first tag can run with --version parameter
137- run : docker run $(echo ${{ steps.meta.outputs.tags }} | head -1) --version
138-
139- - name : Test cli works in sdist installed in local python
140- # ${GITHUB_REPOSITORY##*/} is the repo name without org
141- # Replace this with the cli command if different to the repo name
142- # (python3-pip-skeleton-cli replaces this with python3-pip-skeleton)
143- run : pip install dist/*.gz && python3-pip-skeleton --version
144-
145- - name : Upload build files
146- uses : actions/upload-artifact@v3
147- with :
148- name : dist
149- path : dist
175+ # check that the latest tag can run with --version parameter
176+ run : |
177+ docker run ${{ env.IMAGE_REPOSITORY }} --version
178+ mkdir -p lockfiles
179+ docker run --entrypoint pip ${{ env.IMAGE_REPOSITORY }} freeze > lockfiles/requirements.txt
150180
151- - name : Upload lock files
181+ - name : Upload lockfiles
152182 uses : actions/upload-artifact@v3
153183 with :
154184 name : lockfiles
155185 path : lockfiles
156186
157187 release :
158188 # upload to PyPI and make a release on every tag
159- if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
160- needs : container
189+ needs : [lint, dist, test]
190+ if : ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
161191 runs-on : ubuntu-latest
162192
163193 steps :
164194 - uses : actions/download-artifact@v3
165195
196+ - name : fixup requirements files
197+ # use sed to comment out the self references in requirements files
198+ run : sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements*.txt
199+
166200 - name : Github Release
167201 # We pin to the SHA, not the tag, for security reasons.
168202 # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
0 commit comments