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
3026permissions :
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
0 commit comments