Skip to content

Commit

Permalink
ignore outdated actions on generating popular actions data set
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Apr 25, 2024
1 parent 34242db commit efa70be
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
15 changes: 15 additions & 0 deletions scripts/generate-popular-actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"os"
"sort"
"strconv"
"strings"

"github.com/rhysd/actionlint"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
40 changes: 26 additions & 14 deletions scripts/generate-popular-actions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
}
}

Expand Down
9 changes: 5 additions & 4 deletions scripts/generate-popular-actions/testdata/go/fetched.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions scripts/generate-popular-actions/testdata/go/outdated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"slug": "rhysd/action-setup-vim",
"tags": ["v1.2.7"],
"tags": ["v1.3.2"],
"next": "v2"
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"slug": "rhysd/action-setup-vim",
"tags": ["v1.0.0"]
}
]

0 comments on commit efa70be

Please sign in to comment.