Skip to content

Commit 3461012

Browse files
committed
Improve release workflows
1 parent cf6c6c6 commit 3461012

File tree

4 files changed

+140
-7
lines changed

4 files changed

+140
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
default:
2+
enable-docs: true

.github/workflows/docs.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@ name: '📚 Publish docs via GitHub Pages'
44
# build the documentation whenever there are new commits on main
55
on:
66
workflow_dispatch:
7+
inputs:
8+
dry-run:
9+
required: false
10+
default: true
11+
type: boolean
12+
713
workflow_call:
14+
inputs:
15+
dry-run:
16+
required: false
17+
default: true
18+
type: boolean
19+
20+
outputs:
21+
page-url:
22+
description: 'URL to the docs published on GitHub Pages'
23+
value: ${{ jobs.deploy.outputs.page-url }}
824

925
jobs:
1026
config-prep:
@@ -65,13 +81,17 @@ jobs:
6581
# This is a separate job so that only actions/deploy-pages has the necessary permissions.
6682
deploy:
6783
needs: build
68-
runs-on: ubuntu-latest
84+
if: ${{ !inputs.dry-run }}
6985
permissions:
7086
pages: write
7187
id-token: write
7288
environment:
7389
name: github-pages
7490
url: ${{ steps.deployment.outputs.page_url }}
91+
92+
runs-on: ubuntu-latest
93+
outputs:
94+
page-url: ${{ steps.deployment.outputs.page_url }}
7595
steps:
7696
- id: deployment
7797
uses: actions/deploy-pages@v1

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: '🎁 Release'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry-run:
7+
required: false
8+
default: true
9+
type: boolean
10+
11+
release:
12+
types: [published]
13+
14+
jobs:
15+
config-prep:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run }}
19+
enable-docs: ${{ steps.read-file.outputs.content }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Read YAML file
25+
id: read-file
26+
uses: ./.github/actions/read-yaml
27+
with:
28+
path: .github/settings/release-config.yml
29+
filter: '.default.enable-docs'
30+
31+
publish-package:
32+
needs: config-prep
33+
uses: ./.github/workflows/testpypi.yml
34+
with:
35+
dry-run: ${{ fromJson(needs.config-prep.outputs.dry-run) }}
36+
secrets: inherit
37+
38+
publish-docs:
39+
needs: [config-prep, publish-package]
40+
if: needs.config-prep.outputs.enable-docs == 'true'
41+
uses: ./.github/workflows/docs.yml
42+
with:
43+
dry-run: ${{ fromJson(needs.config-prep.outputs.dry-run) }}
44+
45+
report:
46+
needs: [publish-package, publish-docs]
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Debug
50+
shell: bash
51+
run: |
52+
echo ${{ needs.publish-package.result }}
53+
echo ${{ needs.publish-docs.result }}
54+
55+
- name: Generate a summary
56+
uses: actions/github-script@v6
57+
with:
58+
script: |
59+
const name_to_url = new Map([
60+
['TestPyPI', '${{ needs.publish-package.outputs.page-url }}'],
61+
]);
62+
if ('${{ needs.publish-docs.outputs.page-url }}' != '') {
63+
name_to_url.set('GitHub Pages', '${{ needs.publish-docs.outputs.page-url }}');
64+
}
65+
66+
const list = [...name_to_url].map(([name, url]) =>
67+
`<a href="${url}">${name}</a>`
68+
);
69+
70+
await core.summary
71+
.addHeading('Links to published content')
72+
.addList(list)
73+
.write()

.github/workflows/testpypi.yml

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
name: '📦 Publish the package to TestPyPI'
22

33
on:
4-
workflow_dispatch:
5-
release:
6-
types: [published]
4+
workflow_call:
5+
inputs:
6+
dry-run:
7+
required: false
8+
default: true
9+
type: boolean
10+
11+
outputs:
12+
page-url:
13+
description: 'URL to the package published on TestPyPI'
14+
value: ${{ jobs.make-url.outputs.page-url }}
715

816
jobs:
917
config-prep:
@@ -26,6 +34,8 @@ jobs:
2634
env: ${{ fromJson(needs.config-prep.outputs.env) }}
2735

2836
runs-on: ubuntu-latest
37+
outputs:
38+
api-end-point: ${{ steps.configure-poetry.outputs.api-end-point }}
2939
steps:
3040
- name: Checkout
3141
uses: actions/checkout@v3
@@ -49,11 +59,14 @@ jobs:
4959
poetry-path: ${{ env.poetry-path }}
5060

5161
- name: Configure Poetry
62+
id: configure-poetry
5263
env:
5364
TESTPYPI_API_TOKEN: ${{ secrets.TESTPYPI_API_TOKEN }}
65+
shell: bash
5466
run: |
5567
poetry config repositories.test-pypi https://test.pypi.org/legacy/
5668
poetry config pypi-token.test-pypi $TESTPYPI_API_TOKEN
69+
echo "api-end-point=$(poetry config repositories.test-pypi | sed 's/\x27/"/g' | jq '.url' | sed 's/"//g')" >> $GITHUB_OUTPUT
5770
5871
- name: Install dependencies
5972
run: |
@@ -63,11 +76,36 @@ jobs:
6376
run: |
6477
poetry build
6578
79+
- name: Publish --dry-run
80+
if: inputs.dry-run == true
81+
run: |
82+
poetry publish -r test-pypi --dry-run
83+
6684
- name: Publish
85+
if: inputs.dry-run != true
6786
run: |
6887
poetry publish -r test-pypi
6988
70-
docs:
71-
if: true # true if documentation is needed.
89+
make-url:
7290
needs: deploy
73-
uses: ./.github/workflows/docs.yml
91+
runs-on: ubuntu-latest
92+
outputs:
93+
page-url: ${{ steps.make-url.outputs.url }}
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@v3
97+
98+
- name: Read TOML file
99+
uses: SebRollen/[email protected]
100+
id: read-toml
101+
with:
102+
file: pyproject.toml
103+
field: 'tool.poetry.name'
104+
105+
- name: Make URL
106+
id: make-url
107+
shell: bash
108+
run: |
109+
api_end_point='${{ needs.deploy.outputs.api-end-point }}'
110+
protocol_domain="$(echo "${api_end_point}" | grep -Eo '^http[s]?://[^/]+')/"
111+
echo "url=${protocol_domain}project/${{ steps.read-toml.outputs.value }}/" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)