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. Make sure the Dockerfile uses the same
11+ # version for its build and runtime targets.
12+ PYTHON : " 3.10"
913
1014jobs :
1115 lint :
2024 - name : Setup python
2125 uses : actions/setup-python@v4
2226 with :
23- python-version : " 3.10 "
27+ python-version : ${{env.PYTHON}}
2428
2529 - name : Lint
2630 run : |
5357 python-version : ${{ matrix.python }}
5458
5559 - name : Install with latest dependencies
56- run : pip install .[dev]
60+ run : |
61+ pip install .[dev]
62+ mkdir -p lockfiles
63+ pip freeze > lockfiles/requirements-dev-py${{ matrix.python }}.txt
5764
5865 - name : Run tests
5966 run : pytest tests
6471 name : ${{ matrix.python }}/${{ matrix.os }}
6572 files : cov.xml
6673
74+ - name : Upload lock files
75+ uses : actions/upload-artifact@v3
76+ with :
77+ name : lockfiles
78+ path : lockfiles
79+
80+ dist :
81+ if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
82+ runs-on : " ubuntu-latest"
83+
84+ steps :
85+ - name : Checkout Source
86+ uses : actions/checkout@v3
87+ with :
88+ fetch-depth : 0
89+
90+ - name : Setup python
91+ uses : actions/setup-python@v4
92+ with :
93+ python-version : ${{env.PYTHON}}
94+
95+ - name : Build Sdist and wheel
96+ run : |
97+ export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
98+ pipx run --python $(which python${{env.PYTHON}}) build
99+
100+ # ${GITHUB_REPOSITORY##*/} is the repo name without org
101+ # Replace this with the cli command if different to the repo name
102+ - name : Test cli works in sdist installed in local python
103+ run : |
104+ touch requirements.txt
105+ pip install -r requirements.txt dist/*.gz ${GITHUB_REPOSITORY##*/} --version
106+
107+ # create a requirements.txt to be published as a github release asset
108+ - name : get a requirements.txt from the installed sdist
109+ run : |
110+ mkdir -p lockfiles
111+ pip freeze > lockfiles/requirements.txt
112+
113+ - name : Upload sdist and wheel as artifacts
114+ uses : actions/upload-artifact@v3
115+ with :
116+ name : dist
117+ path : dist
118+
119+ - name : Upload lock files
120+ uses : actions/upload-artifact@v3
121+ with :
122+ name : lockfiles
123+ path : lockfiles
124+
67125 container :
126+ needs : [dist]
68127 if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
69128 runs-on : ubuntu-latest
129+
70130 permissions :
71131 contents : read
72132 packages : write
@@ -77,6 +137,12 @@ jobs:
77137 with :
78138 fetch-depth : 0
79139
140+ - uses : actions/download-artifact@v3
141+
142+ - name : PrepareReg Names
143+ run : |
144+ echo IMAGE_REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
145+
80146 - name : Log in to GitHub Docker Registry
81147 if : github.event_name != 'pull_request'
82148 uses : docker/login-action@v2
@@ -89,74 +155,43 @@ jobs:
89155 id : meta
90156 uses : docker/metadata-action@v4
91157 with :
92- images : ghcr.io/ ${{ github.repository }}
158+ images : ${{env.IMAGE_REPOSITORY }}
93159 tags : |
94- type=ref,event=branch
95160 type=ref,event=tag
161+ type=raw,value=latest
96162
97163 - name : Set up Docker Buildx
98164 id : buildx
99165 uses : docker/setup-buildx-action@v2
100166
101- - name : Build developer image for testing
102- uses : docker/build-push-action@v3
103- with :
104- tags : build:latest
105- context : .
106- target : build
107- load : true
108-
109- - name : Run tests in the container locked with requirements_dev.txt
110- run : |
111- docker run --name test build bash /project/.github/workflows/container_tests.sh
112- docker cp test:/project/dist .
113- docker cp test:/project/lockfiles .
114- docker cp test:/project/cov.xml .
115-
116- - name : Upload coverage to Codecov
117- uses : codecov/codecov-action@v3
118- with :
119- name : 3.10-locked/ubuntu-latest
120- files : cov.xml
121-
122167 - name : Build runtime image
123168 uses : docker/build-push-action@v3
124169 with :
125- push : ${{ github.event_name != 'pull_request' }}
170+ push : true
171+ load : true
126172 tags : ${{ steps.meta.outputs.tags }}
127173 context : .
128- labels : ${{ steps.meta.outputs.labels }}
129174
130175 - name : Test cli works in runtime image
131176 # check that the first tag can run with --version parameter
132- run : docker run $(echo ${{ steps.meta.outputs.tags }} | head -1) --version
133-
134- - name : Test cli works in sdist installed in local python
135- # ${GITHUB_REPOSITORY##*/} is the repo name without org
136- # Replace this with the cli command if different to the repo name
137- run : pip install dist/*.gz && ${GITHUB_REPOSITORY##*/} --version
138-
139- - name : Upload build files
140- uses : actions/upload-artifact@v3
141- with :
142- name : dist
143- path : dist
177+ run : docker run ${{env.IMAGE_REPOSITORY}}:latest --version
144178
145- - name : Upload lock files
146- uses : actions/upload-artifact@v3
147- with :
148- name : lockfiles
149- path : lockfiles
179+ # TODO upload a tar of the image for later publishing
180+ # TODO OR do the publish here ??? if its quick enough - MUCH easier ?
150181
151182 release :
152183 # upload to PyPI and make a release on every tag
153184 if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
154- needs : container
185+ needs : [lint, dist]
155186 runs-on : ubuntu-latest
156187
157188 steps :
158189 - uses : actions/download-artifact@v3
159190
191+ - name : fixup requirements files
192+ # use sed to comment out the self references in requirements files
193+ run : sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements*.txt
194+
160195 - name : Github Release
161196 # We pin to the SHA, not the tag, for security reasons.
162197 # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
0 commit comments