Skip to content

chore(build): broke up pr workflow & measure package size #1031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/measure-packages-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Measure packages size

on:
workflow_dispatch:
inputs:
prNumber:
description: "PR Number"
required: true

jobs:
measure-utils-sizes:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
PR_NUMBER: ${{ inputs.prNumber }}
steps:
# Since we are manually triggering the workflow the previous checkout has the main branch. In order to checkout the branch/code of the PR
# we need first to use the PR number to retrieve the PR SHA number. This means we need three steps to: checkout the repo,
# run a custom script to get the SHA, and then finally checkout the PR branch
- name: Checkout Repo
uses: actions/checkout@v3
- name: Extract PR details
id: extract_PR_details
uses: actions/github-script@v6
with:
script: |
const script = require('.github/scripts/get_pr_info.js');
await script({github, context, core});
- name: Checkout PR code
uses: actions/checkout@v3
with:
ref: ${{ steps.extract_PR_details.outputs.headSHA }}
- name: Packages size report
uses: flochaz/[email protected]
with:
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
dist-directory: /dist
pr-number: ${{ inputs.prNumber }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114 changes: 61 additions & 53 deletions .github/workflows/pr_lint_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: pr-lint-and-test
name: On PR code update

on:
pull_request:
types: [opened, synchronize]
jobs:
on_push:
run-unit-tests-on-utils:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
Expand All @@ -12,63 +13,70 @@ jobs:
version: [12, 14, 16]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: "Use NodeJS"
- name: Checkout code
uses: actions/checkout@v3
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}
- name: Install [email protected]
cache: "npm"
- name: Setup npm
run: npm i -g npm@next-8
- name: "Setup npm"
run: |
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
- name: Install monorepo packages
# This installs all the dependencies of ./packages/*
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: "./node_modules"
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
# if one of them changes the cache is invalidated/discarded
key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
- name: Install dependencies
# We can skip the install if there was a cache hit
if: steps.cache-node-modules.outputs.cache-hit != 'true'
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: Install CDK example packages
# Since we are not managing the CDK examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/cdk
run: npm ci
- name: "Setup SAM"
# We use an ad-hoc action so we can specify the SAM CLI version
uses: aws-actions/setup-sam@v2
with:
version: 1.49.0
- name: Install SAM example packages
# Since we are not managing the SAM examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/sam
run: npm ci
- name: Run lint
run: npm run lerna-lint
- name: Run tests
run: npm run lerna-test
- name: Collate Coverage Reports
if: ${{ github.actor != 'dependabot[bot]' }}
- name: Build packages
# If there's a cache hit we still need to manually build the packages
# this would otherwise have been done automatically as a part of the
# postinstall npm hook
if: steps.cache-node-modules.outputs.cache-hit == 'true'
run: |
for d in ./packages/*/ ; do
mkdir -p coverage
if [[ ! -f coverage/lcov.info ]]
then
continue
fi
filename="$d""coverage/lcov.info"
targetSource="SF:""$d""src"
sed "s|SF:src|$targetSource|g" $filename >> coverage/lcov.info
done
- name: Report Coverage
#Dependabot user will only have read-only perms, so don't try to report coverage
if: ${{ github.actor != 'dependabot[bot]' }}
uses: romeovs/[email protected]
npm run build -w packages/commons
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
- name: Lint
run: npm run lint -w packages/logger -w packages/tracer -w packages/metrics
- name: Run unit tests
run: npm t -w packages/logger -w packages/tracer -w packages/metrics
check-examples:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
strategy:
matrix:
example: ["sam", "cdk"]
fail-fast: false
defaults:
run:
working-directory: examples/${{ matrix.example }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage/lcov.info
- name: Packages size report
uses: flochaz/[email protected]
node-version: 16
cache: "npm"
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v3
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 }}
path: "./examples/${{ matrix.example }}/node_modules"
# Use the combo between example, name, and SHA-256 hash of all example lock files as cache key.
# It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so
# if any of the lock files (wich should be fairly similar anyway) changes the cache is
# invalidated/discarded for all.
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }}
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm t
23 changes: 22 additions & 1 deletion examples/sam/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/sam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"devDependencies": {
"@types/aws-lambda": "^8.10.86",
"@types/jest": "^27.5.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is needed because we are now running the tests outside of the lerna scope. For this reason the dependency (which is present in both the examples/cdk and the main package) is also needed here now.

"@types/node": "18.0.0",
"esbuild": "^0.14.23",
"eslint": "^8.4.0",
Expand All @@ -32,4 +33,4 @@
"@aws-lambda-powertools/tracer": "^1.0.1",
"aws-sdk": "^2.1122.0"
}
}
}
4 changes: 2 additions & 2 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +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/",
"package-bundle": "../../package-bundler.sh commons-bundle ./dist",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
Expand Down Expand Up @@ -48,4 +48,4 @@
"serverless",
"nodejs"
]
}
}
4 changes: 2 additions & 2 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +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/",
"package-bundle": "../../package-bundler.sh logger-bundle ./dist",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
Expand Down Expand Up @@ -64,4 +64,4 @@
"serverless",
"nodejs"
]
}
}
4 changes: 2 additions & 2 deletions packages/metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +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/",
"package-bundle": "../../package-bundler.sh metrics-bundle ./dist",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
Expand Down Expand Up @@ -59,4 +59,4 @@
"serverless",
"nodejs"
]
}
}
4 changes: 2 additions & 2 deletions packages/tracer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags",
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
"package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/"
"package-bundle": "../../package-bundler.sh tracer-bundle ./dist"
},
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/tracer#readme",
"license": "MIT-0",
Expand Down Expand Up @@ -62,4 +62,4 @@
"serverless",
"nodejs"
]
}
}