Skip to content

Commit fb9d437

Browse files
authored
docs: Add versioning plugin for docs and update workflows (#1877)
1 parent 19d3de3 commit fb9d437

File tree

4 files changed

+103
-31
lines changed

4 files changed

+103
-31
lines changed

.github/workflows/build-docs.yml

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Build Docs
1+
# Build Latest Docs
22
#
33
# Description:
4-
# Builds the docs and stores them in S3 to be served by our docs platform
4+
# Builds the latest docs and stores them in S3 to be served by our docs platform
55
#
66
# The workflow allows us to build to the main location (/lambda/java/) and to an alias
77
# (i.e. /lambda/java/preview/) if needed
@@ -15,17 +15,13 @@
1515
on:
1616
workflow_dispatch:
1717
inputs:
18-
alias:
18+
version:
19+
description: "Version to build and publish docs (1.28.0, develop)"
20+
required: true
1921
type: string
20-
required: false
21-
description: |
22-
Alias to deploy the documentation into, this is mostly for testing pre-release
23-
versions of the documentation, such as beta versions or snapshots.
2422

25-
https://docs.powertools.aws.dev/lambda/java/<alias>
26-
27-
name: Build Docs
28-
run-name: Build Docs - ${{ contains(github.head_ref, 'main') && 'main' || inputs.alias }}
23+
name: Build Latest Docs
24+
run-name: Build Latest Docs - ${{ inputs.version }}
2925

3026
permissions:
3127
contents: read
@@ -38,28 +34,58 @@ jobs:
3834
id-token: write
3935
environment: Docs
4036
steps:
41-
- name: Sanity Check
42-
if: ${{ github.head_ref != 'main' || inputs.alias == '' }}
43-
run:
44-
echo "::error::No buildable docs"
45-
4637
- name: Checkout Repository
4738
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
48-
with:
39+
with:
4940
fetch-depth: 0
5041
- name: Build
5142
run: |
5243
mkdir -p dist
5344
docker build -t squidfunk/mkdocs-material ./docs/
5445
docker run --rm -t -v ${PWD}:/docs squidfunk/mkdocs-material build
55-
cp -R site/* dist/
5646
- name: Configure AWS credentials
5747
uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722
5848
with:
5949
aws-region: us-east-1
6050
role-to-assume: ${{ secrets.AWS_DOCS_ROLE_ARN }}
61-
- name: Deploy
51+
- name: Deploy Docs (Version)
52+
env:
53+
VERSION: ${{ inputs.version }}
54+
ALIAS: "latest"
6255
run: |
6356
aws s3 sync \
64-
dist \
65-
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ github.head_ref == 'main' && '' || format('{0}/', inputs.alias )}}
57+
site/ \
58+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.VERSION }}/
59+
- name: Deploy Docs (Alias)
60+
env:
61+
VERSION: ${{ inputs.version }}
62+
ALIAS: "latest"
63+
run: |
64+
aws s3 sync \
65+
site/ \
66+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.ALIAS }}/
67+
- name: Deploy Docs (Version JSON)
68+
env:
69+
VERSION: ${{ inputs.version }}
70+
ALIAS: "latest"
71+
# 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.
72+
# Instead, we're using some shell script that manages the versions.
73+
#
74+
# Operations:
75+
# 1. Download the versions.json file from S3
76+
# 2. Find any reference to the alias and delete it from the versions file
77+
# 3. This is voodoo (don't use JQ):
78+
# - we assign the input as $o and the new version/alias as $n,
79+
# - we check if the version number exists in the file already (for republishing docs)
80+
# - if it's an alias (stage/latest/*) or old version, we do nothing and output $o (original input)
81+
# - if it's a new version number, we add it at position 0 in the array.
82+
# 4. Once done, we'll upload it back to S3.
83+
run: |
84+
aws s3 cp \
85+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json \
86+
versions_old.json
87+
jq 'del(.[].aliases[] | select(. == "${{ env.ALIAS }}"))' < versions_old.json > versions_proc.json
88+
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 == $n[0].title;.) then [($o | .[] | select(.title == $n[0].title).aliases += $n[0].aliases | . )] else $n + $o end' < versions_proc.json > versions.json
89+
aws s3 cp \
90+
versions.json \
91+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json

.github/workflows/release.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#
2121
# Triggers:
2222
# - workflow_dispatch
23-
#
23+
#
2424
# Secrets:
2525
# - RELEASE.GPG_SIGNING_KEY
2626
# - RELEASE.OSSRH_JIRA_USERNAME
@@ -39,23 +39,23 @@ on:
3939
type: boolean
4040
description: Create snapshot release
4141
default: false
42-
skip_checks:
42+
skip_checks:
4343
type: boolean
4444
description: Skip quality checks
4545
default: false
4646
skip_publish:
4747
type: boolean
4848
description: Skip publish to Maven Central
4949
default: false
50-
continue_on_error:
50+
continue_on_error:
5151
type: boolean
5252
description: Continue to build if there's an error in quality checks
5353
default: false
5454

5555
name: Release
5656
run-name: Release – ${{ inputs.version }}
5757

58-
permissions:
58+
permissions:
5959
contents: read
6060

6161
env:
@@ -124,7 +124,7 @@ jobs:
124124

125125
quality:
126126
runs-on: ubuntu-latest
127-
needs:
127+
needs:
128128
- version_seal
129129
if: ${{ inputs.skip_checks == false }}
130130
permissions:
@@ -211,7 +211,7 @@ jobs:
211211
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
212212
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
213213
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
214-
214+
215215
create_pr:
216216
runs-on: ubuntu-latest
217217
if: ${{ inputs.snapshot == false && always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
@@ -280,14 +280,49 @@ jobs:
280280
mkdir -p dist
281281
docker build -t squidfunk/mkdocs-material ./docs/
282282
docker run --rm -t -v ${PWD}:/docs squidfunk/mkdocs-material build
283-
cp -R site/* dist/
284283
- name: Configure AWS credentials
285284
uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722
286285
with:
287286
aws-region: us-east-1
288287
role-to-assume: ${{ secrets.AWS_DOCS_ROLE_ARN }}
289-
- name: Deploy
288+
- name: Deploy Docs (Version)
289+
env:
290+
VERSION: ${{ inputs.version }}
291+
ALIAS: 'latest'
290292
run: |
291293
aws s3 sync \
292-
dist \
293-
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/
294+
site/ \
295+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.VERSION }}/
296+
- name: Deploy Docs (Alias)
297+
env:
298+
VERSION: ${{ inputs.version }}
299+
ALIAS: 'latest'
300+
run: |
301+
aws s3 sync \
302+
site/ \
303+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.ALIAS }}/
304+
- name: Deploy Docs (Version JSON)
305+
env:
306+
VERSION: ${{ inputs.version }}
307+
ALIAS: 'latest'
308+
# 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.
309+
# Instead, we're using some shell script that manages the versions.
310+
#
311+
# Operations:
312+
# 1. Download the versions.json file from S3
313+
# 2. Find any reference to the alias and delete it from the versions file
314+
# 3. This is voodoo (don't use JQ):
315+
# - we assign the input as $o and the new version/alias as $n,
316+
# - we check if the version number exists in the file already (for republishing docs)
317+
# - if it's an alias (stage/latest/*) or old version, we do nothing and output $o (original input)
318+
# - if it's a new version number, we add it at position 0 in the array.
319+
# 4. Once done, we'll upload it back to S3.
320+
run: |
321+
aws s3 cp \
322+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json \
323+
versions_old.json
324+
jq 'del(.[].aliases[] | select(. == "${{ env.ALIAS }}"))' < versions_old.json > versions_proc.json
325+
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 == $n[0].title;.) then [($o | .[] | select(.title == $n[0].title).aliases += $n[0].aliases | . )] else $n + $o end' < versions_proc.json > versions.json
326+
aws s3 cp \
327+
versions.json \
328+
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json

docs/overrides/main.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "base.html" %}
2+
3+
{% block outdated %}
4+
You're not viewing the latest version.
5+
<a href="{{ '../' ~ base_url }}">
6+
<strong>Click here to go to latest.</strong>
7+
</a>
8+
{% endblock %}

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ extra_javascript:
123123
extra:
124124
powertools:
125125
version: 1.20.2 # to update after each release (we do not want snapshot version here)
126+
version:
127+
provider: mike
128+
default: latest
126129

127130
repo_url: https://github.com/aws-powertools/powertools-lambda-java
128131
edit_uri: edit/main/docs

0 commit comments

Comments
 (0)