Skip to content

Commit 3d8e1a1

Browse files
committed
Added CI for validation and testing.
1 parent ddebd19 commit 3d8e1a1

File tree

6 files changed

+110
-11
lines changed

6 files changed

+110
-11
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test with puppeteer
2+
on:
3+
pull_request:
4+
push:
5+
branches: [ development, main ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
docker-test:
10+
runs-on: ubuntu-22.04
11+
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v4
15+
16+
- name: Build and run Containerfile
17+
run: |
18+
IMAGE_ID=$(docker build -q -f Containerfile .)
19+
echo "Built image: $IMAGE_ID"
20+
docker run --rm "$IMAGE_ID"

.github/workflows/verify.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Verify with eslint and semgrep
2+
on:
3+
pull_request:
4+
push:
5+
branches: [ development, main ]
6+
7+
jobs:
8+
verify:
9+
runs-on: ubuntu-22.04
10+
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '25'
19+
20+
- name: Setup Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.12'
24+
25+
- name: Install ESLint deps
26+
working-directory: ./linting
27+
run: npm ci
28+
29+
- name: Create Python venv and install Semgrep
30+
working-directory: ./linting
31+
run: |
32+
python -m venv .venv
33+
. .venv/bin/activate
34+
pip install --upgrade pip
35+
pip install semgrep
36+
37+
- name: Run ESLint
38+
working-directory: ./linting
39+
run: |
40+
npx eslint ../script.user.js
41+
42+
- name: Run Semgrep
43+
working-directory: ./linting
44+
run: |
45+
. .venv/bin/activate
46+
semgrep -c ../.semgrep.yml ../script.user.js

.semgrep.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ rules:
2121

2222
- id: js-no-websocket
2323
message: "WebSockets are not expected in this userscript. Review necessity."
24-
severity: WARNING
24+
severity: ERROR
2525
languages: [ javascript ]
2626
pattern: new WebSocket(...)
2727

2828
- id: js-fetch-non-whitelisted-domain
2929
message: "fetch() URL should be YouTube only. Review this call."
30-
severity: WARNING
30+
severity: ERROR
3131
languages: [ javascript ]
3232
patterns:
3333
- pattern: fetch($URL, ...)
@@ -37,15 +37,15 @@ rules:
3737

3838
- id: js-no-cross-window-postmessage
3939
message: "window.postMessage is not expected in this userscript. Review necessity."
40-
severity: WARNING
40+
severity: ERROR
4141
languages: [ javascript ]
4242
pattern: $OBJ.postMessage(...)
4343
metavariables:
4444
OBJ: window
4545

4646
- id: js-no-location-rewrite-to-non-youtube
4747
message: "Changing window.location to non-YouTube domains is suspicious. Review."
48-
severity: WARNING
48+
severity: ERROR
4949
languages: [ javascript ]
5050
patterns:
5151
- pattern: window.location = $URL
@@ -55,7 +55,7 @@ rules:
5555

5656
- id: js-no-location-href-rewrite-to-non-youtube
5757
message: "Changing window.location to non-YouTube domains is suspicious. Review."
58-
severity: WARNING
58+
severity: ERROR
5959
languages: [ javascript ]
6060
patterns:
6161
- pattern: window.location.href = $URL
@@ -65,7 +65,7 @@ rules:
6565

6666
- id: js-no-open-non-youtube
6767
message: "window.open to non-YouTube domains should be reviewed."
68-
severity: WARNING
68+
severity: ERROR
6969
languages: [ javascript ]
7070
patterns:
7171
- pattern: window.open($URL, ...)

testing/spago.lock

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"console",
1010
"effect",
1111
"node-fs",
12+
"node-process",
1213
"prelude",
1314
"strings",
1415
"toppokki"
@@ -55,6 +56,7 @@
5556
"node-http",
5657
"node-net",
5758
"node-path",
59+
"node-process",
5860
"node-streams",
5961
"node-tls",
6062
"node-url",
@@ -67,6 +69,7 @@
6769
"orders",
6870
"parallel",
6971
"partial",
72+
"posix-types",
7073
"prelude",
7174
"profunctor",
7275
"quickcheck",
@@ -1233,6 +1236,22 @@
12331236
"effect"
12341237
]
12351238
},
1239+
"node-process": {
1240+
"type": "registry",
1241+
"version": "11.2.0",
1242+
"integrity": "sha256-+2MQDYChjGbVbapCyJtuWYwD41jk+BntF/kcOTKBMVs=",
1243+
"dependencies": [
1244+
"effect",
1245+
"foreign",
1246+
"foreign-object",
1247+
"maybe",
1248+
"node-event-emitter",
1249+
"node-streams",
1250+
"posix-types",
1251+
"prelude",
1252+
"unsafe-coerce"
1253+
]
1254+
},
12361255
"node-streams": {
12371256
"type": "registry",
12381257
"version": "9.0.1",
@@ -1390,6 +1409,15 @@
13901409
"integrity": "sha256-fwXerld6Xw1VkReh8yeQsdtLVrjfGiVuC5bA1Wyo/J4=",
13911410
"dependencies": []
13921411
},
1412+
"posix-types": {
1413+
"type": "registry",
1414+
"version": "6.0.0",
1415+
"integrity": "sha256-ZfFz8RR1lee/o/Prccyeut3Q+9tYd08mlR72sIh6GzA=",
1416+
"dependencies": [
1417+
"maybe",
1418+
"prelude"
1419+
]
1420+
},
13931421
"prelude": {
13941422
"type": "registry",
13951423
"version": "6.0.2",

testing/spago.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ package:
44
- aff
55
- console
66
- effect
7+
- node-fs
8+
- node-process
79
- prelude
810
- strings
911
- toppokki
10-
- node-fs
1112
test:
1213
main: Test.Main
1314
dependencies: []

testing/src/Script.purs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Data.Time.Duration (Milliseconds(Milliseconds))
99
import Foreign (isNull, isUndefined, readString)
1010
import Control.Monad.Except (runExcept)
1111
import Data.Either (Either(..))
12+
import Effect.Class (liftEffect)
13+
import Node.Process (exit') as Process
1214

1315
step :: String -> String -> T.Page -> (T.Page -> Aff Unit) -> Boolean -> Aff Boolean
1416
step label expected page setup prev = do
@@ -180,10 +182,12 @@ script = do
180182
delay (Milliseconds 500.0)
181183
)
182184

183-
if result == true
184-
then info "ALL TESTS PASSED!"
185-
else info "UNFORTUNATE FAILURE..."
186-
187185
-- Shutdown
188186

189187
T.close browser
188+
189+
if result == true
190+
then info "ALL TESTS PASSED!"
191+
else do
192+
info "UNFORTUNATE FAILURE..."
193+
liftEffect $ Process.exit' 1

0 commit comments

Comments
 (0)