Skip to content

Commit 1e1a91f

Browse files
authored
Merge pull request #51 from zapta/main
Added a shared workflow action to uninstall all of pip packages.
2 parents 3c29791 + fb71a23 commit 1e1a91f

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# File: .github/actions/uninstall-all-pip-packages/action.yml
2+
name: 'Uninstall All Pip Packages'
3+
description: 'Completely uninstalls all pip packages in the current Python environment, including editable (-e) installations. Includes verification that the environment is clean afterward.'
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Uninstall all pip packages
8+
shell: bash
9+
run: |
10+
#!/bin/bash
11+
set -euo pipefail
12+
13+
echo "Listing installed packages before uninstallation..."
14+
pip freeze
15+
16+
# Extract package names:
17+
# - For editable installs: capture the egg name (e.g., 'apio' from #egg=apio)
18+
# - For normal installs: strip the version part
19+
# - sort -u removes potential duplicates
20+
package_list=$(pip freeze \
21+
| sed -E 's/^-e .*#egg=([^-]+).*/\1/; s/==.*$//' \
22+
| sort -u)
23+
24+
if [ -z "$package_list" ]; then
25+
echo "No packages found to uninstall."
26+
else
27+
echo "Uninstalling the following packages:"
28+
echo "$package_list"
29+
# Use process substitution to feed the list as a "requirements file"
30+
pip uninstall -y -r <(echo "$package_list")
31+
fi
32+
33+
echo "Verifying that no packages remain..."
34+
output=$(pip freeze)
35+
36+
if [ -z "$output" ]; then
37+
echo "Assertion passed: pip freeze is empty. All packages successfully uninstalled."
38+
else
39+
echo "Assertion failed: Remaining packages detected:"
40+
echo "$output"
41+
exit 1
42+
fi

.github/workflows/test.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,67 @@ jobs:
400400
fi
401401
402402
echo "Scan outcome correct: $ACTUAL_OUTCOME (expected $EXPECTED_OUTCOME)."
403+
404+
# -- Test action uninstall-all-pip-packages
405+
test-uninstall-all-pip-packages:
406+
runs-on: ubuntu-latest
407+
408+
steps:
409+
- name: Checkout this repo
410+
uses: actions/checkout@v4
411+
412+
- name: Check the apio repo
413+
uses: actions/checkout@v4
414+
with:
415+
repository: fpgawars/apio
416+
path: apio-repo
417+
418+
# If using the system's python, we can't delete all the packages
419+
# because of permissions. This is why we install our own version.
420+
- name: Install python 3.14
421+
uses: actions/setup-python@v5
422+
with:
423+
python-version: 3.14
424+
425+
- name: Install apio as a pip package
426+
run: pip install -e apio-repo
427+
428+
- name: Verify some pip packages installed.
429+
run: |
430+
output=$(pip freeze)
431+
echo "pip freeze: ${output}"
432+
if [ -z "$output" ]; then
433+
echo "Assertion failed: No packages detected (pip freeze is empty)."
434+
exit 1
435+
fi
436+
- name: Verify apio package installed.
437+
run: |
438+
pip show apio
439+
440+
- name: Verify apio is alive
441+
run: |
442+
apio --version
443+
444+
- name: Uninstall all pip packages
445+
uses: ./.github/actions/uninstall-all-pip-packages
446+
447+
- name: Check no packages.
448+
run: |
449+
output=$(pip freeze)
450+
if [ -n "$output" ]; then
451+
echo "Assertion failed: Remaining packages detected:"
452+
echo "$output"
453+
exit 1
454+
fi
455+
456+
- name: Try to run apio (should fail)
457+
id: run-apio
458+
continue-on-error: true
459+
run: |
460+
apio --version
461+
462+
- name: Assert that previous step failed
463+
uses: ./.github/actions/assert-step-failed
464+
with:
465+
outcome: ${{ steps.run-apio.outcome }}
466+
error-message: "The previous step did not fail as expected"

0 commit comments

Comments
 (0)