Skip to content

Commit 8971f5b

Browse files
heitorlessarubenfonseca
authored andcommitted
chore(ci): create reusable docs publishing workflow (#1482)
1 parent c20277b commit 8971f5b

File tree

5 files changed

+136
-163
lines changed

5 files changed

+136
-163
lines changed

.github/workflows/on_push_docs.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
paths:
8+
- "docs/**"
9+
- "mkdocs.yml"
10+
- "examples/**"
11+
12+
jobs:
13+
changelog:
14+
permissions:
15+
contents: write
16+
uses: ./.github/workflows/reusable_publish_changelog.yml
17+
18+
release-docs:
19+
needs: changelog
20+
permissions:
21+
contents: write
22+
pages: write
23+
uses: ./.github/workflows/reusable_publish_docs.yml
24+
with:
25+
version: develop
26+
alias: stage
27+
# Maintenance: Only necessary in repo migration
28+
# - name: Create redirect from old docs
29+
# run: |
30+
# git checkout gh-pages
31+
# test -f 404.html && echo "Redirect already set" && exit 0
32+
# git checkout develop -- 404.html
33+
# git add 404.html
34+
# git commit -m "chore: set docs redirect" --no-verify
35+
# git push origin gh-pages -f

.github/workflows/on_release_notes.yml

+9-45
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ jobs:
6969
id: release_version
7070
# transform tag format `v<version` to `<version`
7171
run: |
72-
RELEASE_VERSION=${RELEASE_TAG_VERSION:1}
73-
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
72+
RELEASE_VERSION="${RELEASE_TAG_VERSION:1}"
73+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "$GITHUB_ENV"
7474
echo "::set-output name=RELEASE_VERSION::${RELEASE_VERSION}"
7575
- name: Install dependencies
7676
run: make dev
7777
- name: Run all tests, linting and baselines
7878
if: ${{ !inputs.skip_code_quality }}
7979
run: make pr
8080
- name: Bump package version
81-
run: poetry version ${RELEASE_VERSION}
81+
run: poetry version "${RELEASE_VERSION}"
8282
- name: Build python package and wheel
8383
if: ${{ !inputs.skip_pypi }}
8484
run: poetry build
@@ -101,7 +101,7 @@ jobs:
101101
role-to-assume: ${{ secrets.AWS_SAR_ROLE_ARN }}
102102
- name: publish lambda layer in SAR by triggering the internal codepipeline
103103
run: |
104-
aws ssm put-parameter --name "powertools-python-release-version" --value $RELEASE_VERSION --overwrite
104+
aws ssm put-parameter --name "powertools-python-release-version" --value "$RELEASE_VERSION" --overwrite
105105
aws codepipeline start-pipeline-execution --name ${{ secrets.AWS_SAR_PIPELINE_NAME }}
106106
107107
changelog:
@@ -115,47 +115,11 @@ jobs:
115115
permissions:
116116
contents: write
117117
pages: write
118-
runs-on: ubuntu-latest
119-
env:
120-
RELEASE_VERSION: ${{ needs.release.outputs.RELEASE_VERSION }}
121-
steps:
122-
- uses: actions/checkout@v3
123-
with:
124-
fetch-depth: 0
125-
- name: Git client setup and refresh tip
126-
run: |
127-
git config user.name "Release bot"
128-
git config user.email "[email protected]"
129-
git config pull.rebase true
130-
git config remote.origin.url >&- || git remote add origin https://github.com/$origin # Git Detached mode (release notes) doesn't have origin
131-
git pull origin $BRANCH
132-
- name: Install poetry
133-
run: pipx install poetry
134-
- name: Set up Python
135-
uses: actions/setup-python@v4
136-
with:
137-
python-version: "3.8"
138-
cache: "poetry"
139-
- name: Install dependencies
140-
run: make dev
141-
- name: Build docs website and API reference
142-
run: |
143-
make release-docs VERSION=${RELEASE_VERSION} ALIAS="latest"
144-
poetry run mike set-default --push latest
145-
- name: Release API docs to release version
146-
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305 # v3.8.0
147-
with:
148-
github_token: ${{ secrets.GITHUB_TOKEN }}
149-
publish_dir: ./api
150-
keep_files: true
151-
destination_dir: ${{ env.RELEASE_VERSION }}/api
152-
- name: Release API docs to latest
153-
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305 # v3.8.0
154-
with:
155-
github_token: ${{ secrets.GITHUB_TOKEN }}
156-
publish_dir: ./api
157-
keep_files: true
158-
destination_dir: latest/api
118+
uses: ./.github/workflows/reusable_publish_docs.yml
119+
with:
120+
version: ${{ needs.release.outputs.RELEASE_VERSION }}
121+
alias: latest
122+
detached_mode: true
159123

160124
post_release:
161125
needs: release

.github/workflows/python_docs.yml

-71
This file was deleted.

.github/workflows/rebuild_latest_docs.yml

+9-47
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ name: Rebuild latest docs
55
#
66
# 1. Trigger "Rebuild latest docs" workflow manually: https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
77
# 2. Use the latest version released under Releases e.g. v1.22.0
8-
# 3. Set `Build and publish docs only` field to `true`
98

109
on:
1110
workflow_dispatch:
1211
inputs:
1312
latest_published_version:
1413
description: "Latest PyPi published version to rebuild latest docs for, e.g. v1.26.7"
15-
default: "v1.26.7"
14+
default: "v1.28.0"
1615
required: true
1716

1817
jobs:
@@ -21,49 +20,12 @@ jobs:
2120
contents: write
2221
uses: ./.github/workflows/reusable_publish_changelog.yml
2322

24-
release:
23+
release-docs:
2524
needs: changelog
26-
# Force Github action to run only a single job at a time (based on the group name)
27-
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages`
28-
concurrency:
29-
group: on-docs-rebuild
30-
runs-on: ubuntu-latest
31-
steps:
32-
- uses: actions/checkout@v3
33-
with:
34-
fetch-depth: 0
35-
- name: Install poetry
36-
run: pipx install poetry
37-
- name: Set up Python
38-
uses: actions/setup-python@v4
39-
with:
40-
python-version: "3.8"
41-
cache: "poetry"
42-
- name: Set release notes tag
43-
run: |
44-
RELEASE_TAG_VERSION=${{ github.event.inputs.latest_published_version }}
45-
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
46-
- name: Install dependencies
47-
run: make dev
48-
- name: Setup doc deploy
49-
run: |
50-
git config --global user.name Docs deploy
51-
git config --global user.email [email protected]
52-
- name: Build docs website and API reference
53-
run: |
54-
make release-docs VERSION=${RELEASE_TAG_VERSION} ALIAS="latest"
55-
poetry run mike set-default --push latest
56-
- name: Release API docs to release version
57-
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305 # v3.8.0
58-
with:
59-
github_token: ${{ secrets.GITHUB_TOKEN }}
60-
publish_dir: ./api
61-
keep_files: true
62-
destination_dir: ${{ env.RELEASE_TAG_VERSION }}/api
63-
- name: Release API docs to latest
64-
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305 # v3.8.0
65-
with:
66-
github_token: ${{ secrets.GITHUB_TOKEN }}
67-
publish_dir: ./api
68-
keep_files: true
69-
destination_dir: latest/api
25+
permissions:
26+
contents: write
27+
pages: write
28+
uses: ./.github/workflows/reusable_publish_docs.yml
29+
with:
30+
version: ${{ inputs.latest_published_version }}
31+
alias: latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Reusable publish documentation
2+
3+
env:
4+
BRANCH: develop
5+
ORIGIN: awslabs/aws-lambda-powertools-python
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
version:
11+
description: "Version to build and publish docs (v1.28.0, develop)"
12+
required: true
13+
type: string
14+
alias:
15+
description: "Alias to associate version (latest, stage)"
16+
required: true
17+
type: string
18+
detached_mode:
19+
description: "Whether it's running in git detached mode to ensure git is sync'd"
20+
required: false
21+
default: false
22+
type: boolean
23+
24+
permissions:
25+
contents: write
26+
pages: write
27+
28+
jobs:
29+
publish_docs:
30+
# Force Github action to run only a single job at a time (based on the group name)
31+
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages`
32+
concurrency:
33+
group: on-docs-rebuild
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
- name: Install poetry
40+
run: pipx install poetry
41+
- name: Set up Python
42+
uses: actions/setup-python@v4
43+
with:
44+
python-version: "3.8"
45+
cache: "poetry"
46+
- name: Install dependencies
47+
run: make dev
48+
- name: Git client setup
49+
run: |
50+
git config --global user.name Docs deploy
51+
git config --global user.email [email protected]
52+
- name: Git refresh tip (detached mode)
53+
# Git Detached mode (release notes) doesn't have origin
54+
if: ${{ inputs.detached_mode }}
55+
run: |
56+
git config pull.rebase true
57+
git config remote.origin.url >&- || git remote add origin https://github.com/"$ORIGIN"
58+
git pull origin "$BRANCH"
59+
- name: Build docs website and API reference
60+
env:
61+
VERSION: ${{ inputs.version }}
62+
ALIAS: ${{ inputs.alias }}
63+
run: |
64+
make release-docs VERSION="$VERSION" ALIAS="$ALIAS"
65+
poetry run mike set-default --push latest
66+
# Maintenance: Migrate to new gh-pages action
67+
- name: Release API docs
68+
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305 # v3.8.0
69+
env:
70+
VERSION: ${{ inputs.version }}
71+
with:
72+
github_token: ${{ secrets.GITHUB_TOKEN }}
73+
publish_dir: ./api
74+
keep_files: true
75+
destination_dir: ${{ env.VERSION }}/api
76+
- name: Release API docs to latest
77+
if: ${{ inputs.alias == 'latest' }}
78+
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305 # v3.8.0
79+
with:
80+
github_token: ${{ secrets.GITHUB_TOKEN }}
81+
publish_dir: ./api
82+
keep_files: true
83+
destination_dir: latest/api

0 commit comments

Comments
 (0)