-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathreusable-check-python-package-versions.yaml
More file actions
90 lines (76 loc) · 3.21 KB
/
reusable-check-python-package-versions.yaml
File metadata and controls
90 lines (76 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: "[REUSABLE] Check Python package versions"
on:
workflow_call:
inputs:
before_commit:
description: >-
The base Git commit to compare against, i.e., the base of the PR or the previous commit
in a push.
type: string
required: true
after_commit:
description: >-
The Git commit representing the head of the change to be checked, i.e. the head of the
PR or the latest commit in a push.
type: string
required: true
jobs:
get-index-url:
uses: ./.github/workflows/reusable-get-code-artifact-index-url.yaml
check-python-package-versions:
needs: get-index-url
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Check out code before change
uses: actions/checkout@v4
with:
ref: ${{ inputs.before_commit }}
- name: Sync code before change to make packages visible to Python
run: uv sync --all-packages
- name: Capture package versions before change
run: uv run python ./.github/workflows/scripts/package-versions.py collect > /tmp/package-versions-before.json
- name: Check out code after change
uses: actions/checkout@v6
with:
ref: ${{ inputs.after_commit }}
- name: Sync code after change to make packages visible to Python
run: uv sync --all-packages --refresh
- name: Capture package versions after change
run: uv run python ./.github/workflows/scripts/package-versions.py collect > /tmp/package-versions-after.json
- name: Compare package versions before and after change
run: |
uv run python ./.github/workflows/scripts/package-versions.py compare \
/tmp/package-versions-before.json \
/tmp/package-versions-after.json \
>/tmp/package-version-diff.json
- name: Print changed versions
run: cat /tmp/package-version-diff.json
- name: Fail if any of the new versions already exist in the repo
run: |
jq -c '.[]' /tmp/package-version-diff.json | while read -r entry; do
package=$(echo "$entry" | jq -r '.package')
after=$(echo "$entry" | jq -r '.after')
exit_code=0
output=$(uv run pip download "${package}==${after}" --index-url "${{ needs.get-index-url.outputs.index_url }}simple/" --no-deps -d /tmp --quiet 2>&1) || exit_code=$?
if [[ $exit_code -eq 0 || (
"${output,,}" != *"could not find a version"* &&
"${output,,}" != *"no matching distributions"*
) ]]; then
echo "Package ${package} version ${after} already exists in the repository. Failing the workflow."
echo " pip exit code: ${exit_code}."
echo " pip stderr: ${output}."
exit 1
else
echo "Package ${package} version ${after} is new, as expected. Continuing."
fi
done