Repository navigation
175 lines (158 loc) · 6.68 KB
/
Copy pathtest.yml
File metadata and controls
175 lines (158 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Test
# All three systems for the code, and on Linux the installers people
# actually paste into a terminal. The fixtures in the unit tests are only
# as right as my idea of how shell gets written; what this has to work on
# is what other people wrote, and most of what this program knows came from
# those files disagreeing with it.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: stable
- name: Formatting
shell: bash
run: test -z "$(gofmt -l .)" || { gofmt -l .; exit 1; }
- name: Vet
run: go vet ./...
- name: Tests
run: go test -v ./...
- name: The other systems still compile
shell: bash
run: |
for target in windows linux darwin; do
GOOS=$target go vet ./...
GOOS=$target go build -o /dev/null .
done
# The installers, fetched fresh. If one of them changes shape enough that
# this stops seeing what it does, that is worth finding out here rather
# than from somebody's issue.
real:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: stable
- name: Fetch the installers people paste
run: |
mkdir -p real && cd real
fetch() { curl -sSL --max-time 30 -o "$1" "$2" || echo "could not fetch $1"; }
fetch rustup.sh https://sh.rustup.rs
fetch nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh
fetch docker.sh https://get.docker.com
fetch bun.sh https://bun.sh/install
fetch ollama.sh https://ollama.com/install.sh
fetch starship.sh https://starship.rs/install.sh
fetch ohmyzsh.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
wc -l *.sh
- name: Read them
run: |
go build -o customs-check .
for f in real/*.sh; do
echo "════════ $f"
./customs-check "$f" || true
done
# Each of these is a thing the installer is known to do, and each of
# them was missed at some point while this was being written. The
# tags are part of the pattern on purpose: a finding in the wrong
# pile is the failure this program cannot afford.
- name: What each of them is known to do
run: |
check() {
file="$1"; want="$2"; why="$3"
# A site being down is not a failure of this program. The
# check is skipped rather than turning somebody else's outage
# into a red build, and it says so, so a run where everything
# was skipped does not read as a run where everything passed.
if [ ! -s "real/$file" ]; then
echo " skipped: $file could not be fetched"
return
fi
./customs-check "real/$file" > out.txt 2>&1 || true
if ! grep -q "$want" out.txt; then
echo "MISSED in $file: $why"
cat out.txt
exit 1
fi
echo " ok: $file $why"
}
# nvm appends to a profile whose name a function works out.
check nvm.sh '\[LEAVES \].*leaves something behind' 'writes to a shell profile'
# docker adds an apt source and a signing key, through a command
# held in a variable and passed as a string.
check docker.sh '\[LEAVES \].*widens what this machine will accept' 'adds a signing key'
check docker.sh '\[LEAVES \].*brings in more code' 'installs packages'
# bun writes to three shell profiles with a block redirect.
check bun.sh '\[LEAVES \].*leaves something behind' 'writes to a shell profile'
# ollama installs, writes outside home and enables a service.
check ollama.sh '\[LEAVES \]' 'leaves things behind'
# starship unpacks into a directory named by a flag with a default.
check starship.sh '\[LEAVES \].*writes outside your home' 'unpacks into /usr/local/bin'
# oh-my-zsh replaces your .zshrc.
check ohmyzsh.sh '\[LEAVES \]' 'writes to a shell profile'
- name: And it printed no credentials and ran nothing
run: |
for f in real/*.sh; do
./customs-check --source "$f" >> all.txt 2>&1 || true
done
# Nothing in these installers is a live credential, so anything
# that looks like one in the output would be this program
# inventing it or a real one leaking through.
if grep -qE '(gh[pous]_[A-Za-z0-9]{30,}|sk_live_[A-Za-z0-9]{16,})' all.txt; then
echo "something credential shaped reached the report"
exit 1
fi
echo "read $(ls real/*.sh | wc -l) installers, printed no credentials"
# A script with nothing worth deciding about has to come back quiet,
# or the tool is useless on the ones that are fine.
- name: An ordinary script is reported as ordinary
run: |
cat > tidy.sh <<'END'
#!/bin/sh
set -eu
cd "$(dirname "$0")"
echo "building"
go build -o thing ./cmd/thing
echo "done"
END
set +e
./customs-check tidy.sh > tidy.txt 2>&1
code=$?
set -e
cat tidy.txt
if [ "$code" -ne 0 ]; then
echo "An ordinary build script was reported as needing a decision."
exit 1
fi
tr -s '[:space:]' ' ' < tidy.txt > flat.txt
grep -q "not the same as nothing being here" flat.txt || {
echo "it claimed more than it knows"; exit 1; }
# The other formats, where most shell actually lives.
- name: The formats that are not shell scripts
run: |
mkdir -p other && cd other
cat > package.json <<'END'
{"name":"t","scripts":{"postinstall":"curl -s https://x.dev/p.sh | sh"}}
END
printf 'FROM debian\nRUN curl -sSL https://x.dev/a | sh\n' > Dockerfile
printf 'install:\n\tcp thing /usr/local/bin/\n' > Makefile
cd ..
./customs-check other > other.txt 2>&1 || true
cat other.txt
tr -s '[:space:]' ' ' < other.txt > otherflat.txt
for wanted in "postinstall" "RUN" "install:"; do
grep -q "$wanted" otherflat.txt || {
echo "the $wanted case was not read"; exit 1; }
done