Skip to content

Commit

Permalink
rename update-checks-doc script to checks-check
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 24, 2024
1 parent d63a8e1 commit 7917883
Show file tree
Hide file tree
Showing 49 changed files with 23 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ All tests are automated.

The ['Checks' document](./docs/checks.md) is a large document to explain all checks by actionlint.

This document is maintained with [`update-checks-doc`](./scripts/update-checks-doc) script. This script automatically updates
This document is maintained with [`check-checks`](./scripts/check-checks) script. This script automatically updates
the code blocks after `Output:` and the `Playground` links. This script should be run after modifying the document.

Please see [the readme of the script](./scripts/update-checks-doc/README.md) for the usage and knowing the details of the
Please see [the readme of the script](./scripts/check-checks/README.md) for the usage and knowing the details of the
document format that this script assumes.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ t test: .testtimestamp
.staticchecktimestamp: $(TESTS) $(SRCS) $(TOOL)
staticcheck ./...
GOOS=js GOARCH=wasm staticcheck ./playground
go run ./scripts/update-checks-doc -check -quiet ./docs/checks.md
go run ./scripts/check-checks -quiet ./docs/checks.md
touch .staticchecktimestamp

l lint: .staticchecktimestamp
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
update-checks-doc
=================
check-checks
============

This is a script to maintain [the 'Checks' document](../../docs/checks.md).

Expand All @@ -21,19 +21,19 @@ For making the implementation simple, this script does not support Windows.
## Usage

```
go run ./scripts/update-checks-doc [-check] FILE
go run ./scripts/check-checks [-fix] FILE
```

Update the document. This command directly modifies the file.

```sh
go run ./scripts/update-checks-doc ./docs/checks.md
go run ./scripts/check-checks ./docs/checks.md
```

Check the document is up-to-date.

```sh
go run ./scripts/update-checks-doc -check ./docs/checks.md
go run ./scripts/check-checks -check ./docs/checks.md
```

The check is run on the [CI workflow](../../.github/workflows/ci.yaml).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ func Update(in []byte) ([]byte, error) {
var stderr io.Writer = os.Stderr

func Main(args []string) error {
var check bool
var fix bool
var quiet bool
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
flags.BoolVar(&check, "check", false, "check the document is up-to-date")
flags.BoolVar(&fix, "fix", false, "fix the outdated document automatically")
flags.BoolVar(&quiet, "quiet", false, "disable trace logs")
flags.SetOutput(stderr)
flags.Usage = func() {
fmt.Fprintln(stderr, "Usage: update-checks-doc [FLAGS] FILE\n\nFlags:")
fmt.Fprintln(stderr, "Usage: check-checks [FLAGS] FILE\n\nFlags:")
flags.PrintDefaults()
}

Expand Down Expand Up @@ -358,8 +358,8 @@ func Main(args []string) error {
return nil
}

if check {
return fmt.Errorf("checks document has some update. run `go run ./scripts/update-checks-doc %s` and commit the changes. the diff:\n\n%s", path, cmp.Diff(in, out))
if !fix {
return fmt.Errorf("checks document has some update. run `go run ./scripts/check-checks -fix %s` and commit the changes on Linux or macOS. the diff:\n\n%s", path, cmp.Diff(in, out))
}

log.Printf("Overwrite the file with the updated content (%d bytes) at %q", len(out), path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func testErr(t *testing.T, err error, want ...string) {

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

Expand All @@ -52,7 +52,7 @@ func TestMainGenerateOK(t *testing.T) {
in.Close()
tmp.Close()

if err := Main([]string{"exe", path}); err != nil {
if err := Main([]string{"exe", "-fix", path}); err != nil {
t.Fatal(err)
}

Expand All @@ -65,20 +65,20 @@ func TestMainGenerateOK(t *testing.T) {

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

func TestMainCheckQuietOK(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("update-checks-doc doesn't support Windows")
t.Skip("check-checks doesn't support Windows")
}
path := filepath.FromSlash("testdata/ok/minimal.out")
if err := Main([]string{"exe", "-check", "-quiet", path}); err != nil {
if err := Main([]string{"exe", "-quiet", path}); err != nil {
t.Fatal(err)
}
}
Expand All @@ -91,14 +91,14 @@ func TestMainPrintHelp(t *testing.T) {

func TestMainCheckError(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("update-checks-doc doesn't support Windows")
t.Skip("check-checks doesn't support Windows")
}
path := filepath.FromSlash("testdata/ok/minimal.in")
testErr(t, Main([]string{"exe", "-check", path}), "checks document has some update")
testErr(t, Main([]string{"exe", path}), "checks document has some update")
}

func TestMainFileNotFound(t *testing.T) {
testErr(t, Main([]string{"exe", "-check", "this-file-does-not-exist.md"}), "could not read the document file")
testErr(t, Main([]string{"exe", "this-file-does-not-exist.md"}), "could not read the document file")
}

func TestMainTooManyArgs(t *testing.T) {
Expand All @@ -109,16 +109,6 @@ func TestMainInvalidCheckFlag(t *testing.T) {
testErr(t, Main([]string{"exe", "-c", "foo.md"}), "flag provided but not defined")
}

func TestMainNoUpdate(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("update-checks-doc doesn't support Windows")
}
path := filepath.FromSlash("testdata/ok/minimal.out")
if err := Main([]string{"exe", path}); err != nil {
t.Fatal(err)
}
}

func TestMainUpdateError(t *testing.T) {
path := filepath.FromSlash("testdata/err/no_playground_link.md")
if err := Main([]string{"exe", path}); err == nil {
Expand All @@ -128,7 +118,7 @@ func TestMainUpdateError(t *testing.T) {

func TestUpdateOK(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("update-checks-doc doesn't support Windows")
t.Skip("check-checks doesn't support Windows")
}

dir := filepath.FromSlash("testdata/ok")
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7917883

Please sign in to comment.