Skip to content

Commit 27ca202

Browse files
authored
chore(docs): bring examples into npm workspace (#1434)
* chore: added cdkk example to workspace * chore: added sam example to workspace * chore: update setup-local script * chore: ignored lock + removed version command * chore: update version command & moved definition to main package.json * chore: fixed cache key for examples * chore: bumped versions in sam example * chore: extracted node-cache steps * chore: extracted node-cache steps * chore: adapted custom action to all workflows * chore: fixed input
1 parent 160f539 commit 27ca202

17 files changed

+188
-27253
lines changed

Diff for: .github/actions/cached-node-modules/action.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: 'Cached Node Modules'
2+
description: 'A simple action to cache node_modules or install them if they are not cached'
3+
inputs:
4+
nodeVersion: # id of input
5+
description: 'Node.js version to use in the cache key'
6+
default: '18'
7+
outputs:
8+
cache-hit:
9+
description: "Whether the cache was hit or not"
10+
value: ${{ steps.cache-node-modules.outputs.cache-hit }}
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Cache node modules
15+
id: cache-node-modules
16+
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
17+
with:
18+
path: "./node_modules"
19+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
20+
# if one of them changes the cache is invalidated/discarded
21+
key: ${{ inputs.nodeVersion }}-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
22+
- name: Install dependencies
23+
# We can skip the installation if there was a cache hit
24+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
25+
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
26+
run: npm ci --foreground-scripts
27+
shell: bash
28+
- name: Build packages
29+
# If there's a cache hit we still need to manually build the packages
30+
# this would otherwise have been done automatically as a part of the
31+
# post-install npm hook
32+
if: steps.cache-node-modules.outputs.cache-hit == 'true'
33+
run: |
34+
npm run build -w packages/commons
35+
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
36+
shell: bash

Diff for: .github/workflows/make-release.yml

+10-21
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,20 @@ jobs:
2424
with:
2525
node-version: "18"
2626
cache: "npm"
27-
- name: Setup npm
28-
run: |
29-
npm i -g npm@next-8
30-
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
31-
- name: Cache node modules
32-
id: cache-node-modules
33-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
34-
with:
35-
path: "./node_modules"
36-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
37-
# if one of them changes the cache is invalidated/discarded
38-
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
39-
- name: Build packages
40-
run: |
41-
npm run build -w packages/commons
42-
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics & npm run build -w packages/parameters
43-
- name: "Version and publish"
44-
env:
45-
GH_TOKEN: ${{ secrets.GH_PUBLISH_TOKEN }}
27+
- name: Setup auth tokens
4628
run: |
4729
git config --global user.name 'github-actions[bot]'
4830
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
49-
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/$GITHUB_REPOSITORY
50-
npx lerna version --conventional-commits --force-publish --yes
31+
git remote set-url origin https://x-access-token:${{ secrets.GH_PUBLISH_TOKEN }}@github.com/$GITHUB_REPOSITORY
32+
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
33+
- name: Setup dependencies
34+
uses: ./.github/actions/cached-node-modules
35+
- name: Version
36+
run: |
37+
npm run version
5138
git push --tags
39+
- name: Publish to npm
40+
run: |
5241
npx lerna publish from-git --yes
5342
- name: Set release version
5443
id: set-release-version

Diff for: .github/workflows/publish_layer.yml

+2-13
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,8 @@ jobs:
4646
LATEST_TAG=$(git describe --tag --abbrev=0)
4747
RELEASE_TAG_VERSION=${RELEASE_INPUT:-$LATEST_TAG}
4848
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
49-
- name: Cache node modules
50-
id: cache-node-modules
51-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
52-
with:
53-
path: "./node_modules"
54-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
55-
# if one of them changes the cache is invalidated/discarded
56-
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
57-
- name: Install dependencies
58-
# We can skip the installation if there was a cache hit
59-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
60-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
61-
run: npm ci --foreground-scripts
49+
- name: Setup dependencies
50+
uses: ./.github/actions/cached-node-modules
6251
- name: Create layer files
6352
run: |
6453
export VERSION=$RELEASE_TAG_VERSION

Diff for: .github/workflows/reusable-publish-docs.yml

+2-21
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,8 @@ jobs:
3636
with:
3737
node-version: "18"
3838
cache: "npm"
39-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
40-
# if one of them changes the cache is invalidated/discarded
41-
- name: Cache node modules
42-
id: cache-node-modules
43-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
44-
with:
45-
path: "./node_modules"
46-
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
47-
- name: Install dependencies
48-
# We can skip the installation if there was a cache hit
49-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
50-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
51-
run: npm ci --foreground-scripts
52-
- name: Build packages
53-
# If there's a cache hit we still need to manually build the packages
54-
# this would otherwise have been done automatically as a part of the
55-
# post-install npm hook
56-
if: steps.cache-node-modules.outputs.cache-hit == 'true'
57-
run: |
58-
npm run build -w packages/commons
59-
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
39+
- name: Setup dependencies
40+
uses: ./.github/actions/cached-node-modules
6041
- name: Set up Python
6142
uses: actions/setup-python@v4
6243
with:

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

+10-71
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,11 @@ jobs:
2121
node-version: ${{ matrix.version }}
2222
cache: "npm"
2323
- name: Setup npm
24-
run: npm i -g npm@next-8
25-
- name: Cache node modules
26-
id: cache-node-modules
27-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
24+
run: npm i -g npm@latest
25+
- name: Setup dependencies
26+
uses: ./.github/actions/cached-node-modules
2827
with:
29-
path: "./node_modules"
30-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
31-
# if one of them changes the cache is invalidated/discarded
32-
key: ${{ matrix.version }}-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
33-
- name: Install dependencies
34-
# We can skip the installation if there was a cache hit
35-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
36-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
37-
run: npm ci --foreground-scripts
38-
- name: Build packages
39-
# If there's a cache hit we still need to manually build the packages
40-
# this would otherwise have been done automatically as a part of the
41-
# post-install npm hook
42-
if: steps.cache-node-modules.outputs.cache-hit == 'true'
43-
run: |
44-
npm run build -w packages/commons
45-
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
28+
nodeVersion: ${{ matrix.version }}
4629
- name: Run linting
4730
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency
4831
- name: Run unit tests
@@ -66,20 +49,8 @@ jobs:
6649
with:
6750
node-version: 18
6851
cache: "npm"
69-
- name: Cache node modules
70-
id: cache-node-modules
71-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
72-
with:
73-
path: "./examples/${{ matrix.example }}/node_modules"
74-
# Use the combo between example, name, and SHA-256 hash of all example lock files as cache key.
75-
# It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so
76-
# if any of the lock files (wich should be fairly similar anyway) changes the cache is
77-
# invalidated/discarded for all.
78-
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }}
79-
- name: Install dependencies
80-
# We can skip the installation if there was a cache hit
81-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
82-
run: npm ci
52+
- name: Setup dependencies
53+
uses: ./.github/actions/cached-node-modules
8354
- name: Run linting
8455
run: npm run lint
8556
- name: Run tests
@@ -96,19 +67,8 @@ jobs:
9667
with:
9768
node-version: 18
9869
cache: "npm"
99-
- name: Cache node modules
100-
id: cache-node-modules
101-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
102-
with:
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
108-
# We can skip the installation if there was a cache hit
109-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
110-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
111-
run: npm ci --foreground-scripts
70+
- name: Setup dependencies
71+
uses: ./.github/actions/cached-node-modules
11272
- name: Run linting
11373
run: npm run lint -w layers
11474
- name: Create layer files
@@ -129,28 +89,7 @@ jobs:
12989
with:
13090
node-version: 18
13191
cache: "npm"
132-
- name: Setup npm
133-
run: npm i -g npm@next-8
134-
- name: Cache node modules
135-
id: cache-node-modules
136-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
137-
with:
138-
path: "./node_modules"
139-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
140-
# if one of them changes the cache is invalidated/discarded
141-
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
142-
- name: Install dependencies
143-
# We can skip the installation if there was a cache hit
144-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
145-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
146-
run: npm ci --foreground-scripts
147-
- name: Build packages
148-
# If there's a cache hit we still need to manually build the packages
149-
# this would otherwise have been done automatically as a part of the
150-
# post-install npm hook
151-
if: steps.cache-node-modules.outputs.cache-hit == 'true'
152-
run: |
153-
npm run build -w packages/commons
154-
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
92+
- name: Setup dependencies
93+
uses: ./.github/actions/cached-node-modules
15594
- name: Run linting
15695
run: npm run lint -w docs/snippets

Diff for: .github/workflows/reusable_deploy_layer_stack.yml

+2-13
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,8 @@ jobs:
7070
uses: actions/setup-node@v3
7171
with:
7272
node-version: "18"
73-
- name: Cache node modules
74-
id: cache-node-modules
75-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
76-
with:
77-
path: "./node_modules"
78-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
79-
# if one of them changes the cache is invalidated/discarded
80-
key: 18-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
81-
- name: Install dependencies
82-
# We can skip the installation if there was a cache hit
83-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
84-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
85-
run: npm ci --foreground-scripts
73+
- name: Setup dependencies
74+
uses: ./.github/actions/cached-node-modules
8675
- name: Download artifact
8776
uses: actions/download-artifact@v3
8877
with:

Diff for: examples/cdk/.eslintrc.js

-67
This file was deleted.

Diff for: examples/cdk/.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ node_modules
77
# CDK asset staging directory
88
.cdk.staging
99
cdk.out
10-
lib
10+
lib
11+
# npm lock file - this is managed by the npm workspace
12+
package-lock.json

Diff for: examples/cdk/.npmignore

-6
This file was deleted.

0 commit comments

Comments
 (0)