Skip to content

Commit 7f9851a

Browse files
nadr0jacebrowning
andauthored
[Chore]: Added url-checker, updated circular-deps, documented new static analysis .txt pattern (#7442)
* fix: ignoring url checker files * fix: url checker * fix: auto fmt and cleanup * fix: moving the bash scripts and known files into the scripts repo * fix: removed all url_results and made it be all in memory * fix: fixed the newline issue * fix: url checking as a step to the static analysis * fix: removed old code * chore: writing documentation on our static checker pattern * fix: updating the docs more to be clearer * fix: copy and paste without understanding requirements of ci cd dependencies? do i need all of these? * fix: updating * fix: I thought this got in? * Update CONTRIBUTING.md Co-authored-by: Jace Browning <jacebrowning@gmail.com> --------- Co-authored-by: Jace Browning <jacebrowning@gmail.com>
1 parent fbcbb34 commit 7f9851a

File tree

9 files changed

+159
-3
lines changed

9 files changed

+159
-3
lines changed

.github/workflows/static-analysis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ jobs:
120120
121121
- run: npm run circular-deps:diff
122122

123+
npm-url-checker:
124+
runs-on: ubuntu-latest
125+
needs: npm-build-wasm
126+
127+
steps:
128+
- uses: actions/checkout@v4
129+
- uses: actions/setup-node@v4
130+
with:
131+
node-version-file: '.nvmrc'
132+
cache: 'npm'
133+
- run: npm install
134+
135+
- name: Download all artifacts
136+
uses: actions/download-artifact@v4
137+
138+
- name: Copy prepared wasm
139+
run: |
140+
ls -R prepared-wasm
141+
cp prepared-wasm/kcl_wasm_lib_bg.wasm public
142+
mkdir rust/kcl-wasm-lib/pkg
143+
cp prepared-wasm/kcl_wasm_lib* rust/kcl-wasm-lib/pkg
144+
145+
- name: Copy prepared ts-rs bindings
146+
run: |
147+
ls -R prepared-ts-rs-bindings
148+
mkdir rust/kcl-lib/bindings
149+
cp -r prepared-ts-rs-bindings/* rust/kcl-lib/bindings/
150+
151+
- run: npm run url-checker:diff
152+
123153
python-codespell:
124154
runs-on: ubuntu-22.04
125155
steps:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ venv
8787

8888
.vscode-test
8989
.biome/
90-
.million
90+
.million

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,47 @@ To display logging (to the terminal or console) set `ZOO_LOG=1`. This will log s
235235

236236
To enable memory metrics, build with `--features dhat-heap`.
237237

238+
## Running scripts
239+
240+
There are multiple scripts under the folder path `./scripts` which can be used in various settings.
241+
242+
### Pattern for a static file, npm run commands, and CI-CD checks
243+
244+
If you want to implement a static checker follow this pattern. Two static checkers we have are circular dependency checks in our typescript code and url checker to see if any hard coded URL is the typescript application 404s. We have a set of known files in `./scripts/known/*.txt` which is the baseline.
245+
246+
If you improve the baseline, run the overwrite command and commit the new smaller baseline. Try not to make the baseline bigger, the CI CD will complain.
247+
These baselines are to hold us to higher standards and help implement automated testing against the repository
248+
249+
#### Output result to stdout
250+
- `npm run circular-deps`
251+
- `npm run url-checker`
252+
253+
- create a `<name>.sh` file that will run the static checker then output the result to `stdout`
254+
255+
#### Overwrite result to known .txt file on disk
256+
257+
If the application needs to overwrite the known file on disk use this pattern. This known .txt file will be source controlled as the baseline
258+
259+
- `npm run circular-deps:overwrite`
260+
- `npm run url-checker:overwrite`
261+
262+
#### Diff baseline and current
263+
264+
These commands will write a /tmp/ file on disk and compare it to the known file in the repository. This command will also be used in the CI CD pipeline for automated checks
265+
266+
- create a `diff-<name>.sh` file that is the script to diff your tmp file to the baseline
267+
e.g. `diff-url-checker.sh`
268+
```bash
269+
#!/bin/bash
270+
set -euo pipefail
271+
272+
npm run url-checker > /tmp/urls.txt
273+
diff --ignore-blank-lines -w /tmp/urls.txt ./scripts/known/urls.txt
274+
```
275+
276+
- `npm run circular-deps:diff`
277+
- `npm run url-checker:diff`
278+
238279
## Proposing changes
239280

240281
Before you submit a contribution PR to this repo, please ensure that:

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@
110110
"remove-importmeta": "sed -i 's/import.meta.url/window.location.origin/g' \"./rust/kcl-wasm-lib/pkg/kcl_wasm_lib.js\"; sed -i '' 's/import.meta.url/window.location.origin/g' \"./rust/kcl-wasm-lib/pkg/kcl_wasm_lib.js\" || echo \"sed for both mac and linux\"",
111111
"lint-fix": "eslint --fix --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src rust/kcl-language-server/client/src",
112112
"lint": "eslint --max-warnings 0 --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src rust/kcl-language-server/client/src",
113+
"url-checker":"./scripts/url-checker.sh",
114+
"url-checker:overwrite":"npm run url-checker > scripts/known/urls.txt",
115+
"url-checker:diff":"./scripts/diff-url-checker.sh",
113116
"circular-deps": "dpdm --no-warning --no-tree -T --skip-dynamic-imports=circular src/index.tsx",
114-
"circular-deps:overwrite": "npm run circular-deps | sed '$d' | grep -v '^npm run' > known-circular.txt",
117+
"circular-deps:overwrite": "npm run circular-deps | sed '$d' | grep -v '^npm run' > scripts/known/circular.txt",
115118
"circular-deps:diff": "./scripts/diff-circular-deps.sh",
116119
"circular-deps:diff:nodejs": "npm run circular-deps:diff || node ./scripts/diff.js",
117120
"files:set-version": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json",

scripts/diff-circular-deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
set -euo pipefail
33

44
npm run circular-deps | sed '$d' > /tmp/circular-deps.txt
5-
diff --ignore-blank-lines -w /tmp/circular-deps.txt ./known-circular.txt
5+
diff --ignore-blank-lines -w /tmp/circular-deps.txt ./scripts/known/circular.txt

scripts/diff-url-checker.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
npm run url-checker > /tmp/urls.txt
5+
diff --ignore-blank-lines -w /tmp/urls.txt ./scripts/known/urls.txt
File renamed without changes.

scripts/known/urls.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
> zoo-modeling-app@0.0.0 url-checker
3+
> ./scripts/url-checker.sh
4+
5+
URL STATUS
6+
000 https://${BASE_URL}
7+
301 https://discord.gg/JQEpHR7Nt2
8+
404 https://github.com/KittyCAD/engine/issues/3528
9+
404 https://github.com/KittyCAD/modeling-app/commit/${ref}
10+
302 https://github.com/KittyCAD/modeling-app/issues/new/choose
11+
302 https://github.com/KittyCAD/modeling-app/issues/new?template=bug_report.yml
12+
302 https://github.com/KittyCAD/modeling-app/issues/new?title=${title}&body=${body}
13+
404 https://github.com/KittyCAD/modeling-app/releases/tag/v${version}
14+
521 https://placekitten.com/200/200
15+
302 https://reactrouter.com/en/6.16.0/routers/picking-a-router#using-v64-data-apis
16+
302 https://stackoverflow.com/a/57390160/22753272
17+
302 https://stackoverflow.com/a/58436959/22753272
18+
303 https://text-to-cad.zoo.dev/dashboard
19+
307 https://zoo.dev/
20+
308 https://zoo.dev/docs/api/ml/generate-a-cad-model-from-text
21+
308 https://zoo.dev/docs/kcl

scripts/url-checker.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
trap 'echo "$BASH_COMMAND"' ERR
4+
5+
remove_after_space () {
6+
sed 's/ .*//'
7+
}
8+
9+
remove_after_backtick () {
10+
sed 's/`.*//'
11+
}
12+
13+
remove_after_end_paren () {
14+
sed 's/).*//'
15+
}
16+
17+
remove_after_double_quote () {
18+
sed 's/".*//'
19+
}
20+
21+
remove_after_gt () {
22+
sed 's/>.*//'
23+
}
24+
25+
remove_after_comma () {
26+
sed 's/,.*//'
27+
}
28+
29+
# Search all src/**/*.ts files
30+
val1=$(grep -Eoh "(https)://[^']+" src/**/*.ts | remove_after_space | remove_after_backtick | remove_after_end_paren | remove_after_double_quote | remove_after_gt | remove_after_comma)
31+
32+
# Search all src/**/*.tsx files
33+
val2=$(grep -Eoh "(https)://[^']+" src/**/*.tsx | remove_after_space | remove_after_backtick | remove_after_end_paren | remove_after_double_quote | remove_after_gt | remove_after_comma)
34+
35+
# Required a newline between them when combining since there is not one at the end of val1
36+
combined="$val1"$'\n'"$val2"
37+
38+
# Merge both ts and tsx results and unique them
39+
uniqued=$(echo "$combined" | sort | uniq)
40+
41+
# All urls and status codes
42+
all="URL\tSTATUS\n"
43+
44+
# All non 200 urls and status codes
45+
problematic="URL\tSTATUS\n"
46+
while read line; do
47+
# || true this curl request to bypass any failures and not have the scrip panic.
48+
# the set -euo pipefail will cause a panic if a curl fails
49+
status=$(curl -o /dev/null -s -w "%{http_code}\n" $line || true)
50+
all+="$status\t$line\n"
51+
if [[ "$status" -ne 200 ]]; then
52+
# list status first over line because of white space formatting, less annoying for diffing
53+
problematic+="$status\t$line\n"
54+
fi
55+
done < <(echo "$uniqued")
56+
echo -e $problematic | column -t

0 commit comments

Comments
 (0)