Skip to content

chore(all): removed unused npm scripts + moved linting in PR checks #1125

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 15 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ms-azuretools.vscode-docker"
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm ci --foreground-scripts; cd examples/cdk; npm ci; cd ../sam; npm ci; cd ../../; npm run init-environment",
"postCreateCommand": "npm run setup-local",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ on:
types: [opened, synchronize]
jobs:
run-unit-tests:
uses: ./.github/workflows/reusable-run-unit-tests.yml
uses: ./.github/workflows/reusable-run-linting-check-and-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_call:

jobs:
run-unit-tests-on-utils:
run-linting-check-and-unit-tests-on-utilities:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
Expand All @@ -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
Expand Down Expand Up @@ -77,9 +77,11 @@ jobs:
# invalidated/discarded for all.
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/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
- name: Run linting
run: npm run lint
- name: Run tests
run: npm t
check-layer-publisher:
Expand All @@ -103,8 +105,12 @@ jobs:
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') }}
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/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
- name: Run linting
run: npm run lint
- name: Run tests
run: npm t
13 changes: 2 additions & 11 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@ tasks:
nvm use
# Install npm 8.x
npm i -g npm@next-8
# Install monorepo packages
npm ci --foreground-scripts
# Install CDK exampels dependencies
cd examples/cdk
npm ci
# Install SAM exampels dependencies
cd ../sam
npm ci
# Install AWS SAM CLI
wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
sudo ./sam-installation/install
rm -rf sam-installation aws-sam-cli-linux-*
cd ../../
# Setup husky hooks
npm run init-environment
# Install repo dependencies
npm run setup-local
vscode:
extensions:
- dbaeumer.vscode-eslint
Expand Down
8 changes: 7 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lerna-lint-fix
npm run lint-fix -ws
cd examples/sam && npm run lint-fix
cd ../..
cd examples/cdk && npm run lint-fix
cd ../..
cd layer-publisher && npm run lint-fix
cd ..
3 changes: 1 addition & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lerna-lint-fix
npm run test
npm t -ws
12 changes: 5 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ As mentioned before, tests are split into groups thanks to [jest-runner-groups](

To run unit tests, you can either use:

* npm task `lerna-test:unit` (`npm run lerna-test:unit`) in root folder to run them all
* npm task `test:unit` (`npm run test:unit`) in module folder (for example: `packages/metrics`) to run the module specific ones
* jest directly `npx jest --group=unit` in module folder to run the module specific ones (You can run selective tests by restricting the group to the one you want. For instance `npx jest --group=unit/metrics/class`)
* `npm test -ws` while in the root folder to run them all
* `npm test -w packages/metrics` while in the root folder to run the module specific ones

#### e2e tests

Expand Down Expand Up @@ -156,9 +155,8 @@ See `metrics/tests/e2e/basicFeatures.decorator.test.ts` as an example.

To run e2e tests, you can either use:

* npm task `lerna-test:e2e` (`npm run lerna-test:e2e`) in root folder
* npm task `test:e2e` (`npm run test:e2e`) in module folder (for example: `packages/metrics`) to run the module specific ones
* jest directly `npx jest --group=e2e` in module folder. (You can run selective tests by restricting the group to the one you want. For instance `npx jest --group=e2e/metrics/decorator`)
* `npm test:e2e -ws` while in the root folder to run them all
* `npm test:e2e -w packages/metrics` while in the root folder to run the module specific ones

Three important environment variables can be used:

Expand Down Expand Up @@ -200,7 +198,7 @@ As part of the repo you will find an examples folder at the root. This folder co

To test your updates with these examples, you just have to:

1. Build your local version of *aws-lambda-powertools-typescript* npm packages with `npm run lerna-package` while in the root folder
1. Build your local version of *aws-lambda-powertools-typescript* npm packages with `npm run package -ws` while in the root folder
2. Move to the examples folder of your choice
```sh
cd packages/examples/cdk
Expand Down
67 changes: 67 additions & 0 deletions examples/cdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module.exports = {
env: {
browser: false,
es2020: true,
jest: true,
node: true,
},
extends: [ 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended' ],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
settings: {
'import/resolver': {
node: {},
typescript: {
project: './tsconfig.es.json',
alwaysTryTypes: true,
},
},
},
rules: {
'@typescript-eslint/ban-ts-ignore': ['off'],
'@typescript-eslint/camelcase': ['off'],
'@typescript-eslint/explicit-function-return-type': [ 'error', { allowExpressions: true } ],
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/indent': [ 'error', 2, { SwitchCase: 1 } ],
'@typescript-eslint/interface-name-prefix': ['off'],
'@typescript-eslint/member-delimiter-style': [ 'error', { multiline: { delimiter: 'none' } } ],
'@typescript-eslint/member-ordering': [
'error',
{
default: {
memberTypes: [
'signature',
'public-field', // = ["public-static-field", "public-instance-field"]
'protected-field', // = ["protected-static-field", "protected-instance-field"]
'private-field', // = ["private-static-field", "private-instance-field"]
'constructor',
'public-method', // = ["public-static-method", "public-instance-method"]
'protected-method', // = ["protected-static-method", "protected-instance-method"]
'private-method', // = ["private-static-method", "private-instance-method"]
],
order: 'alphabetically',
},
},
],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-inferrable-types': ['off'],
'@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_' } ],
'@typescript-eslint/no-use-before-define': ['off'],
'@typescript-eslint/semi': [ 'error', 'always' ],
'array-bracket-spacing': [ 'error', 'always', { singleValue: false } ],
'arrow-body-style': [ 'error', 'as-needed' ],
'computed-property-spacing': [ 'error', 'never' ],
'func-style': [ 'warn', 'expression' ],
indent: [ 'error', 2, { SwitchCase: 1 } ],
'keyword-spacing': 'error',
'newline-before-return': 2,
'no-console': 0,
'no-multi-spaces': [ 'error', { ignoreEOLComments: false } ],
'no-multiple-empty-lines': [ 'error', { max: 1, maxBOF: 0 } ],
'no-throw-literal': 'error',
'object-curly-spacing': [ 'error', 'always' ],
'prefer-arrow-callback': 'error',
quotes: [ 'error', 'single', { allowTemplateLiterals: true } ],
semi: [ 'error', 'always' ]
},
};
1 change: 1 addition & 0 deletions examples/cdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.js
!.eslintrc.js
!jest.config.js
*.d.ts
node_modules
Expand Down
Loading