Skip to content

Commit 50f1ccd

Browse files
committed
Modernize release GitHub Actions workflow
Add explicit permissions (id-token: write, contents: read) and restructure steps for clarity. Replace legacy pip-based build/publish (setuptools/wheel/twine) with python -m build and the pypa/gh-action-pypi-publish action, and add a dedicated Build step. Preserve the existing version-bump check logic and only run publish/release steps when the package version has changed. Overall changes improve security and simplify publishing.
1 parent 4973933 commit 50f1ccd

1 file changed

Lines changed: 51 additions & 43 deletions

File tree

.github/workflows/release.yml

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,55 @@ on:
99
jobs:
1010
deploy:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write # needed for Trusted Publishing
14+
contents: read
15+
1216
steps:
13-
- uses: actions/checkout@v4
14-
- name: Check version bump
15-
id: version_check
16-
run: |
17-
NEW_VERSION=$(python -c "import re; print(re.search(r\"version='([^']+)'\", open('setup.py').read()).group(1))")
18-
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
19-
pip install ecell4 2>/dev/null && \
20-
CURRENT_VERSION=$(pip show ecell4 | grep ^Version | awk '{print $2}') || \
21-
CURRENT_VERSION="0.0.0"
22-
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
23-
echo "changed=false" >> "$GITHUB_OUTPUT"
24-
else
25-
echo "changed=true" >> "$GITHUB_OUTPUT"
26-
fi
27-
- name: Set up Python
28-
if: steps.version_check.outputs.changed == 'true'
29-
uses: actions/setup-python@v5
30-
with:
31-
python-version: '3.x'
32-
- name: Install dependencies
33-
if: steps.version_check.outputs.changed == 'true'
34-
run: |
35-
python -m pip install --upgrade pip
36-
pip install setuptools wheel twine
37-
- name: Build and publish to PyPI
38-
if: steps.version_check.outputs.changed == 'true'
39-
env:
40-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
41-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
42-
run: |
43-
python setup.py sdist bdist_wheel
44-
twine upload dist/*
45-
- name: Create GitHub Release
46-
if: steps.version_check.outputs.changed == 'true'
47-
env:
48-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
run: |
50-
VERSION=${{ steps.version_check.outputs.version }}
51-
git tag "v${VERSION}"
52-
git push origin "v${VERSION}"
53-
gh release create "v${VERSION}" dist/* \
54-
--title "v${VERSION}" \
55-
--generate-notes
17+
- uses: actions/checkout@v4
18+
19+
- name: Check version bump
20+
id: version_check
21+
run: |
22+
NEW_VERSION=$(python -c "import re; print(re.search(r\"version='([^']+)'\", open('setup.py').read()).group(1))")
23+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
24+
pip install ecell4 2>/dev/null && \
25+
CURRENT_VERSION=$(pip show ecell4 | grep ^Version | awk '{print $2}') || \
26+
CURRENT_VERSION="0.0.0"
27+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
28+
echo "changed=false" >> "$GITHUB_OUTPUT"
29+
else
30+
echo "changed=true" >> "$GITHUB_OUTPUT"
31+
fi
32+
33+
- name: Set up Python
34+
if: steps.version_check.outputs.changed == 'true'
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.x'
38+
39+
- name: Install build tooling
40+
if: steps.version_check.outputs.changed == 'true'
41+
run: |
42+
python -m pip install --upgrade pip
43+
pip install build
44+
45+
- name: Build
46+
if: steps.version_check.outputs.changed == 'true'
47+
run: python -m build
48+
49+
- name: Publish to PyPI
50+
if: steps.version_check.outputs.changed == 'true'
51+
uses: pypa/gh-action-pypi-publish@release/v1
52+
53+
- name: Create GitHub Release
54+
if: steps.version_check.outputs.changed == 'true'
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
run: |
58+
VERSION=${{ steps.version_check.outputs.version }}
59+
git tag "v${VERSION}"
60+
git push origin "v${VERSION}"
61+
gh release create "v${VERSION}" dist/* \
62+
--title "v${VERSION}" \
63+
--generate-notes

0 commit comments

Comments
 (0)