Skip to content

Commit 1d76c37

Browse files
authored
Merge branch 'aws:master' into master
2 parents b3ade09 + 2349b6e commit 1d76c37

File tree

232 files changed

+8360
-2828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+8360
-2828
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
## Problem
22

3+
34
## Solution
45

5-
<!---
6-
REMINDER:
7-
- Read CONTRIBUTING.md first.
8-
- Add test coverage for your changes.
9-
- Update the changelog using `npm run newChange`.
10-
- Link to related issues/commits.
11-
- Testing: how did you test your changes?
12-
- Screenshots (if the pull request is related to UI/UX then please include light and dark theme screenshots)
13-
-->
146

15-
## License
7+
---
8+
9+
<!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md -->
1610

17-
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
11+
License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

.github/workflows/lintcommit.js

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// Checks that a PR title conforms to our custom flavor of "conventional commits"
2+
// (https://www.conventionalcommits.org/).
3+
//
4+
// To run self-tests, simply run this script:
5+
//
6+
// node lintcommit.js test
7+
//
8+
// TODO: "PR must describe Problem in a concise way, and Solution".
9+
// TODO: this script intentionally avoids github APIs so that it is locally-debuggable, but if those
10+
// are needed, use actions/github-script as described in: https://github.com/actions/github-script?tab=readme-ov-file#run-a-separate-file
11+
//
12+
13+
const fs = require('fs')
14+
// This script intentionally avoids github APIs so that:
15+
// 1. it is locally-debuggable
16+
// 2. the CI job is fast ("npm install" is slow)
17+
// But if we still want to use github API, we can keep it fast by using `actions/github-script` as
18+
// described in: https://github.com/actions/github-script?tab=readme-ov-file#run-a-separate-file
19+
//
20+
// const core = require('@actions/core')
21+
// const github = require('@actions/github')
22+
23+
const types = new Set([
24+
'build',
25+
// Don't allow "chore" because it's over-used.
26+
// Instead, add a new type if absolutely needed (if the existing ones can't possibly apply).
27+
// 'chore',
28+
'ci',
29+
'config',
30+
'deps',
31+
'docs',
32+
'feat',
33+
'fix',
34+
'perf',
35+
'refactor',
36+
'revert',
37+
'style',
38+
'telemetry',
39+
'test',
40+
'types',
41+
])
42+
43+
// TODO: Validate against this once we are satisfied with this list.
44+
const scopes = new Set([
45+
'amazonq',
46+
'core',
47+
'explorer',
48+
'lambda',
49+
'logs',
50+
'redshift',
51+
'q-chat',
52+
'q-featuredev',
53+
'q-inlinechat',
54+
'q-transform',
55+
'sam',
56+
's3',
57+
'telemetry',
58+
'toolkit',
59+
'ui',
60+
])
61+
void scopes
62+
63+
/**
64+
* Checks that a pull request title, or commit message subject, follows the expected format:
65+
*
66+
* type(scope): message
67+
*
68+
* Returns undefined if `title` is valid, else an error message.
69+
*/
70+
function validateTitle(title) {
71+
const parts = title.split(':')
72+
const subject = parts.slice(1).join(':').trim()
73+
74+
if (title.startsWith('Merge')) {
75+
return undefined
76+
}
77+
78+
if (parts.length < 2) {
79+
return 'missing colon (:) char'
80+
}
81+
82+
const typeScope = parts[0]
83+
84+
const [type, scope] = typeScope.split(/\(([^)]+)\)$/)
85+
86+
if (/\s+/.test(type)) {
87+
return `type contains whitespace: "${type}"`
88+
} else if (type === 'chore') {
89+
return 'Do not use "chore" as a type. If the existing valid types are insufficent, add a new type to the `lintcommit.js` script.'
90+
} else if (!types.has(type)) {
91+
return `invalid type "${type}"`
92+
} else if (!scope && typeScope.includes('(')) {
93+
return `must be formatted like type(scope):`
94+
} else if (!scope && ['feat', 'fix'].includes(type)) {
95+
return `"${type}" type must include a scope (example: "${type}(amazonq)")`
96+
} else if (scope && scope.length > 30) {
97+
return 'invalid scope (must be <=30 chars)'
98+
} else if (scope && /[^- a-z0-9]+/.test(scope)) {
99+
return `invalid scope (must be lowercase, ascii only): "${scope}"`
100+
} else if (subject.length === 0) {
101+
return 'empty subject'
102+
} else if (subject.length > 100) {
103+
return 'invalid subject (must be <=100 chars)'
104+
}
105+
106+
return undefined
107+
}
108+
109+
function run() {
110+
const eventData = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'))
111+
const pullRequest = eventData.pull_request
112+
113+
// console.log(eventData)
114+
115+
if (!pullRequest) {
116+
console.info('No pull request found in the context')
117+
return
118+
}
119+
120+
const title = pullRequest.title
121+
122+
const failReason = validateTitle(title)
123+
const msg = failReason
124+
? `
125+
Invalid pull request title: \`${title}\`
126+
127+
* Problem: ${failReason}
128+
* Expected format: \`type(scope): subject...\`
129+
* type: one of (${Array.from(types).join(', ')})
130+
* scope: lowercase, <30 chars
131+
* subject: must be <100 chars
132+
* documentation: https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#pull-request-title
133+
`
134+
: `Pull request title matches the [expected format](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#pull-request-title).`
135+
136+
if (process.env.GITHUB_STEP_SUMMARY) {
137+
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, msg)
138+
}
139+
140+
if (failReason) {
141+
console.error(msg)
142+
process.exit(1)
143+
} else {
144+
console.info(msg)
145+
}
146+
}
147+
148+
function _test() {
149+
const tests = {
150+
' foo(scope): bar': 'type contains whitespace: " foo"',
151+
'build: update build process': undefined,
152+
'chore: update dependencies':
153+
'Do not use "chore" as a type. If the existing valid types are insufficent, add a new type to the `lintcommit.js` script.',
154+
'ci: configure CI/CD': undefined,
155+
'config: update configuration files': undefined,
156+
'deps: bump the aws-sdk group across 1 directory with 5 updates': undefined,
157+
'docs: update documentation': undefined,
158+
'feat(foo): add new feature': undefined,
159+
'feat(foo):': 'empty subject',
160+
'feat foo):': 'type contains whitespace: "feat foo)"',
161+
'feat(foo)): sujet': 'invalid type "feat(foo))"',
162+
'feat(foo: sujet': 'invalid type "feat(foo"',
163+
'feat(Q Foo Bar): bar': 'invalid scope (must be lowercase, ascii only): "Q Foo Bar"',
164+
'feat(scope):': 'empty subject',
165+
'feat(q foo bar): bar': undefined,
166+
'feat(foo): x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ':
167+
'invalid subject (must be <=100 chars)',
168+
'feat: foo': '"feat" type must include a scope (example: "feat(amazonq)")',
169+
'fix: foo': '"fix" type must include a scope (example: "fix(amazonq)")',
170+
'fix(a-b-c): resolve issue': undefined,
171+
'foo (scope): bar': 'type contains whitespace: "foo "',
172+
'invalid title': 'missing colon (:) char',
173+
'perf: optimize performance': undefined,
174+
'refactor: improve code structure': undefined,
175+
'revert: feat: add new feature': undefined,
176+
'style: format code': undefined,
177+
'test: add new tests': undefined,
178+
'types: add type definitions': undefined,
179+
'Merge staging into feature/lambda-get-started': undefined,
180+
}
181+
182+
let passed = 0
183+
let failed = 0
184+
185+
for (const [title, expected] of Object.entries(tests)) {
186+
const result = validateTitle(title)
187+
if (result === expected) {
188+
console.log(`✅ Test passed for "${title}"`)
189+
passed++
190+
} else {
191+
console.log(`❌ Test failed for "${title}" (expected "${expected}", got "${result}")`)
192+
failed++
193+
}
194+
}
195+
196+
console.log(`\n${passed} tests passed, ${failed} tests failed`)
197+
}
198+
199+
function main() {
200+
const mode = process.argv[2]
201+
202+
if (mode === 'test') {
203+
_test()
204+
} else {
205+
run()
206+
}
207+
}
208+
209+
main()

