-
Notifications
You must be signed in to change notification settings - Fork 154
174 lines (170 loc) · 5.88 KB
/
reusable-run-linting-check-and-unit-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Run unit tests
#
# PROCESS
#
# 1. Checkout code
# 2. Install dependencies & build project
# 3. Run linting
# 4. Run unit tests
#
# NOTES
# We create different jobs for different workspaces of the monorepo, since we have slightly different requirements for each.
# For example, the docs (`check-docs`), runs markdown linting, while the layer (`check-layer-publisher`), examples (`check-examples`),
# and code snippets (`check-docs-snippets`) jobs run linting and unit tests but only for the current LTS version of Node.js.
#
# For the Powertools for AWS main features (aka `packages/*`), instead we run linting and unit tests for all the supported
# versions of Node.js.
#
# Since #2938, we are in the process of improving our test suite, so we are gradually extracting the tests for each package
# from (`run-linting-check-and-unit-tests-on-utilities`) to their own job, so we can run them in parallel using the matrix
# strategy and reduce the time it takes to run the tests, as well as improve maintainer experience in case of failures.
#
# USAGE
#
# NOTE: meant to be called by ./.github/workflows/pr-run-linting-check-and-unit-tests.yml when a PR is opened or updated,
# or by ./.github/workflows/make-release.yml when a release is made.
#
on:
workflow_call:
permissions:
contents: read
jobs:
code-quality:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
strategy:
matrix:
version: [18, 20]
workspace: [
"packages/batch",
"packages/commons",
"packages/event-handler",
"packages/idempotency",
"packages/jmespath",
"packages/logger",
"packages/tracer",
"packages/parser",
]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup NodeJS
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.version }}
cache: "npm"
- name: Setup dependencies
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
with:
nodeVersion: ${{ matrix.version }}
- name: Linting
run: npm run lint -w ${{ matrix.workspace }}
- name: Unit tests
run: |
npm run test:unit:coverage -w ${{ matrix.workspace }}
npm run test:unit:types -w ${{ matrix.workspace }}
run-linting-check-and-unit-tests-on-utilities:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
strategy:
matrix:
version: [18, 20]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup NodeJS
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.version }}
cache: "npm"
- name: Setup dependencies
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
with:
nodeVersion: ${{ matrix.version }}
- name: Run linting
run: |
npm run lint -w packages/metrics \
-w packages/parameters
- name: Run unit tests
run: |
npm t -w packages/metrics \
-w packages/parameters
check-examples:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
strategy:
matrix:
example: ["app"]
fail-fast: false
defaults:
run:
working-directory: examples/${{ matrix.example }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup NodeJS
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
- name: Run linting
run: npm run lint
- name: Run tests
run: npm t
check-layer-publisher:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup NodeJS
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
- name: Run linting
run: npm run lint -w layers
- name: Run tests
run: npm run test:unit -w layers
check-docs-snippets:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup NodeJS
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
- name: Run linting
run: npm run lint -w examples/snippets
check-docs:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup NodeJS
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
- name: Run linting
run: npm run lint:markdown