-
Notifications
You must be signed in to change notification settings - Fork 156
chore(ci): automatically update docs after layer publish during release #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
am29d
merged 11 commits into
aws-powertools:main
from
am29d:1124-publish-layer-with-version-in-docs
Feb 25, 2023
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a4b4a45
add new regions
7723f00
fix husky pre push command
1a0f1f9
add script to update docs, adjust layer publish workflow
62f508d
add publish layer after release
b68017e
Merge remote-tracking branch 'origin' into 1124-publish-layer-with-ve…
f31ec72
pass output to layer publish during release
d817f88
make publish layer explicit and update docs after layer deployment
06faae6
cleanup and provide inputs to the workflow from the caller, instead o…
562aef6
create dedicated trigger for docs only PR
66d87c9
remove unnecessary workflow
8b6f2f0
add review changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/bash | ||
|
||
# This script is run during the reusable_update_v2_layer_arn_docs CI job, | ||
# and it is responsible for replacing the layer ARN in our documentation, | ||
# based on the output files generated by CDK when deploying to each pseudo_region. | ||
# | ||
# see .github/workflows/reusable_deploy_v2_layer_stack.yml | ||
|
||
set -eo pipefail | ||
|
||
if [[ $# -ne 1 ]]; then | ||
cat <<EOM | ||
Usage: $(basename $0) cdk-output-dir | ||
|
||
cdk-output-dir: directory containing the cdk output files generated when deploying the Layer | ||
EOM | ||
exit 1 | ||
fi | ||
|
||
CDK_OUTPUT_DIR=$1 | ||
|
||
# Check if CDK output dir is a directory | ||
if [ ! -d "$CDK_OUTPUT_DIR" ]; then | ||
echo "No $CDK_OUTPUT_DIR directory found, not replacing lambda layer versions" | ||
exit 1 | ||
fi | ||
|
||
# Process each file inside the directory | ||
files="$CDK_OUTPUT_DIR/*" | ||
for file in $files; do | ||
echo "[+] Processing: $file" | ||
|
||
# Process each line inside the file | ||
lines=$(cat "$file") | ||
for line in $lines; do | ||
echo -e "\t[*] ARN: $line" | ||
# line = arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScript:49 | ||
|
||
# From the full ARN, extract everything but the version at the end. This prefix | ||
# will later be used to find/replace the ARN on the documentation file. | ||
prefix=$(echo "$line" | cut -d ':' -f 1-7) | ||
# prefix = arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScript | ||
|
||
# Now replace the all "prefix"s in the file with the full new Layer ARN (line) | ||
# prefix:\d+ ==> line | ||
# sed doesn't support \d+ in a portable way, so we cheat with (:digit: :digit: *) | ||
sed -i -e "s/$prefix:[[:digit:]][[:digit:]]*/$line/g" docs/index.md | ||
|
||
# We use the eu-central-1 layer as the version for all the frameworks (SAM, CDK, SLS, etc) | ||
# We could have used any other region. What's important is the version at the end. | ||
|
||
# Examples of strings found in the documentation with pseudo regions: | ||
# arn:aws:lambda:{region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39 | ||
# arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39 | ||
# arn:aws:lambda:${aws:region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39 | ||
# arn:aws:lambda:{env.region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:39 | ||
if [[ "$line" == *"eu-central-1"* ]]; then | ||
# These are all the framework pseudo parameters currently found in the docs | ||
for pseudo_region in '{region}' '${AWS::Region}' '${aws::region}' '{aws::region}' '{env.region}' '${cdk.Stack.of(this).region}' '${aws.getRegionOutput().name}'; do | ||
prefix_pseudo_region=$(echo "$prefix" | sed "s/eu-central-1/${pseudo_region}/") | ||
# prefix_pseudo_region = arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript | ||
|
||
line_pseudo_region=$(echo "$line" | sed "s/eu-central-1/${pseudo_region}/") | ||
# line_pseudo_region = arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:49 | ||
|
||
# Replace all the "prefix_pseudo_region"'s in the file | ||
# prefix_pseudo_region:\d+ ==> line_pseudo_region | ||
sed -i -e "s/$prefix_pseudo_region:[[:digit:]][[:digit:]]*/$line_pseudo_region/g" docs/index.md | ||
done | ||
fi | ||
done | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Docs | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "docs/**" | ||
- "mkdocs.yml" | ||
- "examples/**" | ||
|
||
jobs: | ||
release-docs: | ||
needs: changelog | ||
permissions: | ||
contents: write | ||
pages: write | ||
uses: ./.github/workflows/reusable-publish-docs.yml | ||
with: | ||
workflow_origin: ${{ github.event.repository.full_name }} | ||
version: dev | ||
alias: stage | ||
secrets: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
name: Reusable Publish docs | ||
|
||
env: | ||
BRANCH: main | ||
ORIGIN: awslabs/aws-lambda-powertools-python | ||
|
||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349 | ||
version: | ||
description: "Version to build and publish docs (1.28.0, develop)" | ||
am29d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required: true | ||
type: string | ||
prIsMerged: | ||
required: false | ||
default: "false" | ||
type: string | ||
isRelease: | ||
required: false | ||
default: "false" | ||
alias: | ||
description: "Alias to associate version (latest, stage)" | ||
required: true | ||
type: string | ||
versionNumber: | ||
detached_mode: | ||
description: "Whether it's running in git detached mode to ensure git is sync'd" | ||
required: false | ||
default: "" | ||
default: false | ||
type: boolean | ||
workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349 | ||
required: true | ||
type: string | ||
secrets: | ||
token: | ||
|
@@ -65,68 +71,48 @@ jobs: | |
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.8" | ||
# We run this step only when the workflow has been triggered by a release | ||
# in this case we publish the docs to `/latest` | ||
- name: (Conditional) Set RELEASE_VERSION env var to `latest` | ||
if: ${{ inputs.isRelease == 'true' }} | ||
run: | | ||
RELEASE_VERSION=$(echo ${{ github.ref_name }} | sed 's/v//') | ||
EXPLICIT_RELEASE_VERSION=$(echo ${{ inputs.versionNumber }} | sed 's/v//') | ||
if [ $EXPLICIT_RELEASE_VERSION != "" ]; then | ||
echo "RELEASE_VERSION=${EXPLICIT_RELEASE_VERSION}" | ||
echo "RELEASE_VERSION=${EXPLICIT_RELEASE_VERSION}" >> $GITHUB_ENV | ||
else | ||
echo "RELEASE_VERSION=${RELEASE_VERSION}" | ||
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV | ||
fi | ||
# We run this step only when the workflow has been triggered by a PR merge | ||
# in this case we publish the docs to `/dev` | ||
- name: (Conditional) Set RELEASE_VERSION env var to `dev` | ||
if: ${{ inputs.prIsMerged == 'true' }} | ||
run: | | ||
echo "RELEASE_VERSION=dev" >> $GITHUB_ENV | ||
- name: Check RELEASE_VERSION env var | ||
if: ${{ env.RELEASE_VERSION == '' }} | ||
uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
core.setFailed('RELEASE_VERSION env var is empty.') | ||
- name: Install doc generation dependencies | ||
run: | | ||
pip install --upgrade pip | ||
pip install -r docs/requirements.txt | ||
- name: Setup doc deploy | ||
run: | | ||
git config --global user.name Docs deploy | ||
git config --global user.email [email protected] | ||
- name: Publish docs to latest if isRelease | ||
if: ${{ env.RELEASE_VERSION != 'dev' }} | ||
git config --global user.email [email protected] | ||
- name: Git refresh tip (detached mode) | ||
# Git Detached mode (release notes) doesn't have origin | ||
if: ${{ inputs.detached_mode }} | ||
run: | | ||
git config pull.rebase true | ||
git config remote.origin.url >&- || git remote add origin https://github.com/"$ORIGIN" | ||
git pull origin "$BRANCH" | ||
- name: Build docs website and API reference | ||
run: | | ||
make release-docs VERSION="$VERSION" ALIAS="$ALIAS" | ||
poetry run mike set-default --push latest | ||
- name: Build docs website and API reference | ||
env: | ||
VERSION: ${{ inputs.version }} | ||
ALIAS: ${{ inputs.alias }} | ||
run: | | ||
rm -rf site | ||
mkdocs build | ||
mike deploy --push --update-aliases --no-redirect "${{ env.RELEASE_VERSION }}" "latest" | ||
mike deploy --push --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }}" | ||
# Set latest version as a default | ||
mike set-default --push latest | ||
- name: Publish docs to dev | ||
if: ${{ env.RELEASE_VERSION == 'dev' }} | ||
run: | | ||
rm -rf site | ||
mkdocs build | ||
mike deploy --push dev | ||
- name: Build API docs | ||
run: | | ||
rm -rf api | ||
npm run docs-generateApiDoc | ||
|
||
- name: Release API docs | ||
uses: peaceiris/actions-gh-pages@v3 | ||
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7 # v3.9.2 | ||
env: | ||
VERSION: ${{ inputs.version }} | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./api | ||
keep_files: true | ||
destination_dir: ${{ env.RELEASE_VERSION }}/api | ||
- name: Release API docs to latest if isRelease | ||
if: ${{ env.RELEASE_VERSION != 'dev' }} | ||
uses: peaceiris/actions-gh-pages@v3 | ||
destination_dir: ${{ env.VERSION }}/api | ||
- name: Release API docs to latest | ||
if: ${{ input.alias == 'latest' }} | ||
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./api | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.