Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pypa/gh-action-pypi-publish
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.8.5
Choose a base ref
...
head repository: pypa/gh-action-pypi-publish
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.8.6
Choose a head ref
  • 14 commits
  • 4 files changed
  • 5 contributors

Commits on Apr 3, 2023

  1. 📝 Link the announcement discussions from README

    This patch encourages the end-users to share feedback using GitHub
    Discussions instead of issues.
    webknjaz committed Apr 3, 2023
    Copy the full SHA
    82695c5 View commit details
  2. [pre-commit.ci] pre-commit autoupdate

    updates:
    - [github.com/Lucas-C/pre-commit-hooks.git: v1.3.1 → v1.5.1](https://github.com/Lucas-C/pre-commit-hooks.git/compare/v1.3.1...v1.5.1)
    - [github.com/python-jsonschema/check-jsonschema.git: 0.19.2 → 0.22.0](https://github.com/python-jsonschema/check-jsonschema.git/compare/0.19.2...0.22.0)
    - [github.com/codespell-project/codespell: v2.2.2 → v2.2.4](codespell-project/codespell@v2.2.2...v2.2.4)
    - [github.com/adrienverge/yamllint.git: v1.28.0 → v1.30.0](https://github.com/adrienverge/yamllint.git/compare/v1.28.0...v1.30.0)
    - [github.com/PyCQA/flake8.git: 4.0.1 → 6.0.0](https://github.com/PyCQA/flake8.git/compare/4.0.1...6.0.0)
    - [github.com/PyCQA/pylint.git: v2.15.9 → v3.0.0a6](https://github.com/PyCQA/pylint.git/compare/v2.15.9...v3.0.0a6)
    pre-commit-ci[bot] authored Apr 3, 2023
    Copy the full SHA
    6cbdb54 View commit details
  3. Copy the full SHA
    ba70453 View commit details

Commits on Apr 4, 2023

  1. Merge pull request #145 from pypa/pre-commit-ci-update-config

    [pre-commit.ci] pre-commit autoupdate
    webknjaz authored Apr 4, 2023
    Copy the full SHA
    f437f57 View commit details
  2. Copy the full SHA
    c542b72 View commit details

Commits on Apr 21, 2023

  1. README, oidc-exchange: remove beta references

    Signed-off-by: William Woodruff <william@trailofbits.com>
    woodruffw committed Apr 21, 2023
    Copy the full SHA
    fe431ff View commit details

Commits on Apr 22, 2023

  1. README: re-add OIDC note

    Signed-off-by: William Woodruff <william@trailofbits.com>
    woodruffw committed Apr 22, 2023
    Copy the full SHA
    c008c2f View commit details

Commits on Apr 23, 2023

  1. Merge pull request #147 from trail-of-forks/tob-stabilize-oidc

    README, oidc-exchange: remove beta references
    webknjaz authored Apr 23, 2023
    Copy the full SHA
    3b6670b View commit details

Commits on Apr 24, 2023

  1. 🎨 Show GH environments use in README examples

    It is a useful protection feature giving the end-users more control
    over the release flow and trust.
    webknjaz committed Apr 24, 2023
    Copy the full SHA
    7a1a355 View commit details
  2. 📝🎨 Put OIDC on pedestal @ README

    This patch makes sure that the new users would go for the secretless
    publishing when integrating the action, from the beginning.
    webknjaz committed Apr 24, 2023
    2
    Copy the full SHA
    f47b347 View commit details
  3. README: small doc tweaks

    Signed-off-by: William Woodruff <william@trailofbits.com>
    woodruffw committed Apr 24, 2023
    Copy the full SHA
    0811f99 View commit details

Commits on Apr 25, 2023

  1. Copy the full SHA
    5a085bf View commit details

Commits on Apr 27, 2023

  1. password input is no longer required, since not specifying it implies…

    … trusted publishing
    
    Signed-off-by: Asher Foa <1268088+asherf@users.noreply.github.com>
    asherf committed Apr 27, 2023
    Copy the full SHA
    e4b9031 View commit details

Commits on May 2, 2023

  1. Copy the full SHA
    a56da0b View commit details
Showing with 56 additions and 60 deletions.
  1. +7 −8 .pre-commit-config.yaml
  2. +47 −50 README.md
  3. +1 −1 action.yml
  4. +1 −1 oidc-exchange.py
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
ci:
autoupdate_schedule: quarterly
default_language_version: python3.11

repos:
- repo: https://github.com/asottile/add-trailing-comma.git
@@ -16,12 +17,12 @@ repos:
- --honor-noqa

- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.3.1
rev: v1.5.1
hooks:
- id: remove-tabs

- repo: https://github.com/python-jsonschema/check-jsonschema.git
rev: 0.19.2
rev: 0.22.0
hooks:
- id: check-github-actions
- id: check-github-workflows
@@ -61,12 +62,12 @@ repos:
language_version: python3

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.4
hooks:
- id: codespell

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.28.0
rev: v1.30.0
hooks:
- id: yamllint
files: \.(yaml|yml)$
@@ -94,7 +95,6 @@ repos:
additional_dependencies:
- flake8-2020 ~= 1.7.0
- flake8-pytest-style ~= 1.6.0
language_version: python3

- repo: https://github.com/PyCQA/flake8.git
# NOTE: This is kept at v4 for until WPS starts supporting flake v5.
@@ -127,11 +127,10 @@ repos:
- --select
- WPS
additional_dependencies:
- wemake-python-styleguide ~= 0.16.1
language_version: python3
- wemake-python-styleguide ~= 0.17.0

- repo: https://github.com/PyCQA/pylint.git
rev: v2.15.9
rev: v3.0.0a6
hooks:
- id: pylint
args:
97 changes: 47 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@ in the `dist/` directory to PyPI.
This text suggests a minimalistic usage overview. For more detailed
walkthrough check out the [PyPA guide].

If you have any feedback regarding specific action versions, please leave
comments in the corresponding [per-release announcement discussions].


## 🌇 `master` branch sunset ❗

@@ -20,59 +23,17 @@ tag, or a full Git commit SHA.

## Usage

To use the action add the following step to your workflow file (e.g.
`.github/workflows/main.yml`)


```yml
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
```
> **Pro tip**: instead of using branch pointers, like `unstable/v1`, pin
versions of Actions that you use to tagged versions or sha1 commit identifiers.
This will make your workflows more secure and better reproducible, saving you
from sudden and unpleasant surprises.

A common use case is to upload packages only on a tagged commit, to do so add a
filter to the step:


```yml
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
```

So the full step would look like:


```yml
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
```

The example above uses the new [API token][PyPI API token] feature of
PyPI, which is recommended to restrict the access the action has.

The secret used in `${{ secrets.PYPI_API_TOKEN }}` needs to be created on the
settings page of your project on GitHub. See [Creating & using secrets].


### Trusted publishing

> **IMPORTANT**: This functionality is in beta, and will not work for you
> unless you're a member of the PyPI trusted publishing beta testers' group.
> For more information, see [warehouse#12965].

> **NOTE**: Trusted publishing is sometimes referred to by its
> underlying technology -- OpenID Connect, or OIDC for short.
> If you see references to "OIDC publishing" in the context of PyPI,
> this is what they're referring to.
This example jumps right into the current best practice. If you want to
use API tokens directly or a less secure username and password, check out
[how to specify username and password].

This action supports PyPI's [trusted publishing]
implementation, which allows authentication to PyPI without a manually
configured API token or username/password combination. To perform
@@ -83,10 +44,14 @@ To enter the trusted publishing flow, configure this action's job with the
`id-token: write` permission and **without** an explicit username or password:

```yaml
# .github/workflows/ci-cd.yml
jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/<your-pypi-project-name>
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
@@ -96,6 +61,11 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
```
> **Pro tip**: instead of using branch pointers, like `unstable/v1`, pin
versions of Actions that you use to tagged versions or sha1 commit identifiers.
This will make your workflows more secure and better reproducible, saving you
from sudden and unpleasant surprises.

Other indices that support trusted publishing can also be used, like TestPyPI:

```yaml
@@ -104,13 +74,21 @@ Other indices that support trusted publishing can also be used, like TestPyPI:
with:
repository-url: https://test.pypi.org/legacy/
```
_(don't forget to update the environment name to `testpypi` or similar!)_

> **Pro tip**: only set the `id-token: write` permission in the job that does
> publishing, not globally. Also, try to separate building from publishing
> — this makes sure that any scripts maliciously injected into the build
> or test environment won't be able to elevate privileges while flying under
> the radar.

A common use case is to upload packages only on a tagged commit, to do so add a
filter to the job:

```yml
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
```


## Non-goals

@@ -146,7 +124,7 @@ by putting them into the `dist/` folder prior to running this Action.
For best results, figure out what kind of workflow fits your
project's specific needs.

For example, you could implement a parallel workflow that
For example, you could implement a parallel job that
pushes every commit to TestPyPI or your own index server,
like `devpi`. For this, you'd need to (1) specify a custom
`repository-url` value and (2) generate a unique version
@@ -155,8 +133,11 @@ The latter is possible if you use `setuptools_scm` package but
you could also invent your own solution based on the distance
to the latest tagged commit.

You'll need to create another token for a separate host and then
[save it as a GitHub repo secret][Creating & using secrets].
You'll need to create another token for a separate host and then [save it as a
GitHub repo secret][Creating & using secrets] under an environment used in
your job. Though, passing a password would disable the secretless [trusted
publishing] so it's better to configure it instead, when publishing to TestPyPI
and not something custom.

The action invocation in this case would look like:
```yml
@@ -177,7 +158,6 @@ would now look like:
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: custom-dir/
```

@@ -242,6 +222,18 @@ specify a custom username and password pair. This is how it's done.
password: ${{ secrets.DEVPI_PASSWORD }}
```

The secret used in `${{ secrets.DEVPI_PASSWORD }}` needs to be created on the
environment page under the settings of your project on GitHub.
See [Creating & using secrets].

In the past, when publishing to PyPI, the most secure way of the access scoping
for automatic publishing was to use the [API tokens][PyPI API token] feature of
PyPI. One would make it project-scoped and save as an environment-bound secret
in their GitHub repository settings, naming it `${{ secrets.PYPI_API_TOKEN }}`,
for example. See [Creating & using secrets]. While still secure,
[trusted publishing] is now encouraged over API tokens as a best practice
on supported platforms (like GitHub).

## License

The Dockerfile and associated scripts and documentation in this project
@@ -258,6 +250,9 @@ https://results.pre-commit.ci/latest/github/pypa/gh-action-pypi-publish/unstable
[pre-commit.ci status badge]:
https://results.pre-commit.ci/badge/github/pypa/gh-action-pypi-publish/unstable/v1.svg

[per-release announcement discussions]:
https://github.com/pypa/gh-action-pypi-publish/discussions/categories/announcements

[Creating & using secrets]:
https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
[has nothing to do with _building package distributions_]:
@@ -274,3 +269,5 @@ https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md

[warehouse#12965]: https://github.com/pypi/warehouse/issues/12965
[trusted publishing]: https://docs.pypi.org/trusted-publishers/

[how to specify username and password]: #specifying-a-different-username
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ inputs:
default: __token__
password:
description: Password for your PyPI user or an access token
required: true
required: false
repository-url: # Canonical alias for `repository_url`
description: The repository URL to use
required: false
2 changes: 1 addition & 1 deletion oidc-exchange.py
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ def assert_successful_audience_call(resp: requests.Response, domain: str):
match resp.status_code:
case HTTPStatus.FORBIDDEN:
# This index supports OIDC, but forbids the client from using
# it (either because it's disabled, limited to a beta group, etc.)
# it (either because it's disabled, ratelimited, etc.)
die(
f"audience retrieval failed: repository at {domain} has trusted publishing disabled",
)