Skip to content

Commit aefad8b

Browse files
author
Steven Silvester
authored
Merge pull request #146 from jtpio/token-map
Add support for PYPI token map
2 parents e17735c + 9ef5f63 commit aefad8b

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.github/workflows/publish-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ jobs:
3636
- name: Publish Release
3737
id: publish-release
3838
env:
39-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
39+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
40+
PYPI_TOKEN_MAP: ${{ secrets.PYPI_TOKEN_MAP }}
4041
TWINE_USERNAME: __token__
4142
TWINE_REGISTRY: ${{ github.event.inputs.pypi_registry }}
4243
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ A. Prep the `jupyter_releaser` fork:
203203
`ADMIN_GITHUB_TOKEN` in the [repository secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
204204
- [ ] Add access token for the [PyPI registry](https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#saving-credentials-on-github) stored as `PYPI_TOKEN`.
205205
_Note_ For security reasons, it is recommended that you scope the access
206-
to a single repository, and update the value of `PYPI_TOKEN` for each repository that you are releasing.
206+
to a single repository, and use a variable called `PYPI_TOKEN_MAP` that is formatted as follows:
207+
208+
```
209+
owner1/repo1,token1
210+
owner2/repo2,token2
211+
```
212+
207213
- [ ] If needed, add access token for [npm](https://docs.npmjs.com/creating-and-viewing-access-tokens), saved as `NPM_TOKEN`.
208214

209215
B. Prep target repository:

jupyter_releaser/actions/publish_release.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
from jupyter_releaser.util import run
66

7+
# First extract the pypi token
8+
twine_pwd = os.environ.get("PYPI_TOKEN")
9+
pypi_token_map = os.environ.get("PYPI_TOKEN_MAP", "").replace(r"\n", "\n")
10+
if pypi_token_map:
11+
for line in pypi_token_map.splitlines():
12+
name, _, token = line.partition(",")
13+
if name == os.environ["RH_REPOSITORY"]:
14+
twine_pwd = token
15+
os.environ["TWINE_PASSWORD"] = token
16+
17+
718
release_url = os.environ["release_url"]
819
run(f"jupyter-releaser extract-release {release_url}")
920
run(f"jupyter-releaser forwardport-changelog {release_url}")

0 commit comments

Comments
 (0)