Skip to content

Commit c6622ad

Browse files
authored
feat (build): Add package size check in PR workflow (#878)
1 parent 510d31e commit c6622ad

File tree

9 files changed

+59
-1
lines changed

9 files changed

+59
-1
lines changed

Diff for: .github/workflows/pr_lint_and_test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ jobs:
6565
with:
6666
github-token: ${{ secrets.GITHUB_TOKEN }}
6767
lcov-file: ./coverage/lcov.info
68+
- name: Packages size report
69+
uses: flochaz/[email protected]
70+
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 }}

Diff for: examples/cdk/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"watch": "tsc -w",
1616
"test": "npm run test:unit",
1717
"package": "echo 'Not applicable'",
18+
"package-bundle": "echo 'Not applicable'",
1819
"test:unit": "npm run build && jest",
1920
"test:e2e": "echo 'To be implemented ...'",
2021
"version": "npm install @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] && git add package.json",

Diff for: examples/sam/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "sam build --beta-features",
1212
"test": "npm run test:unit",
1313
"package": "echo 'Not applicable'",
14+
"package-bundle": "echo 'Not applicable'",
1415
"test:unit": "npm run build && jest",
1516
"test:e2e": "echo 'To be implemented ...'",
1617
"version": "npm install @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] && git add package.json"

Diff for: package-bundler.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
5+
usage() {
6+
echo "Uber package Builder"
7+
echo "------------------------"
8+
echo "./package-bundler.sh NAME LOCAL_NPM_PACKAGE_LOCATION"
9+
echo ""
10+
}
11+
12+
13+
if [[ "$#" -lt 2 ]]; then
14+
usage
15+
exit 1
16+
fi
17+
18+
name=$(basename ${1})
19+
dist_folder="${2}"
20+
21+
echo "Will bundle $(ls ${dist_folder}) into ${dist_folder}/${name}.tgz"
22+
23+
output_folder="$(mktemp -d)"
24+
25+
docker_image="public.ecr.aws/sam/build-nodejs14.x:latest"
26+
volume_params="-v $output_folder:/bundle"
27+
28+
package_folder="nodejs/"
29+
mkdir -p "$output_folder/$package_folder"
30+
31+
cp -r "${2}" "$output_folder/$package_folder/"
32+
33+
install_command="pushd $package_folder; npm install --save ./*.tgz; popd"
34+
volume_params="$volume_params -v $HOME/.npmrc:/root/.npmrc"
35+
36+
zip_command="zip -r bundle.zip * && rm -rf $package_folder"
37+
38+
docker run --rm $volume_params -w "/bundle" "$docker_image" /bin/bash -c "$install_command && $zip_command"
39+
40+
mv "$output_folder/bundle.zip" "$dist_folder/$name.zip"
41+
42+
rm -rf $output_folder
43+
44+
echo "All done"

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lerna-test:unit": "lerna exec -- npm run test:unit",
2121
"lerna-test:e2e": "lerna exec -- npm run test:e2e",
2222
"lerna-package": "lerna exec -- npm run package",
23+
"lerna-package-bundle": "lerna exec -- npm run package-bundle",
2324
"lerna-build": "lerna exec -- tsc",
2425
"lerna-lint": "lerna exec -- eslint \"./{src,tests}/**/*.ts ./src/*.ts\"",
2526
"lerna-format": "lerna exec -- eslint --fix \"./{src,tests}/**/*.ts ./src/*.ts\"",

Diff for: packages/commons/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +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/",
2223
"prepare": "npm run build",
2324
"prepublishOnly": "npm test && npm run lint",
2425
"preversion": "npm run lint",

Diff for: packages/logger/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +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/",
2526
"prepare": "npm run build",
2627
"prepublishOnly": "npm test && npm run lint",
2728
"preversion": "npm run lint",

Diff for: packages/metrics/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +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/",
2526
"prepare": "npm run build",
2627
"prepublishOnly": "npm test && npm run lint",
2728
"preversion": "npm run lint",

Diff for: packages/tracer/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"preversion": "npm run lint",
2727
"version": "npm run format && git add -A src",
2828
"postversion": "git push && git push --tags",
29-
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/"
29+
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
30+
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/"
3031
},
3132
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/tracer#readme",
3233
"license": "MIT-0",

0 commit comments

Comments
 (0)