Skip to content

Commit

Permalink
Fix: separate build and publish steps in CI (#145)
Browse files Browse the repository at this point in the history
* Fix: separate build and publish steps in CI

* Fix: align upload and download artifact version
  • Loading branch information
lwasser authored Mar 26, 2024
1 parent a76ba97 commit 728d2a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
43 changes: 28 additions & 15 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ on:
branches:
- main
jobs:
build-publish:
# setup build separate from publish
# See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093
build:
runs-on: ubuntu-latest
# This ensures that the publish action only runs in the main repository
# rather than forks
# Environment is encouraged so adding
environment: release
if: github.repository_owner == 'pyopensci'
permissions:
id-token: write # this permission is mandatory for pypi publishing
environment: build
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -42,17 +41,31 @@ jobs:
echo ""
echo "Generated files:"
ls -lh dist/
- name: Publish package on test PyPI on merge in main branch
# Test push to test pypi on merge to main
if: github.event_name == 'push'
uses: pypa/gh-action-pypi-publish@release/v1
# Store an artifact of the build to use in the publish step below
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
repository-url: https://test.pypi.org/legacy/
# Allow existing releases on test PyPI without errors.
# NOT TO BE USED in PyPI!
skip-existing: true

name: python-package-distributions
path: dist/
publish:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: github.repository_owner == 'pyopensci'
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pyosmeta
permissions:
id-token: write # this permission is mandatory for pypi publishing
steps:
# Version 4 doesn't support github enterprise yet
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package to PyPI
# Only publish to real PyPI on release
if: github.event_name == 'release'
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- Add: support for partners and emeritus_editor in contributor model (@lwasser, #133)
- Fix: Refactor all contributor GitHub related methods into gh_client module from contributors module (@lwasser, #125)
- Fix: Add support for pagination in github issue requests (@lwasser, #139)
- Fix: update ci workflow versions (@willingc, #113)
- Fix: separate build from publish steps for added security in pypi publish workflow (@lwasser, #113)


## [v0.2.3] - 2024-02-29
Expand Down

0 comments on commit 728d2a0

Please sign in to comment.