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

Commit 541f176

Browse files
committed
changes from PR review
1 parent c2db66d commit 541f176

File tree

4 files changed

+81
-33
lines changed

4 files changed

+81
-33
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "install requirements"
2+
description: "run pip install with requirements and upload resulting requirements"
3+
inputs:
4+
requirements_file:
5+
description: "name of requirements file to use and upload"
6+
required: true
7+
install_options:
8+
description: "parameters to pass to pip install"
9+
required: true
10+
python_version:
11+
description: "python version to install"
12+
default: "3.x"
13+
14+
runs:
15+
using: "composite"
16+
17+
steps:
18+
- name: Setup python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ inputs.python_version }}
22+
23+
- name: Pip Install
24+
run: |
25+
touch ${{ inputs.requirements_file }}
26+
# -c uses requirements.txt as constraints, see 'Validate requirements file'
27+
pip install -c ${{ inputs.requirements_file }} ${{ inputs.install_options }}
28+
shell: bash
29+
30+
- name: Create Lockfile
31+
run: |
32+
mkdir -p lockfiles
33+
pip freeze --exclude-editable > lockfiles/${{ inputs.requirements_file }}
34+
# delete the self referencing line
35+
sed -i '/file:/d' lockfiles/${{ inputs.requirements_file }}
36+
shell: bash
37+
38+
# This eliminates the class of problems where the requirements being given no
39+
# longer match what the packages themselves dictate. E.g. In the rare instance
40+
# where I install some-package which used to depend on vulnerable-dependency
41+
# but now uses good-dependency (despite being nominally the same version)
42+
# pip will install both if given a requirements file with -r
43+
- name: Validate requirements file
44+
run: if [ -s ${{ inputs.requirements_file }} ] ; then
45+
diff ${{ inputs.requirements_file }} lockfiles/${{ inputs.requirements_file }};
46+
echo "requirements files match";
47+
fi
48+
shell: bash
49+
50+
- name: Upload lockfiles
51+
uses: actions/upload-artifact@v3
52+
with:
53+
name: lockfiles
54+
path: lockfiles

.github/workflows/code.yml

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v3
1919

20-
- name: Setup python
21-
uses: actions/setup-python@v4
20+
- name: Install
21+
uses: ./.github/actions/install_requirements
2222
with:
23-
python-version: "3.x"
23+
requirements_file: requirements-lint.txt
24+
install_options: -e .[dev]
2425

2526
- name: Lint
26-
run: |
27-
.github/workflows/pip_install.sh lint -e .[dev]
28-
tox -e pre-commit,mypy
27+
run: tox -e pre-commit,mypy
2928

3029
- name: Upload lockfiles
3130
uses: actions/upload-artifact@v3
@@ -40,6 +39,12 @@ jobs:
4039
matrix:
4140
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
4241
python: ["3.8", "3.9", "3.10", "3.11"]
42+
install: ["-e .[dev]"]
43+
# Make one version be non-editable to test both paths of version code
44+
include:
45+
- os: "ubuntu-latest"
46+
python: "3.8"
47+
install: ".[dev]"
4348

4449
runs-on: ${{ matrix.os }}
4550
env:
@@ -52,13 +57,12 @@ jobs:
5257
with:
5358
fetch-depth: 0
5459

55-
- name: Setup python ${{ matrix.python }}
56-
uses: actions/setup-python@v4
60+
- name: Install
61+
uses: ./.github/actions/install_requirements
5762
with:
58-
python-version: ${{ matrix.python }}
59-
60-
- name: Install with latest dependencies
61-
run: .github/workflows/pip_install.sh test-${{ matrix.python }}-${{ matrix.os }} .[dev]
63+
python_version: ${{ matrix.python }}
64+
requirements_file: requirements-test-${{ matrix.os }}-${{ matrix.python }}.txt
65+
install_options: ${{ matrix.install }}
6266

6367
- name: Run tests
6468
run: pytest tests
@@ -69,12 +73,6 @@ jobs:
6973
name: ${{ matrix.python }}/${{ matrix.os }}
7074
files: cov.xml
7175

72-
- name: Upload lockfiles
73-
uses: actions/upload-artifact@v3
74-
with:
75-
name: lockfiles
76-
path: lockfiles
77-
7876
dist:
7977
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
8078
runs-on: "ubuntu-latest"
@@ -119,8 +117,8 @@ jobs:
119117
uses: actions/checkout@v3
120118

121119
# image names must be all lower case
122-
- run: |
123-
echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
120+
- name: Generate image repo name
121+
run: echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
124122

125123
# obtain the python wheel from the dist step
126124
- uses: actions/download-artifact@v3
@@ -157,11 +155,11 @@ jobs:
157155
cache-to: type=gha,mode=max
158156

159157
- name: Test cli works in runtime image
160-
# check that the latest tag can run with --version parameter
161158
run: |
162159
docker run ${{ env.IMAGE_REPOSITORY }} --version
163160
mkdir -p lockfiles
164-
docker run --entrypoint pip ${{ env.IMAGE_REPOSITORY }} freeze > lockfiles/requirements.txt
161+
docker run --entrypoint pip ${{ env.IMAGE_REPOSITORY }} freeze | \
162+
sed '/file:/s/^/# Requirements for /' > lockfiles/requirements.txt
165163
166164
- name: Upload lockfiles
167165
uses: actions/upload-artifact@v3
@@ -178,10 +176,6 @@ jobs:
178176
steps:
179177
- uses: actions/download-artifact@v3
180178

181-
- name: fixup requirements files
182-
# use sed to comment out the self references in requirements files
183-
run: sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements*.txt
184-
185179
- name: Github Release
186180
# We pin to the SHA, not the tag, for security reasons.
187181
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions

.github/workflows/pip_install.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
# usage: install_with_requirements.sh suffix [remaining parameters to pip install]
88

9-
suffix=$1
9+
requirements_file=$1
1010
shift
1111

12-
touch requirements-${suffix}.txt
13-
pip install -r requirements-${suffix}.txt "${@}"
12+
touch ${requirements_file}
13+
pip install -r ${requirements_file} "${@}"
1414
mkdir -p lockfiles
15-
pip freeze --exclude-editable > lockfiles/requirements-${suffix}.txt
15+
# get a freeze of the installed packages but delete the self referencing line
16+
pip freeze --exclude-editable | sed '/file:/d' > lockfiles/${requirements_file}

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ FROM python:3.11 as build
88
# Add any system dependencies for the developer/build environment here e.g.
99
# RUN apt-get update && apt-get upgrade -y && \
1010
# apt-get install -y --no-install-recommends \
11-
# busybox \
12-
# && rm -rf /var/lib/apt/lists/* \
13-
# && busybox --install
11+
# desired-packages \
12+
# && rm -rf /var/lib/apt/lists/*
1413

1514
COPY . /project
1615
WORKDIR /project

0 commit comments

Comments
 (0)