Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
leigaol committed Nov 11, 2024
2 parents f6ee8ce + 09510a3 commit afe08e9
Show file tree
Hide file tree
Showing 347 changed files with 42,375 additions and 13,727 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ module.exports = {
'aws-toolkits/no-incorrect-once-usage': 'error',
'aws-toolkits/no-string-exec-for-child-process': 'error',
'aws-toolkits/no-console-log': 'error',

'aws-toolkits/no-json-stringify-in-log': 'error',
'aws-toolkits/no-printf-mismatch': 'error',
'no-restricted-imports': [
'error',
{
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/copyPasteDetection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# github actions: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-nodejs
# setup-node: https://github.com/actions/setup-node

name: Copy-Paste Detection

on:
pull_request:
branches: [master, feature/*, staging]

jobs:
jscpd:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
env:
NODE_OPTIONS: '--max-old-space-size=8192'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Fetch fork upstream
run: |
git remote add forkUpstream https://github.com/${{ github.event.pull_request.head.repo.full_name }} # URL of the fork
git fetch forkUpstream # Fetch fork
- name: Determine base and target branches for comparison.
run: |
echo "CURRENT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
- run: git diff --name-only origin/$TARGET_BRANCH forkUpstream/$CURRENT_BRANCH > diff_output.txt
- run: |
npm install -g jscpd
- run: jscpd --config "$GITHUB_WORKSPACE/.github/workflows/jscpd.json"

- if: always()
uses: actions/upload-artifact@v4
with:
name: unfiltered-jscpd-report
path: ./jscpd-report.json

- name: Filter jscpd report for changed files
run: |
if [ ! -f ./jscpd-report.json ]; then
echo "jscpd-report.json not found"
exit 1
fi
echo "Filtering jscpd report for changed files..."
CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' diff_output.txt)
echo "Changed files: $CHANGED_FILES"
jq --argjson changed_files "$CHANGED_FILES" '
.duplicates | map(select(
(.firstFile?.name as $fname | $changed_files | any(. == $fname)) or
(.secondFile?.name as $sname | $changed_files | any(. == $sname))
))
' ./jscpd-report.json > filtered-jscpd-report.json
cat filtered-jscpd-report.json
- name: Check for duplicates
run: |
if [ $(wc -l < ./filtered-jscpd-report.json) -gt 1 ]; then
echo "filtered_report_exists=true" >> $GITHUB_ENV
else
echo "filtered_report_exists=false" >> $GITHUB_ENV
fi
- name: upload filtered report (if applicable)
if: env.filtered_report_exists == 'true'
uses: actions/upload-artifact@v4
with:
name: filtered-jscpd-report
path: ./filtered-jscpd-report.json

- name: Fail and log found duplicates.
if: env.filtered_report_exists == 'true'
run: |
cat ./filtered-jscpd-report.json
echo "Duplications found, failing the check."
exit 1
9 changes: 9 additions & 0 deletions .github/workflows/jscpd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pattern": "packages/**/*.ts",
"ignore": ["**node_modules**", "**dist**", "**/scripts/**"],
"gitignore": true,
"threshold": 3.0,
"minLines": 3,
"output": "./",
"reporters": ["json"]
}
2 changes: 1 addition & 1 deletion .github/workflows/notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
if: github.event_name == 'pull_request_target'
with:
node-version: '20'
- name: Check for tests
- name: Comment about contribution guidelines
uses: actions/github-script@v7
if: github.event_name == 'pull_request_target'
with:
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
const { hasPath, dedupComment } = require('./utils')

const testFilesMessage =
'This pull request modifies code in src/ but no tests were added/updated. Confirm whether tests should be added or ensure the PR description explains why tests are not required.'
'- This pull request modifies code in `src/*` but no tests were added/updated.\n - Confirm whether tests should be added or ensure the PR description explains why tests are not required.\n'

const changelogMessage = `This pull request implements a feature or fix, so it must include a changelog entry. See [CONTRIBUTING.md#changelog](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#changelog) for instructions.`
const changelogMessage =
'- This pull request implements a `feat` or `fix`, so it must include a changelog entry (unless the fix is for an *unreleased* feature). Review the [changelog guidelines](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#changelog).\n - Note: beta or "experiment" features that have active users *should* announce fixes in the changelog.\n - If this is not a feature or fix, use an appropriate type from the [title guidelines](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#pull-request-title). For example, telemetry-only changes should use the `telemetry` type.\n'

/**
* Remind partner teams that tests are required. We don't need to remind them if:
Expand Down Expand Up @@ -44,12 +45,16 @@ module.exports = async ({ github, context }) => {
issue_number: pullRequestId,
})

let msg = ''
if (shouldAddTestFileMessage) {
await dedupComment({ github, comments, owner, repo, pullRequestId, message: testFilesMessage })
msg += testFilesMessage
}

if (shouldAddChangelogMessage) {
await dedupComment({ github, comments, owner, repo, pullRequestId, message: changelogMessage })
msg += changelogMessage
}

if (shouldAddTestFileMessage || shouldAddChangelogMessage) {
await dedupComment({ github, comments, owner, repo, pullRequestId, message: msg })
}
}

Expand All @@ -69,7 +74,12 @@ function requiresChangelogMessage(filenames, title) {
* Require the test files message if there are changes to source files but aren't any
* changes to the test files
*/
function requiresTestFilesMessage(filenames) {
function requiresTestFilesMessage(filenames, title) {
if (/^\s*[mM]erge/.test(title)) {
console.log('"Merge" pull request')
return
}

// Check if src directory changed
if (!hasPath(filenames, 'src/')) {
console.log('Did not find src files in the code changes')
Expand Down
18 changes: 14 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ To run a single test in VSCode, do any one of:
- Unix/macOS/POSIX shell:
```
TEST_FILE=src/test/foo.test.ts npm run test
TEST_FILE=../core/src/test/foo.test.ts npm run test
```
- Powershell:
```
$Env:TEST_FILE = "src/test/foo.test.ts"; npm run test
$Env:TEST_FILE = "../core/src/test/foo.test.ts"; npm run test
```
- To run all tests in a particular subdirectory, you can edit
Expand All @@ -209,13 +209,23 @@ To run tests against a specific folder in VSCode, do any one of:
- Run in your terminal
- Unix/macOS/POSIX shell:
```
TEST_DIR=src/test/foo npm run test
TEST_DIR=../core/src/test/foo npm run test
```
- Powershell:
```
$Env:TEST_DIR = "src/test/foo"; npm run test
$Env:TEST_DIR = "../core/src/test/foo"; npm run test
```
#### Run jscpd ("Copy-Paste Detection")
If the "Copy-Paste Detection" CI job fails, you will find it useful to check things locally. To
check a specific file:
npx jscpd --config .github/workflows/jscpd.json --pattern packages/…/src/foo.ts
See the [jscpd cli documentation](https://github.com/kucherenko/jscpd/tree/master/apps/jscpd) for
more options.
### Coverage report
You can find the coverage report at `./coverage/amazonq/lcov-report/index.html` and `./coverage/toolkit/lcov-report/index.html` after running the tests. Tests ran from the workspace launch config won't generate a coverage report automatically because it can break file watching.
Expand Down
2 changes: 1 addition & 1 deletion buildspec/shared/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# - "Webview is disposed": only happens on vscode "minimum" (1.68.0)
# - "HTTPError: Response code …": caused by github rate-limiting.
# - "npm WARN deprecated querystring": transitive dep of aws sdk v2 (check `npm ls querystring`), so that's blocked until we migrate to v3.
_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404\|npm WARN deprecated querystring'
_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404\|npm WARN deprecated querystring\|npm WARN deprecated'
if [ "$VSCODE_TEST_VERSION" = 'minimum' ]; then
_ignore_pat="$_ignore_pat"'\|Webview is disposed'
fi
Expand Down
20 changes: 16 additions & 4 deletions docs/build.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# Build

The AmazonQ features rely on the `codewhisperer-streaming` service, who's client
is generated from the service's smithy models and placed in
`src.gen/@amzn/codewhisperer-streaming` (For more
information about this client and how it is generated, please see this
The AmazonQ features rely on the `codewhisperer-streaming` service, to support both Sigv4 and Bearer token modes of this service,
two clients are generated from the service's smithy models and placed in
`src.gen/@amzn/amazon-q-developer-streaming-client` and `src.gen/@amzn/codewhisperer-streaming` respectively (For more
information about these clients and how they are generated, please see this
[quip document](https://quip-amazon.com/2dAWAvTIYXXr/Build-instructions-for-AWS-CodeWhisperer-Streaming-Typescript-client)).

## @amzn/amazon-q-developer-streaming client

This client is a standalone npm project in typescript, and it is added to
the project as a workspace in the project's root `package.json` with the line `"workspaces": [ ..., "src.gen/@amzn/amazon-q-developer-streaming" ]`.
The client may be manually built using `npm run build -w @amzn/amazon-q-developer-streaming"`.
The `generateClients` run script ensures that this dependency is
built before the toolkit project itself. Workspaces are automatically ready to
be imported in the root toolkit project by their declared package.json name,
(`@amzn/amazon-q-developer-streaming` in this case).

## @amzn/codewhisperer-streaming client

This client is a standalone npm project in typescript, and it is added to
the project as a workspace in the project's root `package.json` with the line `"workspaces": [ ..., "src.gen/@amzn/codewhisperer-streaming" ]`.
The client may be manually built using `npm run build -w @amzn/codewhisperer-streaming"`.
Expand Down
Loading

0 comments on commit afe08e9

Please sign in to comment.