-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
91 lines (80 loc) · 2.83 KB
/
create-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Create release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
permissions:
contents: read
jobs:
publish-pypi:
runs-on: ubuntu-latest
name: PyPI Release
environment: release
permissions:
id-token: write # for PyPI trusted publishing
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
cache: pip
cache-dependency-path: pyproject.toml
- name: Install build dependencies (pypa/build, twine)
run: |
pip install -U pip
pip install build twine
- name: Build distribution
run: python -m build
- name: Mint PyPI API token
id: mint-token
uses: actions/github-script@v6
with:
script: |
// retrieve the ambient OIDC token
const oidc_request_token = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
const oidc_request_url = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
const oidc_resp = await fetch(`${oidc_request_url}&audience=testpypi`, {
headers: {Authorization: `bearer ${oidc_request_token}`},
}
);
const oidc_token = (await oidc_resp.json()).value;
// exchange the OIDC token for an API token
const mint_resp = await fetch('https://test.pypi.org/_/oidc/github/mint-token', {
method: 'post',
body: '{"token": "oidc_token"}' ,
headers: {'Content-Type': 'application/json'},
}
);
const api_token = (await mint_resp.json()).token;
// mask the newly minted API token, so that we don't accidentally leak it
core.setSecret(api_token)
core.setOutput('api-token', api_token)
- name: Upload to Test PyPI
env:
TWINE_NON_INTERACTIVE: "true"
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: "${{ steps.mint-token.outputs.api-token }}"
TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
run: |
twine check dist/*
twine upload dist/*
github-release:
runs-on: ubuntu-latest
name: GitHub release
permissions:
contents: write # for softprops/action-gh-release to create GitHub release
steps:
- uses: actions/checkout@v3
- name: Get release version
id: get_version
uses: actions/github-script@v6
with:
script: core.setOutput('version', context.ref.replace("refs/tags/v", ""))
- name: Create GitHub release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
name: "Sphinx ${{ steps.get_version.outputs.version }}"
body: "Changelog: https://www.sphinx-doc.org/en/master/changes.html"