From efa70bee406bb73e0724faf71c829ec19014997a Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 25 Apr 2024 22:59:00 +0900 Subject: [PATCH] ignore outdated actions on generating popular actions data set --- scripts/generate-popular-actions/main.go | 15 +++++++ scripts/generate-popular-actions/main_test.go | 40 ++++++++++++------- .../testdata/go/fetched.go | 9 +++-- .../testdata/go/outdated.go | 7 ++++ .../testdata/registry/fetch.json | 2 +- .../testdata/registry/outdated.json | 6 +++ 6 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 scripts/generate-popular-actions/testdata/go/outdated.go create mode 100644 scripts/generate-popular-actions/testdata/registry/outdated.json diff --git a/scripts/generate-popular-actions/main.go b/scripts/generate-popular-actions/main.go index 22175f179..19c64ad3e 100644 --- a/scripts/generate-popular-actions/main.go +++ b/scripts/generate-popular-actions/main.go @@ -13,6 +13,7 @@ import ( "net/http" "os" "sort" + "strconv" "strings" "github.com/rhysd/actionlint" @@ -61,6 +62,16 @@ func (r *registry) spec(tag string) string { //go:embed popular_actions.json var defaultPopularActionsJSON []byte +const minNodeRunnerVersion = 16 + +func isOutdatedRunner(r string) bool { + if !strings.HasPrefix(r, "node") { + return false + } + v, err := strconv.ParseUint(r[len("node"):], 10, 8) + return err == nil && v < minNodeRunnerVersion +} + type gen struct { stdout io.Writer stderr io.Writer @@ -169,6 +180,10 @@ func (g *gen) fetchRemote() (map[string]*actionlint.ActionMetadata, error) { close(done) return nil, f.err } + if isOutdatedRunner(f.meta.Runs.Using) { + g.log.Printf("Ignore outdated action %q since runner is %q", f.spec, f.meta.Runs.Using) + continue + } ret[f.spec] = f.meta } diff --git a/scripts/generate-popular-actions/main_test.go b/scripts/generate-popular-actions/main_test.go index 9a81f2011..227af0f4a 100644 --- a/scripts/generate-popular-actions/main_test.go +++ b/scripts/generate-popular-actions/main_test.go @@ -193,23 +193,35 @@ func TestWriteGoFile(t *testing.T) { } func TestFetchRemoteYAML(t *testing.T) { - f := filepath.Join("testdata", "registry", "fetch.json") - stdout := &bytes.Buffer{} - stderr := io.Discard - status := newGen(stdout, stderr, io.Discard).run([]string{"test", "-r", f}) - if status != 0 { - t.Fatal("exit status is non-zero:", status) + tests := []struct { + registry string + want string + }{ + {"fetch.json", "fetched.go"}, + {"outdated.json", "outdated.go"}, } - b, err := os.ReadFile(filepath.Join("testdata", "go", "fetched.go")) - if err != nil { - panic(err) - } - want := string(b) - have := stdout.String() + for _, tc := range tests { + t.Run(tc.registry, func(t *testing.T) { + f := filepath.Join("testdata", "registry", tc.registry) + stdout := &bytes.Buffer{} + stderr := io.Discard + status := newGen(stdout, stderr, io.Discard).run([]string{"test", "-r", f}) + if status != 0 { + t.Fatal("exit status is non-zero:", status) + } + + b, err := os.ReadFile(filepath.Join("testdata", "go", tc.want)) + if err != nil { + panic(err) + } + want := string(b) + have := stdout.String() - if !cmp.Equal(want, have) { - t.Fatalf("fetched JSONL data does not match: %s", cmp.Diff(want, have)) + if !cmp.Equal(want, have) { + t.Fatalf("fetched JSONL data does not match: %s", cmp.Diff(want, have)) + } + }) } } diff --git a/scripts/generate-popular-actions/testdata/go/fetched.go b/scripts/generate-popular-actions/testdata/go/fetched.go index cab22e4b4..896d40671 100644 --- a/scripts/generate-popular-actions/testdata/go/fetched.go +++ b/scripts/generate-popular-actions/testdata/go/fetched.go @@ -5,12 +5,13 @@ package actionlint // PopularActions is data set of known popular actions. Keys are specs (owner/repo@ref) of actions // and values are their metadata. var PopularActions = map[string]*ActionMetadata{ - "rhysd/action-setup-vim@v1.2.7": { + "rhysd/action-setup-vim@v1.3.2": { Name: "Setup Vim", Inputs: ActionMetadataInputs{ - "neovim": {"neovim", false}, - "token": {"token", false}, - "version": {"version", false}, + "configure-args": {"configure-args", false}, + "neovim": {"neovim", false}, + "token": {"token", false}, + "version": {"version", false}, }, Outputs: ActionMetadataOutputs{ "executable": {"executable"}, diff --git a/scripts/generate-popular-actions/testdata/go/outdated.go b/scripts/generate-popular-actions/testdata/go/outdated.go new file mode 100644 index 000000000..8923b9bc0 --- /dev/null +++ b/scripts/generate-popular-actions/testdata/go/outdated.go @@ -0,0 +1,7 @@ +// Code generated by actionlint/scripts/generate-popular-actions. DO NOT EDIT. + +package actionlint + +// PopularActions is data set of known popular actions. Keys are specs (owner/repo@ref) of actions +// and values are their metadata. +var PopularActions = map[string]*ActionMetadata{} diff --git a/scripts/generate-popular-actions/testdata/registry/fetch.json b/scripts/generate-popular-actions/testdata/registry/fetch.json index 84bbb8c2e..c90db4d2e 100644 --- a/scripts/generate-popular-actions/testdata/registry/fetch.json +++ b/scripts/generate-popular-actions/testdata/registry/fetch.json @@ -1,7 +1,7 @@ [ { "slug": "rhysd/action-setup-vim", - "tags": ["v1.2.7"], + "tags": ["v1.3.2"], "next": "v2" }, { diff --git a/scripts/generate-popular-actions/testdata/registry/outdated.json b/scripts/generate-popular-actions/testdata/registry/outdated.json new file mode 100644 index 000000000..3cbe58c40 --- /dev/null +++ b/scripts/generate-popular-actions/testdata/registry/outdated.json @@ -0,0 +1,6 @@ +[ + { + "slug": "rhysd/action-setup-vim", + "tags": ["v1.0.0"] + } +]