Skip to content

Commit df03119

Browse files
committed
chore(docs): output the Layer ARN to a artifact
1 parent a12e134 commit df03119

File tree

5 files changed

+137
-442
lines changed

5 files changed

+137
-442
lines changed

Diff for: .github/workflows/reusable_deploy_layer_stack.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ jobs:
9494
- name: unzip artefact
9595
run: unzip cdk.out.zip
9696
- name: CDK Deploy Layer
97-
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerStack' --require-approval never --verbose
97+
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerStack' --require-approval never --verbose --outputs-file cdk-outputs.json
98+
- name: Store latest layer ARN
99+
if: ${{ inputs.stage == 'PROD' }}
100+
run: jq -c '.LayerStack.LatestLayerArn' cdk-outputs.json > cdk-layer-stack-${{ matrix.region }}-layer-version.txt
98101
- name: CDK Deploy Canary
99102
run: cdk deploy --app cdk.out --context region=${{ matrix.region}} --parameters DeployStage="${{ inputs.stage }}" 'CanaryStack' --require-approval never --verbose
103+
- name: Save layer stack ARN artifact
104+
uses: actions/upload-artifacts@v3
105+
with:
106+
name: cdk-layer-stack
107+
path: cdk-layer-stack*

Diff for: docs/plugins/lambda_layer_version.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import re
3+
from pathlib import Path
4+
5+
from mkdocs.config import Config
6+
from mkdocs.structure.files import Files
7+
from mkdocs.structure.pages import Page
8+
9+
10+
def inject(markdown: str, page: Page, config: Config, files: Files):
11+
if not page.is_homepage:
12+
return markdown
13+
14+
# Try to see if we have a cdk-layer-stack directory.
15+
# This is created during the layer build, saved as an artifact, and downloaded before the jobs runs
16+
if not os.path.exists("cdk-layer-stack"):
17+
print("No cdk-layer-stack directory found, not replacing lambda layer versions")
18+
return markdown
19+
20+
# For each cdk output file, replace all the lambda layer occurrences in the docs
21+
files = Path("cdk-layer-stack").glob("*")
22+
for cdk_file in files:
23+
with open(cdk_file, "r") as f:
24+
layer_version_arn = f.readlines()[0].strip()
25+
layer_version_prefix = ":".join(layer_version_arn.split(":")[:-1])
26+
27+
# replace the prefix with the new version
28+
markdown = re.sub(rf"{layer_version_prefix}:\d+", layer_version_arn, markdown)
29+
30+
return markdown

Diff for: mkdocs.yml

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ copyright: Copyright © 2022 Amazon Web Services
8989
plugins:
9090
- git-revision-date
9191
- search
92+
- mkdocs-simple-hooks:
93+
hooks:
94+
on_page_markdown: "docs.plugins.lambda_layer_version:inject"
9295

9396
extra_css:
9497
- stylesheets/extra.css

0 commit comments

Comments
 (0)