Skip to content

Commit f02cc45

Browse files
committed
bughunt probe: deno store
1 parent f6b7fb9 commit f02cc45

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

‎.github/workflows/bughunt-deno.yml‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: bughunt-deno
2+
on:
3+
push:
4+
branches: ['bughunt/deno/**']
5+
permissions:
6+
contents: read
7+
jobs:
8+
probe:
9+
runs-on: ${{ matrix.os }}
10+
timeout-minutes: 45
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
deno: ['1.46.3', '2.2.15', '2.9.6']
16+
defaults:
17+
run:
18+
shell: bash
19+
steps:
20+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
22+
- uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5
23+
with:
24+
deno-version: ${{ matrix.deno }}
25+
- name: build
26+
run: cargo build --release -p socket-patch-cli
27+
- name: probe
28+
run: |
29+
set -u
30+
SP="$GITHUB_WORKSPACE/target/release/socket-patch"
31+
T="$RUNNER_TEMP/t"; mkdir -p "$T"
32+
cat > "$T/mkman.py" <<'PYEOF'
33+
#!/usr/bin/env python3
34+
# usage: mkman.py <projdir> <purl>=<pkgdir>[:file] ... -> writes .socket/manifest.json + blobs (before+after)
35+
import sys, os, json, hashlib
36+
def gh(b): return hashlib.sha256(b"blob %d\0" % len(b) + b).hexdigest()
37+
proj = sys.argv[1]; soc = os.path.join(proj, ".socket"); os.makedirs(os.path.join(soc,"blobs"), exist_ok=True)
38+
man = {"patches": {}}
39+
for i, arg in enumerate(sys.argv[2:]):
40+
purl, rest = arg.split("=",1)
41+
pkgdir, _, f = rest.partition(":"); f = f or "index.js"
42+
orig = open(os.path.join(pkgdir, f),"rb").read()
43+
nm = purl.split("/")[-1].split("@")[0]
44+
patched = ("/* SOCKET-MARKER */ globalThis.__SP=(globalThis.__SP||[]).concat([\"%s\"]);\n" % nm).encode() + orig
45+
bh, ah = gh(orig), gh(patched)
46+
open(os.path.join(soc,"blobs",bh),"wb").write(orig); open(os.path.join(soc,"blobs",ah),"wb").write(patched)
47+
man["patches"][purl] = {"uuid": "1111111%d-1111-4111-8111-111111111111" % i, "exportedAt":"2024-01-01T00:00:00Z",
48+
"files": {"package/"+f: {"beforeHash": bh, "afterHash": ah}},
49+
"vulnerabilities": {"GHSA-xxxx-xxxx-xxxx": {"cves":["CVE-2099-0001"],"summary":"t","severity":"high","description":"t"}},
50+
"description":"t","license":"MIT","tier":"free"}
51+
json.dump(man, open(os.path.join(soc,"manifest.json"),"w"), indent=2)
52+
PYEOF
53+
PY=python3; command -v python3 >/dev/null || PY=python
54+
deno --version | head -1
55+
for MODE in auto manual; do
56+
W="$T/$MODE"; mkdir -p "$W"; cd "$W"; export DENO_DIR="$T/denodir-$MODE"
57+
case "${{ matrix.deno }}" in 1.*) NMD=true ;; *) NMD='"auto"' ;; esac
58+
if [ $MODE = auto ]; then echo "{\"nodeModulesDir\":$NMD,\"imports\":{\"is-odd\":\"npm:is-odd@3.0.1\"}}" > deno.json
59+
else echo "{\"nodeModulesDir\":$NMD}" > deno.json; echo '{"dependencies":{"is-odd":"3.0.1"}}' > package.json; fi
60+
echo 'import isOdd from "is-odd"; isOdd(3); console.log("loaded-patched=" + JSON.stringify((globalThis as any).__SP || []));' > probe.ts
61+
if [ $MODE = auto ]; then deno cache probe.ts; else deno install || deno cache probe.ts; fi
62+
S=node_modules/.deno
63+
if [ ! -f $S/is-number@6.0.0/node_modules/is-number/index.js ]; then echo "CELL $MODE: SETUP-FAIL"; ls -la node_modules $S || true; continue; fi
64+
$PY "$T/mkman.py" . "pkg:npm/is-odd@3.0.1=$S/is-odd@3.0.1/node_modules/is-odd" "pkg:npm/is-number@6.0.0=$S/is-number@6.0.0/node_modules/is-number"
65+
"$SP" apply --offline --json > apply.json; RC=$?
66+
cat apply.json
67+
OUT=$(deno run -A probe.ts 2>&1 | tail -1)
68+
EV=$($PY -c "import json;d=json.load(open('apply.json'));print(d['status'],[(e['purl'],e['action'],e.get('errorCode')) for e in d['events']])")
69+
echo "CELL ${{ matrix.os }} deno=${{ matrix.deno }} $MODE rc=$RC $EV runtime=$OUT"
70+
done

0 commit comments

Comments
 (0)