Skip to content

Commit 21ffeac

Browse files
committed
Merge commit 'pull/origin/7'
2 parents 0bc3d27 + 8225ac3 commit 21ffeac

File tree

5 files changed

+77
-30
lines changed

5 files changed

+77
-30
lines changed

.yamllint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
indentation:
2+
indent-sequences: false

Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ LABEL "maintainer"="Sviatoslav Sydorenko <[email protected]>"
44
LABEL "repository"="https://github.com/re-actors/gh-action-pypi-publish"
55
LABEL "homepage"="https://github.com/re-actors/gh-action-pypi-publish"
66

7-
LABEL "com.github.actions.name"="pypi-publish"
8-
LABEL "com.github.actions.description"="Upload Python distribution packages to PyPI"
9-
LABEL "com.github.actions.icon"="upload-cloud"
10-
LABEL "com.github.actions.color"="yellow"
11-
127
ENV PYTHONDONTWRITEBYTECODE 1
138
ENV PYTHONUNBUFFERED 1
149

15-
ADD LICENSE.md /LICENSE.md
16-
1710
RUN pip install --upgrade --no-cache-dir twine
1811

19-
ENTRYPOINT ["twine"]
20-
CMD ["upload", "dist/*"]
12+
WORKDIR /app
13+
COPY LICENSE.md .
14+
COPY twine-upload.sh .
15+
16+
RUN chmod +x twine-upload.sh
17+
ENTRYPOINT ["/app/twine-upload.sh"]

README.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,50 @@ PyPI.
55

66

77
## Usage
8-
To use the action simply add the following lines in the end of your
9-
`.github/main.workflow`.
10-
11-
```hcl
12-
action "Upload Python dist to PyPI" {
13-
uses = "re-actors/pypi-action@master"
14-
env = {
15-
TWINE_USERNAME = "f'{your_project}-bot'"
16-
}
17-
secrets = ["TWINE_PASSWORD"]
18-
}
8+
9+
To use the action add the following step to your workflow file (e.g.:
10+
`.github/workflows/main.yml`)
11+
12+
13+
```yml
14+
- name: Publish a Python distribution to PyPI
15+
uses: pypa/gh-action-pypi-publish@master
16+
with:
17+
user: __token__
18+
password: ${{ secrets.pypi_password }}
1919
```
2020
21-
N.B. Use a valid tag, or branch, or commit SHA instead
22-
of `master` to pin the action to use a specific version of it.
21+
A common use case is to upload packages only on a tagged commit, to do so add a
22+
filter to the step:
2323
2424
25-
### Environment Variables and Secrets
26-
- **`TWINE_USERNAME`**: set this one to the username used to authenticate
27-
against PyPI. _It is recommended to have a separate user account like
28-
`f'{your_project}-bot'` having the lowest privileges possible on your
29-
target dist page._
30-
- **`TWINE_PASSWORD`**: it's a password for the account used in
31-
`TWINE_USERNAME` env var. **ATTENTION! WARNING! When adding this value
32-
to the Action node in your workflow, use SECRETS, not normal env vars.**
25+
```yml
26+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
27+
```
28+
29+
So the full step would look like:
30+
31+
32+
```yml
33+
- name: Publish package
34+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
35+
uses: pypa/gh-action-pypi-publish@master
36+
with:
37+
user: __token__
38+
password: ${{ secrets.pypi_password }}
39+
```
40+
41+
The example above uses the new [API token](https://pypi.org/help/#apitoken)
42+
feature of PyPI, which is recommended to restrict the access the action has.
43+
44+
The secret used in `${{ secrets.pypi_password }}` needs to be created on the settings
45+
page of your project on GitHub. See [Creating & using secrets].
3346

3447

3548
## License
49+
3650
The Dockerfile and associated scripts and documentation in this project
3751
are released under the [BSD 3-clause license](LICENSE.md).
52+
53+
54+
[Creating & using secrets]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables

action.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: pypi-publish
3+
description: Upload Python distribution packages to PyPI
4+
inputs:
5+
user:
6+
description: PyPI user
7+
required: false
8+
default: __token__
9+
password:
10+
description: Password for your PyPI user or an access token
11+
required: true
12+
repository_url:
13+
description: The repository URL to use
14+
required: false
15+
branding:
16+
color: yellow
17+
icon: upload-cloud
18+
runs:
19+
using: docker
20+
image: Dockerfile
21+
args:
22+
- ${{ inputs.user }}
23+
- ${{ inputs.password }}
24+
- ${{ inputs.repository_url }}

twine-upload.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
TWINE_USERNAME="$INPUT_USER" \
5+
TWINE_PASSWORD="$INPUT_PASSWORD" \
6+
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
7+
exec twine upload dist/*

0 commit comments

Comments
 (0)