Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: add trusted publisher #229

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ on:
- main
workflow_dispatch:

release:
types:
- published

permissions:
contents: read
# Needed for trusted publishing.
id-token: write

jobs:
pure-python-wheel-and-sdist:
name: Build a pure Python wheel and source distribution
Expand All @@ -21,20 +30,32 @@ jobs:
# Fetch all tags; this is needed for hatch-vcs
fetch-depth: 0

- name: Install build dependencies
run: python -m pip install --upgrade build
- uses: hynek/build-and-inspect-python-package@v1

# Upload to Test PyPI on every commit on main.
publish-test-release:
name: Publish in-dev package to test.pypi.org
environment: publish-test-release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- pure-python-wheel-and-sdist

- name: Build
run: python -m build
steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
with:
name: Packages
path: dist

- uses: actions/upload-artifact@v3
- name: Upload package to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
name: artifacts
path: dist/*
if-no-files-found: error
repository-url: https://test.pypi.org/legacy/

publish:
publish-release:
name: Publish release
environment: publish-release
needs:
- pure-python-wheel-and-sdist
runs-on: ubuntu-latest
Expand All @@ -43,13 +64,13 @@ jobs:
(github.event_name == 'workflow_dispatch' && startsWith(github.event.ref, 'refs/tags'))

steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
name: artifacts
path: dist

- name: Push build artifacts to PyPI
uses: pypa/gh-action-pypi-publish@v1.4.2
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip_existing: true
user: __token__
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Issues = "https://github.com/hamcrest/PyHamcrest/issues"

[tool.hatch.version]
source = "vcs"
raw_options = { local_scheme = "no-local-version" }

[tool.hatch.build.hooks.vcs]
version-file = "src/hamcrest/_version.py"
Expand Down