@@ -2,111 +2,176 @@ name: Code CI
22
33on :
44 push :
5- branches :
6- # Restricting to these branches and tags stops duplicate jobs on internal
7- # PRs but stops CI running on internal branches without a PR. Delete the
8- # next 5 lines to restore the original behaviour
9- - master
10- - main
11- tags :
12- - " *"
135 pull_request :
146 schedule :
157 # Run every Monday at 8am to check latest versions of dependencies
16- - cron : ' 0 8 * * MON '
8+ - cron : " 0 8 * * WED "
179
1810jobs :
1911 lint :
20- runs-on : " ubuntu-latest"
21- steps :
22- - name : Run black, flake8, mypy
23- uses : dls-controls/pipenv-run-action@v1
24- with :
25- pipenv-run : lint
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.head.repo.full_name != github.repository
14+ runs-on : ubuntu-latest
2615
27- wheel :
28- runs-on : " ubuntu-latest"
2916 steps :
30- - uses : actions/checkout@v2
17+ - name : Checkout
18+ uses : actions/checkout@v2
19+
20+ - name : Setup python
21+ uses : actions/setup-python@v4
3122 with :
32- fetch-depth : 0
23+ python-version : " 3.10 "
3324
34- - name : Create Sdist and Wheel
35- # Set SOURCE_DATE_EPOCH from git commit for reproducible build
36- # https://reproducible-builds.org/
37- # Set group writable and umask to do the same to match inside DLS
25+ - name : Lint
3826 run : |
39- chmod -R g+w .
40- umask 0002
41- SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) pipx run build --sdist --wheel
42-
43- - name : Test cli works from the installed wheel
44- # Can remove the repository reference after https://github.com/pypa/pipx/pull/733
45- run : pipx run --spec dist/*.whl ${GITHUB_REPOSITORY##*/} --version
46-
47- - name : Upload Wheel and Sdist as artifacts
48- uses : actions/upload-artifact@v2
49- with :
50- name : dist
51- path : dist/*
27+ touch requirements_dev.txt requirements.txt
28+ pip install -r requirements.txt -r requirements_dev.txt -e .[dev]
29+ tox -e pre-commit,mypy
5230
5331 test :
32+ if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
5433 strategy :
5534 fail-fast : false
5635 matrix :
57- os : ["ubuntu-latest"] # can add windows-latest, macos-latest
58- python : ["3.7", "3.8", "3.9"]
59- pipenv : ["skip-lock"]
60-
61- include :
62- # Add an extra Python3.7 runner to use the lockfile
63- - os : " ubuntu-latest"
64- python : " 3.7"
65- pipenv : " deploy"
36+ os : ["ubuntu-latest"] # can add windows-latest, macos-latest
37+ python : ["3.8", "3.9", "3.10"]
6638
6739 runs-on : ${{ matrix.os }}
6840 env :
6941 # https://github.com/pytest-dev/pytest/issues/2042
7042 PY_IGNORE_IMPORTMISMATCH : " 1"
7143
7244 steps :
73- - name : Setup repo and test
74- uses : dls-controls/pipenv-run-action@v1
45+ - name : Checkout
46+ uses : actions/checkout@v2
47+ with :
48+ fetch-depth : 0
49+
50+ - name : Setup python ${{ matrix.python }}
51+ uses : actions/setup-python@v4
7552 with :
7653 python-version : ${{ matrix.python }}
77- pipenv-install : --dev --${{ matrix.pipenv }}
78- allow-editable-installs : ${{ matrix.pipenv == 'deploy' }}
79- pipenv-run : tests
54+
55+ - name : Install with latest dependencies
56+ run : pip install .[dev]
57+
58+ - name : Run tests
59+ run : pytest tests
8060
8161 - name : Upload coverage to Codecov
82- uses : codecov/codecov-action@v2
62+ uses : codecov/codecov-action@v3
8363 with :
84- name : ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.pipenv }}
64+ name : ${{ matrix.python }}/${{ matrix.os }}
8565 files : cov.xml
8666
87- release :
88- needs : [lint, wheel, test]
67+ container :
68+ if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
8969 runs-on : ubuntu-latest
90- # upload to PyPI and make a release on every tag
91- if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
70+ permissions :
71+ contents : read
72+ packages : write
73+
9274 steps :
93- - uses : actions/download-artifact@v2
75+ - name : Checkout
76+ uses : actions/checkout@v2
77+ with :
78+ fetch-depth : 0
79+
80+ - name : Log in to GitHub Docker Registry
81+ if : github.event_name != 'pull_request'
82+ uses : docker/login-action@v2
83+ with :
84+ registry : ghcr.io
85+ username : ${{ github.actor }}
86+ password : ${{ secrets.GITHUB_TOKEN }}
87+
88+ - name : Docker meta
89+ id : meta
90+ uses : docker/metadata-action@v4
91+ with :
92+ images : ghcr.io/${{ github.repository }}
93+ tags : |
94+ type=ref,event=branch
95+ type=ref,event=tag
96+
97+ - name : Set up Docker Buildx
98+ id : buildx
99+ uses : docker/setup-buildx-action@v2
100+
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/cov.xml .
114+
115+ - name : Upload coverage to Codecov
116+ uses : codecov/codecov-action@v3
117+ with :
118+ name : 3.10-locked/ubuntu-latest
119+ files : cov.xml
120+
121+ - name : Build runtime image
122+ uses : docker/build-push-action@v3
123+ with :
124+ push : ${{ github.event_name != 'pull_request' }}
125+ tags : ${{ steps.meta.outputs.tags }}
126+ context : .
127+ labels : ${{ steps.meta.outputs.labels }}
128+
129+ - name : Check runtime
130+ run : for i in ${{ steps.meta.outputs.tags }}; do docker run ${i} --version; done
131+
132+ - name : Upload build files
133+ uses : actions/upload-artifact@v3
94134 with :
95135 name : dist
96- path : dist
136+ path : dist/*
137+
138+ sdist :
139+ needs : container
140+ runs-on : ubuntu-latest
141+
142+ steps :
143+ - uses : actions/download-artifact@v3
144+
145+ - name : Install sdist in a venv and check cli works
146+ # ${GITHUB_REPOSITORY##*/} is the repo name without org
147+ # Replace this with the cli command if different to the repo name
148+ run : |
149+ pip install dist/*.gz
150+ ${GITHUB_REPOSITORY##*/} --version
151+
152+ release :
153+ # upload to PyPI and make a release on every tag
154+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
155+ needs : container
156+ runs-on : ubuntu-latest
157+
158+ steps :
159+ - uses : actions/download-artifact@v3
97160
98161 - name : Github Release
99162 # We pin to the SHA, not the tag, for security reasons.
100163 # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
101- uses : softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
164+ uses : softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
102165 with :
103- files : dist/*
166+ prerelease : ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
167+ files : |
168+ dist/*
104169 generate_release_notes : true
105170 env :
106171 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
107172
108173 - name : Publish to PyPI
109174 env :
110175 TWINE_USERNAME : __token__
111- TWINE_PASSWORD : ${{ secrets.pypi_token }}
112- run : pipx run twine upload dist/*
176+ TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
177+ run : pipx run twine upload dist/*/whl dist/*.tar.gz
0 commit comments