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