Skip to content

Commit c0edd4d

Browse files
committed
check docs/checks.md is up-to-date in CI
1 parent b1d6ae6 commit c0edd4d

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,21 @@ jobs:
9191
- uses: actions/setup-go@v5
9292
with:
9393
go-version: '1.23'
94-
- run: sudo apt-get install -y shellcheck
94+
- name: Install dependencies
95+
run: |
96+
sudo apt-get install -y shellcheck
97+
pip install pyflakes
98+
shellcheck --version
99+
pyflakes --version
95100
- name: Check Go sources are formatted
96101
run: |
97102
diffs="$(gofmt -d ./*.go ./cmd/actionlint/*.go ./scripts/*/*.go ./playground/*.go)"
98103
if [[ "$diffs" != "" ]]; then
99104
echo "$diffs" >&2
100105
exit 1
101106
fi
107+
- name: Check `docs/checks.md` is up-to-date
108+
run: go run ./scripts/update-checks-doc -check ./docs/checks.md
102109
- name: Install staticcheck
103110
run: |
104111
go install honnef.co/go/tools/cmd/staticcheck@latest

scripts/update-checks-doc/main.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"strings"
1313

14+
"github.com/google/go-cmp/cmp"
1415
"github.com/rhysd/actionlint"
1516
)
1617

@@ -180,28 +181,43 @@ func update(in []byte) ([]byte, error) {
180181
}
181182

182183
func Main(args []string) error {
183-
if len(os.Args) < 2 {
184-
return errors.New("usage: update-checks-doc FILE")
184+
var path string
185+
var check bool
186+
switch len(args) {
187+
case 2:
188+
path = args[1]
189+
case 3:
190+
if args[1] != "-check" && args[1] != "--check" {
191+
return errors.New("usage: update-checks-doc [-check] FILE")
192+
}
193+
path = args[2]
194+
check = true
195+
default:
196+
return errors.New("usage: update-checks-doc [-check] FILE")
185197
}
186-
p := os.Args[1]
187-
in, err := os.ReadFile(p)
198+
199+
in, err := os.ReadFile(path)
188200
if err != nil {
189201
return err
190202
}
191-
log.Printf("Read %d bytes from %q", len(in), p)
203+
log.Printf("Read %d bytes from %q", len(in), path)
192204

193205
out, err := update(in)
194206
if err != nil {
195207
return err
196208
}
197209

198210
if bytes.Equal(in, out) {
199-
log.Printf("Do nothing because there is no update in %q", p)
211+
log.Printf("Do nothing because there is no update in %q", path)
200212
return nil
201213
}
202214

203-
log.Printf("Generate the updated content (%d bytes) for %q", len(out), p)
204-
if err := os.WriteFile(p, out, 0666); err != nil {
215+
if check {
216+
return errors.New("checks document has some update. run `go run ./scripts/update-checks-doc ./docs/checks.md` and commit the changes. the diff:\n\n" + cmp.Diff(in, out))
217+
}
218+
219+
log.Printf("Generate the updated content (%d bytes) for %q", len(out), path)
220+
if err := os.WriteFile(path, out, 0666); err != nil {
205221
return err
206222
}
207223

0 commit comments

Comments
 (0)