Skip to content

Commit c672c40

Browse files
authored
chore(layers): moved layer-publisher into npm workspace (#1292)
* chore: moved layer-publisher into npm workspace * chore: fixed leftover command * refactor: layer publisher * refactor: layer publisher * refactor: layer publisher * refactor: layer publisher * refactor: layer publisher * refactor: layer publisher * refactor: layer publisher * tests: remove snapshots & added resource testing * chore: extracted script * chore: update path in cdk.json
1 parent 9942f07 commit c672c40

36 files changed

+525
-11791
lines changed

Diff for: .github/scripts/setup_tmp_layer_files.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
rm -rf tmp/nodejs
3+
mkdir -p tmp/nodejs
4+
cd tmp/nodejs
5+
npm init -y
6+
npm i \
7+
@aws-lambda-powertools/logger@$VERSION \
8+
@aws-lambda-powertools/metrics@$VERSION \
9+
@aws-lambda-powertools/tracer@$VERSION
10+
rm -rf node_modules/@types \
11+
package.json \
12+
package-lock.json
13+
cd ../..

Diff for: .github/workflows/publish_layer.yaml

+21-14
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
build-layer:
2424
runs-on: ubuntu-latest
2525
if: ${{ (github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch') }}
26-
defaults:
27-
run:
28-
working-directory: ./layer-publisher
2926
steps:
3027
- name: checkout
3128
uses: actions/checkout@v3
@@ -41,22 +38,32 @@ jobs:
4138
LATEST_TAG=$(git describe --tag --abbrev=0)
4239
RELEASE_TAG_VERSION=${RELEASE_INPUT:-$LATEST_TAG}
4340
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
44-
- name: install cdk and deps
45-
run: |
46-
npm install -g [email protected]
47-
cdk --version
48-
- name: install deps
41+
- name: Cache node modules
42+
id: cache-node-modules
43+
uses: actions/cache@v3
44+
with:
45+
path: "./node_modules"
46+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
47+
# if one of them changes the cache is invalidated/discarded
48+
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
49+
- name: Install dependencies
50+
# We can skip the installation if there was a cache hit
51+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
52+
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
53+
run: npm ci --foreground-scripts
54+
- name: Create layer files
4955
run: |
50-
npm ci
56+
export VERSION=$RELEASE_TAG_VERSION
57+
bash .github/scripts/setup_tmp_layer_files.sh
5158
- name: CDK build
52-
run: cdk synth --context PowerToolsPackageVersion=$RELEASE_TAG_VERSION -o cdk.out
59+
run: npm run cdk -w layers -- synth --context PowertoolsPackageVersion=$RELEASE_TAG_VERSION -o cdk.out
5360
- name: zip output
5461
run: zip -r cdk.out.zip cdk.out
5562
- name: Archive CDK artifacts
5663
uses: actions/upload-artifact@v3
5764
with:
58-
name: cdk-layer-artefact
59-
path: layer-publisher/cdk.out.zip
65+
name: cdk-layer-artifact
66+
path: layers/cdk.out.zip
6067

6168
# Deploy layer to all regions in beta account
6269
deploy-beta:
@@ -65,7 +72,7 @@ jobs:
6572
uses: ./.github/workflows/reusable_deploy_layer_stack.yml
6673
with:
6774
stage: "BETA"
68-
artefact-name: "cdk-layer-artefact"
75+
artifact-name: "cdk-layer-artifact"
6976
secrets:
7077
target-account-role: ${{ secrets.AWS_LAYERS_BETA_ROLE_ARN }}
7178

@@ -76,6 +83,6 @@ jobs:
7683
uses: ./.github/workflows/reusable_deploy_layer_stack.yml
7784
with:
7885
stage: "PROD"
79-
artefact-name: "cdk-layer-artefact"
86+
artifact-name: "cdk-layer-artifact"
8087
secrets:
8188
target-account-role: ${{ secrets.AWS_LAYERS_PROD_ROLE_ARN }}

Diff for: .github/workflows/reusable-run-linting-check-and-unit-tests.yml

+14-11
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ jobs:
8888
runs-on: ubuntu-latest
8989
env:
9090
NODE_ENV: dev
91-
defaults:
92-
run:
93-
working-directory: layer-publisher
9491
steps:
9592
- name: Checkout code
9693
uses: actions/checkout@v3
@@ -103,17 +100,23 @@ jobs:
103100
id: cache-node-modules
104101
uses: actions/cache@v3
105102
with:
106-
path: "./layer-publisher/node_modules"
107-
# Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key.
108-
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/package-lock.json') }}
109-
- name: Install Layer publisher
103+
path: "./node_modules"
104+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
105+
# if one of them changes the cache is invalidated/discarded
106+
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
107+
- name: Install dependencies
110108
# We can skip the installation if there was a cache hit
111109
if: steps.cache-node-modules.outputs.cache-hit != 'true'
112-
run: npm ci
110+
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
111+
run: npm ci --foreground-scripts
113112
- name: Run linting
114-
run: npm run lint
113+
run: npm run lint -w layers
114+
- name: Create layer files
115+
run: |
116+
export VERSION=latest
117+
bash .github/scripts/setup_tmp_layer_files.sh
115118
- name: Run tests
116-
run: npm t
119+
run: npm run test:unit -w layers
117120
check-docs-snippets:
118121
runs-on: ubuntu-latest
119122
env:
@@ -150,4 +153,4 @@ jobs:
150153
npm run build -w packages/commons
151154
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics & npm run build -w packages/parameters & npm run build -w packages/idempotency & npm run build -w docs/snippets
152155
- name: Run linting
153-
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency -w docs/snippets
156+
run: npm run lint -w docs/snippets

Diff for: .github/workflows/reusable_deploy_layer_stack.yml

+19-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
stage:
1111
required: true
1212
type: string
13-
artefact-name:
13+
artifact-name:
1414
required: true
1515
type: string
1616
secrets:
@@ -20,9 +20,6 @@ on:
2020
jobs:
2121
deploy-cdk-stack:
2222
runs-on: ubuntu-latest
23-
defaults:
24-
run:
25-
working-directory: ./layer-publisher
2623
strategy:
2724
fail-fast: false
2825
matrix:
@@ -63,19 +60,25 @@ jobs:
6360
uses: actions/setup-node@v3
6461
with:
6562
node-version: "18"
66-
- name: install cdk and deps
67-
run: |
68-
npm install -g [email protected]
69-
cdk --version
70-
- name: install deps
71-
run: |
72-
npm ci
63+
- name: Cache node modules
64+
id: cache-node-modules
65+
uses: actions/cache@v3
66+
with:
67+
path: "./node_modules"
68+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
69+
# if one of them changes the cache is invalidated/discarded
70+
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
71+
- name: Install dependencies
72+
# We can skip the installation if there was a cache hit
73+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
74+
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
75+
run: npm ci --foreground-scripts
7376
- name: Download artifact
7477
uses: actions/download-artifact@v3
7578
with:
76-
name: ${{ inputs.artefact-name }}
77-
path: layer-publisher
78-
- name: unzip artefact
79+
name: ${{ inputs.artifact-name }}
80+
path: layers
81+
- name: Unzip artifact
7982
run: unzip cdk.out.zip
80-
- name: CDK Deploy Layer
81-
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerPublisherStack' --require-approval never --verbose
83+
- name: Deploy Layer
84+
run: npm run cdk -w layers -- deploy --app cdk.out --context region=${{ matrix.region }} 'LayerPublisherStack' --require-approval never --verbose

Diff for: .github/workflows/run-e2e-tests.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ jobs:
122122
if: steps.cache-node-modules.outputs.cache-hit == 'true'
123123
run: |
124124
npm run build -w packages/commons
125-
- name: Run integration test on layers
125+
- name: Create layer files
126126
run: |
127-
npm ci --foreground-scripts
128-
RUNTIME=nodejs${{ matrix.version }}.x npm run test:e2e
129-
working-directory: layer-publisher
127+
export VERSION=latest
128+
bash .github/scripts/setup_tmp_layer_files.sh
129+
- name: Run integration test on layers
130+
run: RUNTIME=nodejs${{ matrix.version }}.x npm run test:e2e -w layers

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ site
4242

4343
# SAM Example copies files
4444
/examples/sam/src/handlers/*
45-
!/examples/sam/src/handlers/COPY_LAMBDA_FUNCTIONS_HERE
45+
!/examples/sam/src/handlers/COPY_LAMBDA_FUNCTIONS_HERE
46+
47+
# Layer temp files
48+
tmp

Diff for: .husky/pre-commit

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ npm run lint-fix -ws
55
cd examples/sam && npm run lint-fix
66
cd ../..
77
cd examples/cdk && npm run lint-fix
8-
cd ../..
9-
cd layer-publisher && npm run lint-fix
10-
cd ..
8+
cd ../..

Diff for: .husky/pre-push

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm t -ws
4+
npm t \
5+
-w packages/commons && \
6+
-w packages/logger && \
7+
-w packages/metrics && \
8+
-w packages/tracer && \
9+
-w packages/idempotency && \
10+
-w packages/parameters

Diff for: layer-publisher/jest.config.js

-8
This file was deleted.

0 commit comments

Comments
 (0)