1
- name : pr-lint-and-test
1
+ name : On PR code update
2
+
2
3
on :
3
4
pull_request :
4
5
types : [opened, synchronize]
5
6
jobs :
6
- on_push :
7
+ run-unit-tests-on-utils :
7
8
runs-on : ubuntu-latest
8
9
env :
9
10
NODE_ENV : dev
@@ -12,63 +13,70 @@ jobs:
12
13
version : [12, 14, 16]
13
14
fail-fast : false
14
15
steps :
15
- - uses : actions/checkout@v3
16
- - name : " Use NodeJS"
16
+ - name : Checkout code
17
+ uses : actions/checkout@v3
18
+ - name : Setup NodeJS
17
19
uses : actions/setup-node@v3
18
20
with :
19
21
node-version : ${{ matrix.version }}
20
-
22
+ cache : " npm"
23
+ - name : Setup npm
21
24
run : npm i -g npm@next-8
22
- - name : " Setup npm"
23
- run : |
24
- npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
25
- - name : Install monorepo packages
26
- # This installs all the dependencies of ./packages/*
25
+ - name : Cache node modules
26
+ id : cache-node-modules
27
+ uses : actions/cache@v3
28
+ 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-utils-node-modules-${{ hashFiles('./package-lock.json') }}
33
+ - name : Install dependencies
34
+ # We can skip the install if there was a cache hit
35
+ if : steps.cache-node-modules.outputs.cache-hit != 'true'
27
36
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
28
37
run : npm ci --foreground-scripts
29
- - name : Install CDK example packages
30
- # Since we are not managing the CDK examples with npm workspaces we install
31
- # the dependencies in a separate step
32
- working-directory : ./examples/cdk
33
- run : npm ci
34
- - name : " Setup SAM"
35
- # We use an ad-hoc action so we can specify the SAM CLI version
36
- uses : aws-actions/setup-sam@v2
37
- with :
38
- version : 1.49.0
39
- - name : Install SAM example packages
40
- # Since we are not managing the SAM examples with npm workspaces we install
41
- # the dependencies in a separate step
42
- working-directory : ./examples/sam
43
- run : npm ci
44
- - name : Run lint
45
- run : npm run lerna-lint
46
- - name : Run tests
47
- run : npm run lerna-test
48
- - name : Collate Coverage Reports
49
- if : ${{ github.actor != 'dependabot[bot]' }}
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
+ # postinstall npm hook
42
+ if : steps.cache-node-modules.outputs.cache-hit == 'true'
50
43
run : |
51
- for d in ./packages/*/ ; do
52
- mkdir -p coverage
53
- if [[ ! -f coverage/lcov.info ]]
54
- then
55
- continue
56
- fi
57
- filename="$d""coverage/lcov.info"
58
- targetSource="SF:""$d""src"
59
- sed "s|SF:src|$targetSource|g" $filename >> coverage/lcov.info
60
- done
61
- - name : Report Coverage
62
- # Dependabot user will only have read-only perms, so don't try to report coverage
63
- if : ${{ github.actor != 'dependabot[bot]' }}
64
-
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
46
+ - name : Lint
47
+ run : npm run lint -w packages/logger -w packages/tracer -w packages/metrics
48
+ - name : Run unit tests
49
+ run : npm t -w packages/logger -w packages/tracer -w packages/metrics
50
+ check-examples :
51
+ runs-on : ubuntu-latest
52
+ env :
53
+ NODE_ENV : dev
54
+ strategy :
55
+ matrix :
56
+ example : ["sam", "cdk"]
57
+ fail-fast : false
58
+ defaults :
59
+ run :
60
+ working-directory : examples/${{ matrix.example }}
61
+ steps :
62
+ - name : Checkout code
63
+ uses : actions/checkout@v3
64
+ - name : Setup NodeJS
65
+ uses : actions/setup-node@v3
65
66
with :
66
- github-token : ${{ secrets.GITHUB_TOKEN }}
67
- lcov-file : ./coverage/lcov.info
68
- - name : Packages size report
69
-
67
+ node-version : 16
68
+ cache : " npm"
69
+ - name : Cache node modules
70
+ id : cache-node-modules
71
+ uses : actions/cache@v3
70
72
with :
71
- build-command : mkdir dist && npm run lerna-package && npm run lerna-package-bundle && bash -c "mv ./packages/*/dist/* dist/" && ls dist
72
- dist-directory : /dist
73
- env :
74
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
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
+ run : npm ci
81
+ - name : Run tests
82
+ run : npm t
0 commit comments