.github/workflows/node.js.yml

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
1-
# github actions: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
1+
# github actions: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-nodejs
22
# setup-node: https://github.com/actions/setup-node
33

44
name: CI
55

66
on:
77
push:
8-
branches: [master]
8+
branches: [master, staging]
99
pull_request:
10-
branches: [master, feature/*, mynah-dev]
10+
branches: [master, feature/*, staging]
11+
# Default = opened + synchronize + reopened.
12+
# We also want "edited" so that lint-commits runs when PR title is updated.
13+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request
14+
types:
15+
- edited
16+
- opened
17+
- reopened
18+
- synchronize
19+
20+
# Cancel old jobs when a pull request is updated.
21+
concurrency:
22+
group: ${{ github.head_ref || github.run_id }}
23+
cancel-in-progress: true
1124

1225
jobs:
26+
lint-commits:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 20
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: '20'
35+
- name: Check PR title
36+
run: |
37+
node "$GITHUB_WORKSPACE/.github/workflows/lintcommit.js"
38+
39+
lint:
40+
needs: lint-commits
41+
runs-on: ubuntu-latest
42+
strategy:
43+
matrix:
44+
node-version: [16.x]
45+
vscode-version: [stable]
46+
env:
47+
NODE_OPTIONS: '--max-old-space-size=8192'
48+
steps:
49+
- uses: actions/checkout@v4
50+
- name: Use Node.js ${{ matrix.node-version }}
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: ${{ matrix.node-version }}
54+
- run: npm ci
55+
- run: npm run testCompile
56+
- run: npm run lint
57+
1358
macos:
59+
needs: lint-commits
1460
name: test macOS
1561
runs-on: macos-latest
1662
strategy:
@@ -21,6 +67,8 @@ jobs:
2167
env:
2268
VSCODE_TEST_VERSION: ${{ matrix.vscode-version }}
2369
NODE_OPTIONS: '--max-old-space-size=8192'
70+
AWS_TOOLKIT_TEST_CACHE_DIR: '/tmp/.vscode-test/'
71+
AWS_TOOLKIT_TEST_USER_DIR: '/tmp/.vscode-test/user-data/'
2472
steps:
2573
- uses: actions/checkout@v4
2674
- name: Use Node.js ${{ matrix.node-version }}
@@ -36,7 +84,7 @@ jobs:
3684
env:
3785
# Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475
3886
NODE_OPTIONS: ''
39-
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && ( github.ref == 'master' || github.event_name == 'pull_request' ) }}
87+
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }}
4088
uses: codecov/codecov-action@v4
4189
with:
4290
flags: macos-core-unittests
@@ -47,7 +95,7 @@ jobs:
4795
env:
4896
# Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475
4997
NODE_OPTIONS: ''
50-
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && ( github.ref == 'master' || github.event_name == 'pull_request' ) }}
98+
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }}
5199
uses: codecov/codecov-action@v4
52100
with:
53101
flags: macos-toolkit-unittests
@@ -58,7 +106,7 @@ jobs:
58106
env:
59107
# Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475
60108
NODE_OPTIONS: ''
61-
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && ( github.ref == 'master' || github.event_name == 'pull_request' ) }}
109+
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }}
62110
uses: codecov/codecov-action@v4
63111
with:
64112
flags: macos-amazonq-unittests
@@ -69,7 +117,7 @@ jobs:
69117
env:
70118
# Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475
71119
NODE_OPTIONS: ''
72-
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && ( github.ref == 'master' || github.event_name == 'pull_request' ) }}
120+
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }}
73121
uses: codecov/codecov-action@v4
74122
with:
75123
flags: codewhisperer
@@ -78,6 +126,7 @@ jobs:
78126
token: ${{ secrets.CODECOV_TOKEN }}
79127

80128
web:
129+
needs: lint-commits
81130
name: test Web
82131
runs-on: ubuntu-latest
83132
strategy:
@@ -88,6 +137,8 @@ jobs:
88137
env:
89138
VSCODE_TEST_VERSION: ${{ matrix.vscode-version }}
90139
NODE_OPTIONS: '--max-old-space-size=8192'
140+
AWS_TOOLKIT_TEST_CACHE_DIR: '/tmp/.vscode-test/'
141+
AWS_TOOLKIT_TEST_USER_DIR: '/tmp/.vscode-test/user-data/'
91142
steps:
92143
- uses: actions/checkout@v4
93144
- name: Use Node.js ${{ matrix.node-version }}
@@ -101,6 +152,7 @@ jobs:
101152
run: npm run testWeb
102153

103154
windows:
155+
needs: lint-commits
104156
name: test Windows
105157
runs-on: windows-2019
106158
strategy:
@@ -124,29 +176,10 @@ jobs:
124176
env:
125177
# Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475
126178
NODE_OPTIONS: ''
127-
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && ( github.ref == 'master' || github.event_name == 'pull_request' ) }}
179+
if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }}
128180
uses: codecov/codecov-action@v4
129181
with:
130182
flags: windows-unittests
131183
verbose: true
132184
file: ./coverage/lcov.info
133185
token: ${{ secrets.CODECOV_TOKEN }}
134-
135-
lint:
136-
name: Lint
137-
runs-on: ubuntu-latest
138-
strategy:
139-
matrix:
140-
node-version: [16.x]
141-
vscode-version: [stable]
142-
env:
143-
NODE_OPTIONS: '--max-old-space-size=8192'
144-
steps:
145-
- uses: actions/checkout@v4
146-
- name: Use Node.js ${{ matrix.node-version }}
147-
uses: actions/setup-node@v4
148-
with:
149-
node-version: ${{ matrix.node-version }}
150-
- run: npm ci
151-
- run: npm run testCompile
152-
- run: npm run lint

0 commit comments

Comments
 (0)