diff --git a/.github/workflows/pr-run-linting-check-and-unit-tests.yml b/.github/workflows/pr-run-linting-check-and-unit-tests.yml new file mode 100644 index 0000000000..f834476ec6 --- /dev/null +++ b/.github/workflows/pr-run-linting-check-and-unit-tests.yml @@ -0,0 +1,8 @@ +name: On PR code update + +on: + pull_request: + types: [opened, synchronize] +jobs: + run-linting-check-and-unit-tests: + uses: ./.github/workflows/reusable-run-linting-check-and-unit-tests.yml diff --git a/.github/workflows/pr_lint_and_test.yml b/.github/workflows/pr_lint_and_test.yml deleted file mode 100644 index 640395e70b..0000000000 --- a/.github/workflows/pr_lint_and_test.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: On PR code update - -on: - pull_request: - types: [opened, synchronize] -jobs: - run-unit-tests: - uses: ./.github/workflows/reusable-run-unit-tests.yml diff --git a/.github/workflows/reusable-run-unit-tests.yml b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml similarity index 66% rename from .github/workflows/reusable-run-unit-tests.yml rename to .github/workflows/reusable-run-linting-check-and-unit-tests.yml index b2e29ce068..6777b93ebb 100644 --- a/.github/workflows/reusable-run-unit-tests.yml +++ b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml @@ -4,7 +4,7 @@ on: workflow_call: jobs: - run-unit-tests-on-utils: + run-linting-check-and-unit-tests: runs-on: ubuntu-latest env: NODE_ENV: dev @@ -29,21 +29,21 @@ jobs: 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') }} + key: ${{ matrix.version }}-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }} - name: Install dependencies - # We can skip the install if there was a cache hit + # We can skip the installation 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: 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 + # post-install npm hook if: steps.cache-node-modules.outputs.cache-hit == 'true' run: | 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 + - name: Run linting run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics - name: Run unit tests run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics @@ -55,9 +55,6 @@ jobs: matrix: example: ["sam", "cdk"] fail-fast: false - defaults: - run: - working-directory: examples/${{ matrix.example }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -70,25 +67,20 @@ jobs: id: cache-node-modules uses: actions/cache@v3 with: - 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') }} + path: "./node_modules" + key: cache-node-modules-${{ hashFiles('./package-lock.json') }} - name: Install dependencies - # We can skip the install if there was a cache hit + # We can skip the installation if there was a cache hit if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: npm ci + run: npm ci --foreground-scripts + - name: Run linting + run: npm run lerna -- run lint --scope ${{ matrix.example }}-example - name: Run tests - run: npm t + run: npm run lerna -- run test --scope ${{ matrix.example }}-example check-layer-publisher: runs-on: ubuntu-latest env: NODE_ENV: dev - defaults: - run: - working-directory: layer-publisher steps: - name: Checkout code uses: actions/checkout@v3 @@ -101,10 +93,11 @@ jobs: id: cache-node-modules uses: actions/cache@v3 with: - path: "./layer-publisher/node_modules" - # Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key. - key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }} + path: "./node_modules" + key: cache-node-modules-${{ hashFiles('./package-lock.json') }} - name: Install Layer publisher - # We can skip the install if there was a cache hit + # We can skip the installation if there was a cache hit if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: npm ci + run: npm ci --foreground-scripts + - name: Run linting + run: npm run lerna -- run lint --scope layer-publisher \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push index 78f6873145..d1096ab18a 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,5 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npm run lerna-lint-fix npm run test diff --git a/examples/cdk/package.json b/examples/cdk/package.json index cce5d95777..2f87d83e51 100644 --- a/examples/cdk/package.json +++ b/examples/cdk/package.json @@ -1,5 +1,5 @@ { - "name": "cdk-app", + "name": "cdk-example", "version": "1.2.1", "author": { "name": "Amazon Web Services", diff --git a/examples/sam/package.json b/examples/sam/package.json index 693389d09d..b6f87dde35 100644 --- a/examples/sam/package.json +++ b/examples/sam/package.json @@ -1,5 +1,5 @@ { - "name": "powertools-typescript-sam-example", + "name": "sam-example", "version": "1.2.1", "author": { "name": "Amazon Web Services", diff --git a/layer-publisher/src/layer-publisher-stack.ts b/layer-publisher/src/layer-publisher-stack.ts index ec4545733d..99b628d0a8 100644 --- a/layer-publisher/src/layer-publisher-stack.ts +++ b/layer-publisher/src/layer-publisher-stack.ts @@ -1,6 +1,8 @@ import { CfnOutput, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import * as lambda from 'aws-cdk-lib/aws-lambda'; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; import { CfnLayerVersionPermission } from 'aws-cdk-lib/aws-lambda'; diff --git a/package.json b/package.json index e0a5025392..9d99cb0adf 100644 --- a/package.json +++ b/package.json @@ -15,20 +15,18 @@ "test": "npm run lerna-test", "commit": "commit", "package": "npm run package", - "setup-local": "npm ci --foreground-scripts && cd examples/cdk && npm ci && cd ../.. && cd examples/sam && npm ci && cd ../.. && npm run init-environment", + "setup-local": "npm ci --foreground-scripts && cd examples/cdk && npm ci && cd ../../examples/sam && npm ci && cd ../../layer-publisher && npm ci && cd ../.. && npm run init-environment", + "lerna" : "lerna", "lerna-test": "lerna exec -- npm run test", "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-build": "lerna exec -- npm run build", "lerna-lint": "lerna exec -- npm run lint", "lerna-lint-fix": "lerna exec -- npm run lint-fix", "lerna-prepare": "lerna exec -- npm run build", - "lerna-prepublishOnly": "lerna exec -- npm test && lerna exec -- npm run lint", - "lerna-preversion": "lerna exec -- npm run lint", - "lerna-version": "lerna exec -- npm run format && git add -A src", - "postversion": "git push && git push --tags", + "postversion": "git push --tags", "docs-website-build-run": "npm run docs-buildDockerImage && npm run docs-runLocalDocker", "docs-buildDockerImage": "docker build -t powertool-typescript/docs ./docs/", "docs-runLocalDocker": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs powertool-typescript/docs", diff --git a/packages/commons/package.json b/packages/commons/package.json index a24ab07859..32329528f2 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -21,10 +21,7 @@ "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", "package-bundle": "../../package-bundler.sh commons-bundle ./dist", "prepare": "npm run build", - "prepublishOnly": "npm test && npm run lint", - "preversion": "npm run lint", - "version": "npm run format && git add -A src", - "postversion": "git push && git push --tags" + "postversion": "git push --tags" }, "homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/metrics#readme", "license": "MIT-0", diff --git a/packages/idempotency/package.json b/packages/idempotency/package.json index 60fca20565..bc6736355e 100644 --- a/packages/idempotency/package.json +++ b/packages/idempotency/package.json @@ -24,10 +24,7 @@ "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", "package-bundle": "../../package-bundler.sh logger-bundle ./dist", "prepare": "npm run build", - "prepublishOnly": "npm test && npm run lint", - "preversion": "npm run lint", - "version": "npm run format && git add -A src", - "postversion": "git push && git push --tags" + "postversion": "git push --tags" }, "homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/idempotency#readme", "license": "MIT", diff --git a/packages/logger/package.json b/packages/logger/package.json index f646569cd9..015e757324 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -24,10 +24,7 @@ "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", "package-bundle": "../../package-bundler.sh logger-bundle ./dist", "prepare": "npm run build", - "prepublishOnly": "npm test && npm run lint", - "preversion": "npm run lint", - "version": "npm run format && git add -A src", - "postversion": "git push && git push --tags" + "postversion": "git push --tags" }, "homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/logging#readme", "license": "MIT", diff --git a/packages/metrics/package.json b/packages/metrics/package.json index ec26a65c45..997aaa25f0 100644 --- a/packages/metrics/package.json +++ b/packages/metrics/package.json @@ -24,10 +24,7 @@ "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", "package-bundle": "../../package-bundler.sh metrics-bundle ./dist", "prepare": "npm run build", - "prepublishOnly": "npm test && npm run lint", - "preversion": "npm run lint", - "version": "npm run format && git add -A src", - "postversion": "git push && git push --tags" + "postversion": "git push --tags" }, "homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/metrics#readme", "license": "MIT-0", diff --git a/packages/tracer/package.json b/packages/tracer/package.json index 93708217e0..bf39bd55f0 100644 --- a/packages/tracer/package.json +++ b/packages/tracer/package.json @@ -22,10 +22,7 @@ "lint": "eslint --ext .ts --no-error-on-unmatched-pattern src tests", "lint-fix": "eslint --fix --ext .ts --no-error-on-unmatched-pattern src tests", "prepare": "npm run build", - "prepublishOnly": "npm test && npm run lint", - "preversion": "npm run lint", - "version": "npm run format && git add -A src", - "postversion": "git push && git push --tags", + "postversion": "git push --tags", "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", "package-bundle": "../../package-bundler.sh tracer-bundle ./dist" },