Skip to content

Commit

Permalink
feat (build): Add package size check in PR workflow (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
flochaz authored and dreamorosi committed Jul 21, 2022
1 parent 4427e82 commit 38b893f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/pr_lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage/lcov.info
- name: Packages size report
uses: flochaz/pkg-size-action@v1.2.12
with:
build-command: mkdir dist && npm run lerna-package && npm run lerna-package-bundle && bash -c "mv ./packages/*/dist/* dist/" && ls dist
dist-directory: /dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions examples/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"watch": "tsc -w",
"test": "npm run test:unit",
"package": "echo 'Not applicable'",
"package-bundle": "echo 'Not applicable'",
"test:unit": "npm run build && jest",
"test:e2e": "echo 'To be implemented ...'",
"version": "npm install @aws-lambda-powertools/logger@0.7.0 @aws-lambda-powertools/tracer@0.7.0 @aws-lambda-powertools/metrics@0.7.0 && git add package.json",
Expand Down
1 change: 1 addition & 0 deletions examples/sam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build": "sam build --beta-features",
"test": "npm run test:unit",
"package": "echo 'Not applicable'",
"package-bundle": "echo 'Not applicable'",
"test:unit": "npm run build && jest",
"test:e2e": "echo 'To be implemented ...'",
"version": "npm install @aws-lambda-powertools/logger@0.7.0 @aws-lambda-powertools/tracer@0.7.0 @aws-lambda-powertools/metrics@0.7.0 && git add package.json"
Expand Down
44 changes: 44 additions & 0 deletions package-bundler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -e


usage() {
echo "Uber package Builder"
echo "------------------------"
echo "./package-bundler.sh NAME LOCAL_NPM_PACKAGE_LOCATION"
echo ""
}


if [[ "$#" -lt 2 ]]; then
usage
exit 1
fi

name=$(basename ${1})
dist_folder="${2}"

echo "Will bundle $(ls ${dist_folder}) into ${dist_folder}/${name}.tgz"

output_folder="$(mktemp -d)"

docker_image="public.ecr.aws/sam/build-nodejs14.x:latest"
volume_params="-v $output_folder:/bundle"

package_folder="nodejs/"
mkdir -p "$output_folder/$package_folder"

cp -r "${2}" "$output_folder/$package_folder/"

install_command="pushd $package_folder; npm install --save ./*.tgz; popd"
volume_params="$volume_params -v $HOME/.npmrc:/root/.npmrc"

zip_command="zip -r bundle.zip * && rm -rf $package_folder"

docker run --rm $volume_params -w "/bundle" "$docker_image" /bin/bash -c "$install_command && $zip_command"

mv "$output_folder/bundle.zip" "$dist_folder/$name.zip"

rm -rf $output_folder

echo "All done"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"lerna-test:unit": "lerna exec -- npm run test:unit",
"lerna-test:e2e": "lerna exec -- npm run test:e2e",
"lerna-package": "lerna exec -- npm run package",
"lerna-package-bundle": "lerna exec -- npm run package-bundle",
"lerna-build": "lerna exec -- tsc",
"lerna-lint": "lerna exec -- eslint \"./{src,tests}/**/*.ts ./src/*.ts\"",
"lerna-format": "lerna exec -- eslint --fix \"./{src,tests}/**/*.ts ./src/*.ts\"",
Expand Down
1 change: 1 addition & 0 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
Expand Down
1 change: 1 addition & 0 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
Expand Down
1 change: 1 addition & 0 deletions packages/metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
Expand Down
3 changes: 2 additions & 1 deletion packages/tracer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags",
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/"
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/"
},
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/tracer#readme",
"license": "MIT-0",
Expand Down

0 comments on commit 38b893f

Please sign in to comment.