Skip to content

Commit 6807526

Browse files
committed
add support for Windows to update-checks-doc script
1 parent 54f7d98 commit 6807526

File tree

9 files changed

+140
-26
lines changed

9 files changed

+140
-26
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/scripts/generate-webhook-events/testdata/** -text
44
/scripts/generate-availability/testdata/** -text
55
/scripts/generate-actionlint-matcher/test/** -text
6+
/scripts/update-checks-doc/testdata/** -text

.github/workflows/ci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ jobs:
104104
echo "$diffs" >&2
105105
exit 1
106106
fi
107-
- name: Check `docs/checks.md` is up-to-date
108-
run: go run ./scripts/update-checks-doc -check ./docs/checks.md
109107
- name: Install staticcheck
110108
run: |
111109
go install honnef.co/go/tools/cmd/staticcheck@latest

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ all: build test lint
2323

2424
t test: .testtimestamp
2525

26-
.staticchecktimestamp: $(TESTS) $(SRCS) $(TOOL)
26+
.staticchecktimestamp: $(TESTS) $(SRCS) $(TOOL) docs/checks.md
2727
staticcheck ./...
2828
GOOS=js GOARCH=wasm staticcheck ./playground
29+
go run ./scripts/update-checks-doc -check -quiet docs/checks.md
2930
touch .staticchecktimestamp
3031

3132
l lint: .staticchecktimestamp

docs/checks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,7 @@ jobs:
21822182
```
21832183

21842184
Output:
2185+
<!-- Skip update output on Windows -->
21852186

21862187
```
21872188
test.yaml:6:5: when a reusable workflow is called with "uses", "runs-on" is not available. only following keys are allowed: "name", "uses", "with", "secrets", "needs", "if", and "permissions" in job "job1" [syntax-check]

scripts/update-checks-doc/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ This script does:
99
- update the links to the [playground](https://rhysd.github.io/actionlint/) for the example inputs
1010
- check the document is up-to-date
1111

12-
For making the implementation simple, this script does not support Windows.
13-
1412
## Prerequisites
1513

1614
- Go
17-
- Linux or macOS
1815
- `shellcheck` command
1916
- `pyflakes` command
2017

scripts/update-checks-doc/main.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"log"
1313
"os"
14+
"runtime"
1415
"strings"
1516

1617
"github.com/google/go-cmp/cmp"
@@ -183,6 +184,7 @@ func (u *Updater) Update() {
183184
isInputHeader := l == "Example input:"
184185
isOutputHeader := l == "Output:"
185186
isSkipOutput := l == "<!-- Skip update output -->"
187+
isSkipOutputWin := l == "<!-- Skip update output on Windows -->"
186188
isSkipPlaygroundLink := l == "<!-- Skip playground link -->"
187189
isPlaygroundLink := strings.HasPrefix(l, "[Playground](") && strings.HasSuffix(l, ")")
188190

@@ -194,7 +196,7 @@ func (u *Updater) Update() {
194196
u.expect(stateHeading, stateEnd)
195197
case isOutputHeader:
196198
u.expect(stateAfterInput)
197-
case isSkipOutput:
199+
case isSkipOutput, isSkipOutputWin:
198200
u.expect(stateOutputHeader)
199201
case isSkipPlaygroundLink, isPlaygroundLink:
200202
u.expect(stateAfterOutput)
@@ -274,8 +276,12 @@ func (u *Updater) Update() {
274276
u.state(stateOutputHeader, "Found example output header")
275277
}
276278
case stateOutputHeader:
277-
if isSkipOutput {
278-
u.state(stateAfterOutput, "Skip updating output due to the comment")
279+
if isSkipOutput || isSkipOutputWin && runtime.GOOS == "windows" {
280+
reason := "Skip updating output due to the comment"
281+
if isSkipOutputWin {
282+
reason += " only on Windows"
283+
}
284+
u.state(stateAfterOutput, reason)
279285
} else if l == "```" {
280286
u.state(stateOutputBlock, "Start code block for output")
281287
}
@@ -317,8 +323,10 @@ var stderr io.Writer = os.Stderr
317323

318324
func Main(args []string) error {
319325
var check bool
326+
var quiet bool
320327
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
321328
flags.BoolVar(&check, "check", false, "check the document is up-to-date")
329+
flags.BoolVar(&quiet, "quiet", false, "disable trace log")
322330
flags.SetOutput(stderr)
323331
flags.Usage = func() {
324332
fmt.Fprintln(stderr, "Usage: update-checks-doc [FLAGS] FILE\n\nFlags:")
@@ -335,12 +343,20 @@ func Main(args []string) error {
335343
}
336344
path := flags.Arg(0)
337345

346+
if quiet {
347+
log.SetOutput(io.Discard)
348+
}
349+
338350
in, err := os.ReadFile(path)
339351
if err != nil {
340352
return fmt.Errorf("could not read the document file: %w", err)
341353
}
342354
log.Printf("Read %d bytes from %q", len(in), path)
343355

356+
if runtime.GOOS == "windows" {
357+
in = bytes.ReplaceAll(in, []byte{'\r', '\n'}, []byte{'\n'})
358+
}
359+
344360
out, err := Update(in)
345361
if err != nil {
346362
return err

scripts/update-checks-doc/main_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ func testErr(t *testing.T, err error, want ...string) {
4040
}
4141

4242
func TestMainGenerateOK(t *testing.T) {
43-
if runtime.GOOS == "windows" {
44-
t.Skip("update-checks-doc doesn't support Windows")
45-
}
4643
root := t.TempDir()
4744

4845
in := must(os.Open(filepath.FromSlash("testdata/ok/minimal.in")))
@@ -64,25 +61,26 @@ func TestMainGenerateOK(t *testing.T) {
6461
}
6562

6663
func TestMainCheckOK(t *testing.T) {
67-
if runtime.GOOS == "windows" {
68-
t.Skip("update-checks-doc doesn't support Windows")
69-
}
7064
path := filepath.FromSlash("testdata/ok/minimal.out")
7165
if err := Main([]string{"exe", "-check", path}); err != nil {
7266
t.Fatal(err)
7367
}
7468
}
7569

70+
func TestMainCheckQuietOK(t *testing.T) {
71+
path := filepath.FromSlash("testdata/ok/minimal.out")
72+
if err := Main([]string{"exe", "-check", "-quiet", path}); err != nil {
73+
t.Fatal(err)
74+
}
75+
}
76+
7677
func TestMainPrintHelp(t *testing.T) {
7778
if err := Main([]string{"exe", "-help"}); err != nil {
7879
t.Fatal(err)
7980
}
8081
}
8182

8283
func TestMainCheckError(t *testing.T) {
83-
if runtime.GOOS == "windows" {
84-
t.Skip("update-checks-doc doesn't support Windows")
85-
}
8684
path := filepath.FromSlash("testdata/ok/minimal.in")
8785
testErr(t, Main([]string{"exe", "-check", path}), "checks document has some update")
8886
}
@@ -100,9 +98,6 @@ func TestMainInvalidCheckFlag(t *testing.T) {
10098
}
10199

102100
func TestMainNoUpdate(t *testing.T) {
103-
if runtime.GOOS == "windows" {
104-
t.Skip("update-checks-doc doesn't support Windows")
105-
}
106101
path := filepath.FromSlash("testdata/ok/minimal.out")
107102
if err := Main([]string{"exe", path}); err != nil {
108103
t.Fatal(err)
@@ -117,10 +112,6 @@ func TestMainUpdateError(t *testing.T) {
117112
}
118113

119114
func TestUpdateOK(t *testing.T) {
120-
if runtime.GOOS == "windows" {
121-
t.Skip("update-checks-doc doesn't support Windows")
122-
}
123-
124115
dir := filepath.FromSlash("testdata/ok")
125116

126117
tests := []string{}
@@ -129,7 +120,18 @@ func TestUpdateOK(t *testing.T) {
129120
if !strings.HasSuffix(n, ".in") {
130121
continue
131122
}
132-
tests = append(tests, strings.TrimSuffix(n, filepath.Ext(n)))
123+
124+
id := strings.TrimSuffix(n, filepath.Ext(n))
125+
// This test case does not work on Windows
126+
if runtime.GOOS == "windows" && id == "replace_absolute_path" {
127+
continue
128+
}
129+
// This test case only works on Windows
130+
if runtime.GOOS != "windows" && id == "skip_output_on_windows" {
131+
continue
132+
}
133+
134+
tests = append(tests, id)
133135
}
134136

135137
for _, tc := range tests {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<a id="hello"></a>
2+
## Hello
3+
4+
Example input:
5+
6+
```yaml
7+
on: push
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- run: echo ${{ unknown }}
13+
```
14+
15+
Output:
16+
<!-- Skip update output on Windows -->
17+
18+
```
19+
This section will NOT be updated
20+
```
21+
22+
[Playground](URL_WILL_BE_GENERATED)
23+
24+
Skip updating the output.
25+
26+
<a id="hello2"></a>
27+
## Hello 2
28+
29+
Example input:
30+
31+
```yaml
32+
on: push
33+
jobs:
34+
test:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- run: echo ${{ unknown }}
38+
```
39+
40+
Output:
41+
<!-- Skip update output on Windows -->
42+
43+
```
44+
This section will NOT be updated
45+
```
46+
47+
[Playground](URL_WILL_BE_GENERATED)
48+
49+
Skip updating the output.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<a id="hello"></a>
2+
## Hello
3+
4+
Example input:
5+
6+
```yaml
7+
on: push
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- run: echo ${{ unknown }}
13+
```
14+
15+
Output:
16+
<!-- Skip update output -->
17+
18+
```
19+
This section will NOT be updated
20+
```
21+
22+
[Playground](https://rhysd.github.io/actionlint/#eNokyjEOhSAQRdGeVbzit2yA3XwMCVEzQ5x5sSDs3YxWtzhXpWDQetq1WkmAN/MocFEsh7NSnPn8h71k3oZ9F5DjLGhbV/zmBOUQvQVrPQEAAP//SLkdHQ==)
23+
24+
Skip updating the output.
25+
26+
<a id="hello2"></a>
27+
## Hello 2
28+
29+
Example input:
30+
31+
```yaml
32+
on: push
33+
jobs:
34+
test:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- run: echo ${{ unknown }}
38+
```
39+
40+
Output:
41+
<!-- Skip update output -->
42+
43+
```
44+
This section will NOT be updated
45+
```
46+
47+
[Playground](https://rhysd.github.io/actionlint/#eNokyjEOhSAQRdGeVbzit2yA3XwMCVEzQ5x5sSDs3YxWtzhXpWDQetq1WkmAN/MocFEsh7NSnPn8h71k3oZ9F5DjLGhbV/zmBOUQvQVrPQEAAP//SLkdHQ==)
48+
49+
Skip updating the output.

0 commit comments

Comments
 (0)