Skip to content

Commit 5092119

Browse files
committed
docs: add support for docs versioning (#1239)
1 parent f19e202 commit 5092119

File tree

6 files changed

+189
-78
lines changed

6 files changed

+189
-78
lines changed

.github/workflows/build-docs.yml

-37
This file was deleted.

.github/workflows/docs.yml

-41
This file was deleted.

.github/workflows/on-doc-merge.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "docs/**"
9+
- "mkdocs.yml"
10+
11+
jobs:
12+
release-docs:
13+
permissions:
14+
contents: write
15+
pages: write
16+
id-token: write
17+
secrets: inherit
18+
uses: ./.github/workflows/reusable-publish-docs.yml
19+
with:
20+
version: main
21+
alias: stage
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Rebuild latest docs
2+
3+
# PROCESS
4+
#
5+
# 1. Build User Guide and API docs
6+
# 2. Publish to GitHub Pages
7+
# 3. Publish to S3 (new home)
8+
9+
# USAGE
10+
#
11+
# Only used for deploying a documentation hotfix to /latest and its associated version w/o a full release.
12+
#
13+
# Steps:
14+
#
15+
# 1. Trigger "Rebuild latest docs" workflow manually: https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
16+
# 2. Use the latest version released under Releases e.g. 2.0.0
17+
18+
on:
19+
workflow_dispatch:
20+
inputs:
21+
latest_published_version:
22+
description: "Latest published version to rebuild latest docs for, e.g. 1.4.2"
23+
default: "1.4.2"
24+
required: true
25+
26+
permissions:
27+
contents: read
28+
29+
jobs:
30+
release-docs:
31+
permissions:
32+
contents: write # push to gh-pages
33+
pages: write # deploy gh-pages website
34+
id-token: write # trade JWT token for AWS credentials in AWS Docs account
35+
secrets: inherit
36+
uses: ./.github/workflows/reusable_publish_docs.yml
37+
with:
38+
version: ${{ inputs.latest_published_version }}
39+
alias: latest
+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Reusable Publish docs
2+
3+
env:
4+
BRANCH: main
5+
ORIGIN: aws-powertools/powertools-lambda-java
6+
VERSION: ""
7+
8+
on:
9+
workflow_call:
10+
inputs:
11+
version:
12+
description: "Version to build and publish docs (1.28.0, develop)"
13+
required: true
14+
type: string
15+
alias:
16+
description: "Alias to associate version (latest, stage)"
17+
required: true
18+
type: string
19+
detached_mode:
20+
description: "Whether it's running in git detached mode to ensure git is sync'd"
21+
required: false
22+
default: false
23+
type: boolean
24+
25+
permissions:
26+
contents: write
27+
id-token: write
28+
pages: write
29+
30+
jobs:
31+
publish-docs:
32+
runs-on: ubuntu-latest
33+
environment: Docs
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
37+
with:
38+
# While `fetch-depth` is used to allow the workflow to later commit & push the changes.
39+
fetch-depth: 0
40+
- name: Setup dependencies
41+
uses: ./.github/actions/cached-node-modules
42+
- name: Set up Python
43+
uses: actions/setup-python@57ded4d7d5e986d7296eab16560982c6dd7c923b # v4.6.0
44+
with:
45+
python-version: "3.8"
46+
- name: Install doc generation dependencies
47+
run: |
48+
pip install --upgrade pip
49+
pip install -r docs/requirements.txt
50+
- name: Setup doc deploy
51+
run: |
52+
git config --global user.name Docs deploy
53+
git config --global user.email [email protected]
54+
- name: Git refresh tip (detached mode)
55+
# Git Detached mode (release notes) doesn't have origin
56+
if: ${{ inputs.detached_mode }}
57+
run: |
58+
git config pull.rebase true
59+
git config remote.origin.url >&- || git remote add origin https://github.com/"$ORIGIN"
60+
git pull origin "$BRANCH"
61+
- name: Normalize Version Number
62+
run: echo "VERSION=$(echo ${{ inputs.version }} | sed 's/v//')" >> $GITHUB_ENV
63+
- name: Build docs website and API reference
64+
env:
65+
ALIAS: ${{ inputs.alias }}
66+
run: |
67+
rm -rf site
68+
mkdocs build
69+
mike deploy --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }} --branch backup-gh-pages
70+
# Set latest version as a default
71+
mike set-default latest --branch backup-gh-pages
72+
- name: Configure AWS credentials
73+
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0
74+
with:
75+
aws-region: us-east-1
76+
role-to-assume: ${{ secrets.AWS_DOCS_ROLE_ARN }}
77+
- name: Copy API Docs
78+
run: |
79+
cp -r api site/
80+
81+
## Uncomment to deploy to s3
82+
# - name: Deploy Docs (Version)
83+
# env:
84+
# VERSION: ${{ inputs.version }}
85+
# ALIAS: ${{ inputs.alias }}
86+
# run: |
87+
# aws s3 sync \
88+
# site/ \
89+
# s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.VERSION }}/
90+
# - name: Deploy Docs (Alias)
91+
# env:
92+
# VERSION: ${{ inputs.version }}
93+
# ALIAS: ${{ inputs.alias }}
94+
# run: |
95+
# aws s3 sync \
96+
# site/ \
97+
# s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.ALIAS }}/
98+
# - name: Deploy Docs (Version JSON)
99+
# env:
100+
# VERSION: ${{ inputs.version }}
101+
# ALIAS: ${{ inputs.alias }}
102+
103+
104+
# We originally used "mike" from PyPi to manage versions for us, but since we moved to S3, we can't use it to manage versions any more.
105+
# Instead, we're using some shell script that manages the versions.
106+
#
107+
# Operations:
108+
# 1. Download the versions.json file from S3
109+
# 2. Find any reference to the alias and delete it from the versions file
110+
# 3. This is voodoo (don't use JQ):
111+
# - we assign the input as $o and the new version/alias as $n,
112+
# - we check if the version number exists in the file already (for republishing docs)
113+
# - if it's an alias (stage/latest/*) or old version, we do nothing and output $o (original input)
114+
# - if it's a new version number, we add it at position 0 in the array.
115+
# 4. Once done, we'll upload it back to S3.
116+
117+
## Uncomment to deploy to s3
118+
# run: |
119+
# aws s3 cp \
120+
# s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json \
121+
# versions_old.json
122+
# jq 'del(.[].aliases[] | select(. == "${{ env.ALIAS }}"))' < versions_old.json > versions_proc.json
123+
# jq '. as $o | [{"title": "${{ env.VERSION }}", "version": "${{ env.VERSION }}", "aliases": ["${{env.ALIAS}}"] }] as $n | $n | if .[0].title | test("[a-z]+") or any($o[].title == "${{ env.VERSION }}";.) then $o else $n + $o end' < versions_proc.json > versions.json
124+
# aws s3 cp \
125+
# versions.json \
126+
# s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json

mkdocs.yml

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ extra_javascript:
8282
- javascript/extra.js
8383

8484
extra:
85+
version:
86+
provider: mike
87+
default: latest
8588
powertools:
8689
version: 1.16.0 # to update after each release (we do not want snapshot version here)
8790

0 commit comments

Comments
 (0)