Skip to content

Commit 4a1c436

Browse files
authored
chore(build): broke up pr workflow & measure package size (#1031)
* chore: broke up pr workflow & measure package size * chore: explicitly set packages where to run cmds * fix: added missing dependency to examples/sam * added cache in workflow * chore: updated workflow + removed env var from command * chore: updated action version * fix: removed redundant env variable
1 parent 6fe48ba commit 4a1c436

File tree

8 files changed

+133
-63
lines changed

8 files changed

+133
-63
lines changed

Diff for: .github/workflows/measure-packages-size.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Measure packages size
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
prNumber:
7+
description: "PR Number"
8+
required: true
9+
10+
jobs:
11+
measure-utils-sizes:
12+
runs-on: ubuntu-latest
13+
env:
14+
NODE_ENV: dev
15+
PR_NUMBER: ${{ inputs.prNumber }}
16+
steps:
17+
# Since we are manually triggering the workflow the previous checkout has the main branch. In order to checkout the branch/code of the PR
18+
# we need first to use the PR number to retrieve the PR SHA number. This means we need three steps to: checkout the repo,
19+
# run a custom script to get the SHA, and then finally checkout the PR branch
20+
- name: Checkout Repo
21+
uses: actions/checkout@v3
22+
- name: Extract PR details
23+
id: extract_PR_details
24+
uses: actions/github-script@v6
25+
with:
26+
script: |
27+
const script = require('.github/scripts/get_pr_info.js');
28+
await script({github, context, core});
29+
- name: Checkout PR code
30+
uses: actions/checkout@v3
31+
with:
32+
ref: ${{ steps.extract_PR_details.outputs.headSHA }}
33+
- name: Packages size report
34+
uses: flochaz/[email protected]
35+
with:
36+
build-command: mkdir dist && npm run package -w packages/logger -w packages/tracer -w packages/metrics -w packages/commons && npm run package-bundle -w packages/logger -w packages/tracer -w packages/metrics -w packages/commons && bash -c "mv ./packages/*/dist/* dist/" && ls dist
37+
dist-directory: /dist
38+
pr-number: ${{ inputs.prNumber }}
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: .github/workflows/pr_lint_and_test.yml

+61-53
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
name: pr-lint-and-test
1+
name: On PR code update
2+
23
on:
34
pull_request:
45
types: [opened, synchronize]
56
jobs:
6-
on_push:
7+
run-unit-tests-on-utils:
78
runs-on: ubuntu-latest
89
env:
910
NODE_ENV: dev
@@ -12,63 +13,70 @@ jobs:
1213
version: [12, 14, 16]
1314
fail-fast: false
1415
steps:
15-
- uses: actions/checkout@v3
16-
- name: "Use NodeJS"
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
- name: Setup NodeJS
1719
uses: actions/setup-node@v3
1820
with:
1921
node-version: ${{ matrix.version }}
20-
- name: Install [email protected]
22+
cache: "npm"
23+
- name: Setup npm
2124
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'
2736
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
2837
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'
5043
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-
uses: romeovs/[email protected]
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
6566
with:
66-
github-token: ${{ secrets.GITHUB_TOKEN }}
67-
lcov-file: ./coverage/lcov.info
68-
- name: Packages size report
69-
uses: flochaz/[email protected]
67+
node-version: 16
68+
cache: "npm"
69+
- name: Cache node modules
70+
id: cache-node-modules
71+
uses: actions/cache@v3
7072
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

Diff for: examples/sam/package-lock.json

+22-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/sam/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"devDependencies": {
2020
"@types/aws-lambda": "^8.10.86",
21+
"@types/jest": "^27.5.2",
2122
"@types/node": "18.0.0",
2223
"esbuild": "^0.14.23",
2324
"eslint": "^8.4.0",
@@ -32,4 +33,4 @@
3233
"@aws-lambda-powertools/tracer": "^1.0.1",
3334
"aws-sdk": "^2.1122.0"
3435
}
35-
}
36+
}

Diff for: packages/commons/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2020
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2121
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
22-
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/",
22+
"package-bundle": "../../package-bundler.sh commons-bundle ./dist",
2323
"prepare": "npm run build",
2424
"prepublishOnly": "npm test && npm run lint",
2525
"preversion": "npm run lint",
@@ -48,4 +48,4 @@
4848
"serverless",
4949
"nodejs"
5050
]
51-
}
51+
}

Diff for: packages/logger/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2323
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2424
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
25-
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/",
25+
"package-bundle": "../../package-bundler.sh logger-bundle ./dist",
2626
"prepare": "npm run build",
2727
"prepublishOnly": "npm test && npm run lint",
2828
"preversion": "npm run lint",
@@ -64,4 +64,4 @@
6464
"serverless",
6565
"nodejs"
6666
]
67-
}
67+
}

Diff for: packages/metrics/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2323
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2424
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
25-
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/",
25+
"package-bundle": "../../package-bundler.sh metrics-bundle ./dist",
2626
"prepare": "npm run build",
2727
"prepublishOnly": "npm test && npm run lint",
2828
"preversion": "npm run lint",
@@ -59,4 +59,4 @@
5959
"serverless",
6060
"nodejs"
6161
]
62-
}
62+
}

Diff for: packages/tracer/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"version": "npm run format && git add -A src",
2828
"postversion": "git push && git push --tags",
2929
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
30-
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/"
30+
"package-bundle": "../../package-bundler.sh tracer-bundle ./dist"
3131
},
3232
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/tracer#readme",
3333
"license": "MIT-0",
@@ -62,4 +62,4 @@
6262
"serverless",
6363
"nodejs"
6464
]
65-
}
65+
}

0 commit comments

Comments
 (0)