Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit eb1f2f3

Browse files
authored
Merge pull request #35 from DiamondLightSource/test-lockfiles
Multiple fixes.
2 parents 26e752f + fd24dde commit eb1f2f3

File tree

12 files changed

+82
-51
lines changed

12 files changed

+82
-51
lines changed

.containerignore renamed to .dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Dockerfile
21
build/
32
dist/
43
.mypy_cache

.github/pages/make_switcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_versions(ref: str, add: Optional[str], remove: Optional[str]) -> List[st
5959
def write_json(path: Path, repository: str, versions: str):
6060
org, repo_name = repository.split("/")
6161
struct = [
62-
dict(name=version, url=f"https://{org}.github.io/{repo_name}/{version}/")
62+
dict(version=version, url=f"https://{org}.github.io/{repo_name}/{version}/")
6363
for version in versions
6464
]
6565
text = json.dumps(struct, indent=2)

.github/workflows/code.yml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ jobs:
115115
run: |
116116
docker run --name test build bash /project/.github/workflows/container_tests.sh
117117
docker cp test:/project/dist .
118+
docker cp test:/project/lockfiles .
118119
docker cp test:/project/cov.xml .
119120
120121
- name: Upload coverage to Codecov
@@ -131,30 +132,27 @@ jobs:
131132
context: .
132133
labels: ${{ steps.meta.outputs.labels }}
133134

134-
- name: Check runtime
135+
- name: Test cli works in runtime image
135136
# check that the first tag can run with --version parameter
136-
run: docker run $(echo ${{ steps.meta.outputs.tags }} | sed -e 's/\s.*$//') --version
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
137144

138145
- name: Upload build files
139146
uses: actions/upload-artifact@v3
140147
with:
141148
name: dist
142149
path: dist
143150

144-
sdist:
145-
needs: container
146-
runs-on: ubuntu-latest
147-
148-
steps:
149-
- uses: actions/download-artifact@v3
150-
151-
- name: Install sdist in a venv and check cli works
152-
# ${GITHUB_REPOSITORY##*/} is the repo name without org
153-
# Replace this with the cli command if different to the repo name
154-
# (In the python3-pip-skeleton-cli this is already renamed)
155-
run: |
156-
pip install dist/*.gz
157-
python3-pip-skeleton --version
151+
- name: Upload lock files
152+
uses: actions/upload-artifact@v3
153+
with:
154+
name: lockfiles
155+
path: lockfiles
158156

159157
release:
160158
# upload to PyPI and make a release on every tag
@@ -171,13 +169,14 @@ jobs:
171169
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
172170
with:
173171
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
174-
files: dist/*
172+
files: |
173+
dist/
174+
lockfiles/
175175
generate_release_notes: true
176176
env:
177177
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
178178

179179
- name: Publish to PyPI
180-
env:
181-
TWINE_USERNAME: __token__
182-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
183-
run: pipx run twine upload dist/*.whl dist/*.tar.gz
180+
uses: pypa/gh-action-pypi-publish@release/v1
181+
with:
182+
password: ${{ secrets.PYPI_TOKEN }}

.github/workflows/container_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ source /venv/bin/activate
66

77
touch requirements_dev.txt
88
pip install -r requirements_dev.txt -e .[dev]
9-
pip freeze --exclude-editable > dist/requirements_dev.txt
9+
mkdir -p lockfiles
10+
pip freeze --exclude-editable > lockfiles/requirements_dev.txt
1011

1112
pipdeptree
1213

.github/workflows/docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ jobs:
4141
- name: Build docs
4242
run: tox -e docs
4343

44+
- name: Sanitize ref name for docs version
45+
run: echo "DOCS_VERSION=${GITHUB_REF_NAME//[^A-Za-z0-9._-]/_}" >> $GITHUB_ENV
46+
4447
- name: Move to versioned directory
45-
# e.g. main or 0.1.2
46-
run: mv build/html ".github/pages/${{ github.ref_name }}"
48+
run: mv build/html .github/pages/$DOCS_VERSION
4749

4850
- name: Write switcher.json
49-
run: python .github/pages/make_switcher.py --add "${{ github.ref_name }}" ${{ github.repository }} .github/pages/switcher.json
51+
run: python .github/pages/make_switcher.py --add $DOCS_VERSION ${{ github.repository }} .github/pages/switcher.json
5052

5153
- name: Publish Docs to gh-pages
5254
if: github.event_name == 'push'

.github/workflows/docs_clean.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ jobs:
2424

2525
- name: removing documentation for branch ${{ github.event.ref }}
2626
if: ${{ github.event_name != 'workflow_dispatch' }}
27-
run: echo "remove_me=${{ github.event.ref }}" >> $GITHUB_ENV
27+
run: echo "REF_NAME=${{ github.event.ref }}" >> $GITHUB_ENV
2828

2929
- name: manually removing documentation version ${{ github.event.inputs.version }}
3030
if: ${{ github.event_name == 'workflow_dispatch' }}
31-
run: echo "remove_me=${{ github.event.inputs.version }}" >> $GITHUB_ENV
31+
run: echo "REF_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
32+
33+
- name: Sanitize ref name for docs version
34+
run: echo "DOCS_VERSION=${REF_NAME//[^A-Za-z0-9._-]/_}" >> $GITHUB_ENV
3235

3336
- name: update index and push changes
3437
run: |
35-
rm -r ${{ env.remove_me }}
36-
python make_switcher.py --remove ${{ env.remove_me }} ${{ github.repository }} switcher.json
38+
rm -r ${{ env.DOCS_VERSION }}
39+
python make_switcher.py --remove $DOCS_VERSION ${{ github.repository }} switcher.json
3740
git config --global user.name 'GitHub Actions Docs Cleanup CI'
3841
git config --global user.email '[email protected]'
39-
git commit -am"removing redundant docs version ${{ env.remove_me }}"
42+
git commit -am "Removing redundant docs version $DOCS_VERSION"
4043
git push

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ target/
6464
.venv*
6565
venv*
6666

67+
# further build artifacts
68+
lockfiles/
6769

Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,34 @@ RUN apt-get update && apt-get upgrade -y && \
1818
&& busybox --install
1919

2020
COPY . /project
21+
WORKDIR /project
2122

22-
RUN cd /project && \
23-
pip install --upgrade pip build && \
23+
# make the wheel outside of the venv so 'build' does not dirty requirements.txt
24+
RUN pip install --upgrade pip build && \
2425
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
25-
python -m build --sdist --wheel && \
26+
git diff && \
27+
python -m build && \
2628
touch requirements.txt
2729

30+
# set up a virtual environment and put it in PATH
2831
RUN python -m venv /venv
2932
ENV PATH=/venv/bin:$PATH
3033
ENV TOX_DIRECT=1
3134

32-
RUN cd /project && \
33-
pip install --upgrade pip && \
35+
# install the wheel and generate the requirements file
36+
RUN pip install --upgrade pip && \
3437
pip install -r requirements.txt dist/*.whl && \
35-
pip freeze > dist/requirements.txt && \
38+
mkdir -p lockfiles && \
39+
pip freeze > lockfiles/requirements.txt && \
3640
# we don't want to include our own wheel in requirements - remove with sed
3741
# and replace with a comment to avoid a zero length asset upload later
38-
sed -i '/file:/s/^/# Requirements for /' dist/requirements.txt
42+
sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements.txt
3943

4044
FROM python:3.10-slim as runtime
4145

4246
# Add apt-get system dependecies for runtime here if needed
4347

48+
# copy the virtual environment from the build stage and put it in PATH
4449
COPY --from=build /venv/ /venv/
4550
ENV PATH=/venv/bin:$PATH
4651

README.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ It integrates the following tools:
2626
- which verifies all the things that CI does
2727
- If you use VSCode, it will run black, flake8, isort and mypy on save
2828

29-
The the related skeleton_ repo for this module contains the source
30-
code that can be merged into new or existing projects, and pulled from to
31-
keep them up to date. It can also serve as a working example for those who
29+
The the related skeleton_ repo for this module contains the source
30+
code that can be merged into new or existing projects, and pulled from to
31+
keep them up to date. It can also serve as a working example for those who
3232
would prefer to cherry-pick.
3333

3434
.. _skeleton: https://github.com/DiamondLightSource/python3-pip-skeleton
@@ -43,12 +43,12 @@ and existing projects::
4343

4444
python3-pip-skeleton existing /path/to/existing/repo --org my_github_user_or_org
4545

46-
.. |code_ci| image:: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/workflows/Code%20CI/badge.svg?branch=main
47-
:target: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/actions?query=workflow%3A%22Code+CI%22
46+
.. |code_ci| image:: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/actions/workflows/code.yml/badge.svg?branch=main
47+
:target: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/actions/workflows/code.yml
4848
:alt: Code CI
4949

50-
.. |docs_ci| image:: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/workflows/Docs%20CI/badge.svg?branch=main
51-
:target: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/actions?query=workflow%3A%22Docs+CI%22
50+
.. |docs_ci| image:: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/actions/workflows/docs.yml/badge.svg?branch=main
51+
:target: https://github.com/DiamondLightSource/python3-pip-skeleton-cli/actions/workflows/docs.yml
5252
:alt: Docs CI
5353

5454
.. |coverage| image:: https://codecov.io/gh/DiamondLightSource/python3-pip-skeleton-cli/branch/main/graph/badge.svg

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
git_branch = check_output("git branch --show-current".split(), cwd=root)
2525
version = git_branch.decode().strip()
2626
else:
27-
branch = "main"
2827
version = release
2928

3029
extensions = [

0 commit comments

Comments
 (0)