Skip to content

Commit 853075e

Browse files
committed
Refactor Python GitHub Actions workflow
Simplify and reorganize the CI workflow: normalize tag pattern quoting and narrow pull_request branches/types. Add permissions.contents=read. Rename the main job to a test_matrix job that runs a Python matrix, streamline setup and pip installs, remove verbose cache steps (use setup-python cache option), and simplify build/twine checks and wheel smoke test (only imports the package; CLI smoke test removed). Add a separate build_release job (runs on tag pushes) to build distributions and upload them as artifacts. Update publish job to download artifacts, install twine, and upload to PyPI using non-interactive --skip-existing; make publish depend on build_release.
1 parent 6e59a94 commit 853075e

1 file changed

Lines changed: 53 additions & 48 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ name: Build, validate & Release
33
on:
44
push:
55
tags:
6-
- 'v*.*.*'
6+
- "v*.*.*"
77
pull_request:
8-
branches: [ main, master ]
9-
types: [ labeled, opened, edited, synchronize, reopened ]
8+
branches: [main, master]
9+
types: [opened, edited, synchronize, reopened]
10+
11+
permissions:
12+
contents: read
1013

1114
jobs:
12-
build_check:
13-
name: Build & validate package
15+
test_matrix:
16+
name: Test install & smoke (Py ${{ matrix.python-version }})
1417
runs-on: ubuntu-latest
1518
strategy:
1619
fail-fast: false
1720
matrix:
18-
python-version: [ "3.10", "3.11", "3.12" ] # adjust to what you support
21+
python-version: ["3.10", "3.11", "3.12"]
1922
steps:
20-
- name: Checkout
21-
uses: actions/checkout@v6
22-
23-
- name: Setup Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v6
23+
- uses: actions/checkout@v6
24+
- uses: actions/setup-python@v6
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

@@ -39,65 +39,70 @@ jobs:
3939
run: |
4040
python -m pip install --upgrade pip
4141
python -m pip install build twine wheel "packaging>=24.2"
42+
cache: pip
4243
43-
- name: Build distributions (sdist + wheel)
44+
- name: Build (for validation only)
4445
run: python -m build
4546

46-
- name: Inspect dist
47-
run: |
48-
ls -lah dist/
49-
echo "sdist contents (first ~200 entries):"
50-
tar -tf dist/*.tar.gz | sed -n '1,200p'
51-
52-
- name: Twine metadata & README check
47+
- name: Twine check
5348
run: python -m twine check dist/*
5449

5550
- name: Install from wheel & smoke test
5651
run: |
57-
# Install from the built wheel (not from the source tree)
5852
python -m pip install dist/*.whl
59-
6053
python - <<'PY'
6154
import importlib
62-
pkg_name = "dlclivegui" # change if your top-level import differs
63-
m = importlib.import_module(pkg_name)
64-
print("Imported:", m.__name__, "version:", getattr(m, "__version__", "n/a"))
55+
m = importlib.import_module("dlclivegui")
56+
print("Imported:", m.__name__)
6557
PY
6658
67-
if ! command -v dlclivegui >/dev/null 2>&1; then
68-
echo "CLI entry point 'dlclivegui' not found in PATH; skipping CLI smoke test."
69-
else
70-
echo "Running 'dlclivegui --help' smoke test..."
71-
if ! dlclivegui --help >/dev/null 2>&1; then
72-
echo "::error::'dlclivegui --help' failed; this indicates a problem with the installed CLI package."
73-
exit 1
74-
fi
75-
fi
59+
build_release:
60+
name: Build release artifacts
61+
runs-on: ubuntu-latest
62+
needs: test_matrix
63+
if: startsWith(github.ref, 'refs/tags/v')
64+
steps:
65+
- uses: actions/checkout@v6
66+
- uses: actions/setup-python@v6
67+
with:
68+
python-version: "3.12"
69+
70+
- name: Install build tools
71+
run: python -m pip install -U pip build twine
72+
73+
- name: Build distributions
74+
run: python -m build
75+
76+
- name: Twine check
77+
run: python -m twine check dist/*
78+
79+
- name: Upload dist artifacts
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: dist
83+
path: dist/*
7684

7785
publish:
78-
name: Publish to PyPI
86+
name: Publish to PyPI (API token)
7987
runs-on: ubuntu-latest
80-
needs: build_check
81-
if: ${{ startsWith(github.ref, 'refs/tags/v') }} # only on tag pushes like v1.2.3
88+
needs: build_release
89+
if: startsWith(github.ref, 'refs/tags/v')
8290
steps:
83-
- name: Checkout
84-
uses: actions/checkout@v6
91+
- name: Download dist artifacts
92+
uses: actions/download-artifact@v4
93+
with:
94+
name: dist
95+
path: dist
8596

86-
- name: Setup Python
87-
uses: actions/setup-python@v6
97+
- uses: actions/setup-python@v6
8898
with:
8999
python-version: "3.x"
90100

91-
- name: Install build tools
92-
run: |
93-
python -m pip install --upgrade pip
94-
python -m pip install build twine
95-
96-
- name: Build distributions (sdist + wheel)
97-
run: python -m build
101+
- name: Install Twine
102+
run: python -m pip install -U twine
98103

99104
- name: Publish to PyPI
100105
env:
101106
TWINE_USERNAME: __token__
102107
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
103-
run: python -m twine upload --verbose dist/*
108+
run: python -m twine upload --non-interactive --verbose --skip-existing dist/*

0 commit comments

Comments
 (0)