Skip to content

Commit e09485d

Browse files
committed
fix generate-popular-actions to read/write outdated actions in JSONL
and add more tests
1 parent 679440f commit e09485d

17 files changed

+104
-44
lines changed

action_metadata.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,31 @@ func (inputs *ActionMetadataOutputs) UnmarshalYAML(n *yaml.Node) error {
9494
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs
9595
type ActionMetadataRuns struct {
9696
// Using is `using` configuration of action.yaml. It defines what runner is used for the action.
97-
Using string `yaml:"using"`
97+
Using string `yaml:"using" json:"using"`
9898
// Main is `main` configuration of action.yaml for JavaScript action.
99-
Main string `yaml:"main"`
99+
Main string `yaml:"main" json:"main"`
100100
// Pre is `pre` configuration of action.yaml for JavaScript action.
101-
Pre string `yaml:"pre"`
101+
Pre string `yaml:"pre" json:"pre"`
102102
// PreIf is `pre-if` configuration of action.yaml for JavaScript action.
103-
PreIf string `yaml:"pre-if"`
103+
PreIf string `yaml:"pre-if" json:"pre-if"`
104104
// Post is `post` configuration of action.yaml for JavaScript action.
105-
Post string `yaml:"post"`
105+
Post string `yaml:"post" json:"post"`
106106
// PostIf is `post-if` configuration of action.yaml for JavaScript action.
107-
PostIf string `yaml:"post-if"`
107+
PostIf string `yaml:"post-if" json:"post-if"`
108108
// Steps is `steps` configuration of action.yaml for Composite action.
109-
Steps []any `yaml:"steps"`
109+
Steps []any `yaml:"steps" json:"steps"`
110110
// Image is `image` of action.yaml for Docker action.
111-
Image string `yaml:"image"`
111+
Image string `yaml:"image" json:"image"`
112112
// PreEntrypoint is `pre-entrypoint` of action.yaml for Docker action.
113-
PreEntrypoint string `yaml:"pre-entrypoint"`
113+
PreEntrypoint string `yaml:"pre-entrypoint" json:"pre-entrypoint"`
114114
// Entrypoint is `entrypoint` of action.yaml for Docker action.
115-
Entrypoint string `yaml:"entrypoint"`
115+
Entrypoint string `yaml:"entrypoint" json:"entrypoint"`
116116
// PostEntrypoint is `post-entrypoint` of action.yaml for Docker action.
117-
PostEntrypoint string `yaml:"post-entrypoint"`
117+
PostEntrypoint string `yaml:"post-entrypoint" json:"post-entrypoint"`
118118
// Args is `args` of action.yaml for Docker action.
119-
Args []any `yaml:"args"`
119+
Args []any `yaml:"args" json:"args"`
120120
// Env is `env` of action.yaml for Docker action.
121-
Env map[string]any `yaml:"env"`
121+
Env map[string]any `yaml:"env" json:"env"`
122122
}
123123

124124
// ActionMetadataBranding is "branding" section of action.yaml.
@@ -149,7 +149,7 @@ type ActionMetadata struct {
149149
// true, the outputs object accepts any properties along with strictly typed props.
150150
SkipOutputs bool `yaml:"-" json:"skip_outputs"`
151151
// Runs is "runs" field of action.yaml.
152-
Runs ActionMetadataRuns `yaml:"runs" json:"-"`
152+
Runs ActionMetadataRuns `yaml:"runs" json:"runs"`
153153
// Branding is "branding" field of action.yaml.
154154
Branding ActionMetadataBranding `yaml:"branding" json:"-"`
155155
}

scripts/generate-popular-actions/main.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
)
2222

2323
type actionOutput struct {
24-
Spec string `json:"spec"`
25-
Meta *actionlint.ActionMetadata `json:"metadata"`
24+
Spec string `json:"spec"`
25+
Meta *actionlint.ActionMetadata `json:"metadata"`
26+
Outdated bool `json:"outdated"`
2627
}
2728

2829
type registry struct {
@@ -201,11 +202,7 @@ func (g *gen) fetchRemote() (map[string]*actionlint.ActionMetadata, error) {
201202
func (g *gen) writeJSONL(out io.Writer, actions map[string]*actionlint.ActionMetadata) error {
202203
enc := json.NewEncoder(out)
203204
for spec, meta := range actions {
204-
if isOutdatedRunner(meta.Runs.Using) {
205-
g.log.Printf("Ignore outdated action %q since runner is %q", spec, meta.Runs.Using)
206-
continue
207-
}
208-
j := actionOutput{spec, meta}
205+
j := actionOutput{spec, meta, isOutdatedRunner(meta.Runs.Using)}
209206
if err := enc.Encode(&j); err != nil {
210207
return fmt.Errorf("could not encode action %q data into JSON: %w", spec, err)
211208
}

scripts/generate-popular-actions/main_test.go

+30-14
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ func TestDefaultPopularActions(t *testing.T) {
6262

6363
func TestReadWriteJSONL(t *testing.T) {
6464
files := []string{
65-
"test.jsonl",
65+
"no_new_version.jsonl",
6666
"skip_inputs.jsonl",
6767
"skip_outputs.jsonl",
68+
"skip_both.jsonl",
69+
"skip_both.jsonl",
70+
"outdated.jsonl",
6871
}
6972

7073
for _, file := range files {
@@ -98,16 +101,24 @@ func TestWriteGoToStdout(t *testing.T) {
98101
want string
99102
}{
100103
{
101-
in: "test.jsonl",
102-
want: "want.go",
104+
in: "no_new_version.jsonl",
105+
want: "no_new_version.go",
103106
},
104107
{
105108
in: "skip_inputs.jsonl",
106-
want: "skip_inputs_want.go",
109+
want: "skip_inputs.go",
107110
},
108111
{
109112
in: "skip_outputs.jsonl",
110-
want: "skip_outputs_want.go",
113+
want: "skip_outputs.go",
114+
},
115+
{
116+
in: "skip_both.jsonl",
117+
want: "skip_both.go",
118+
},
119+
{
120+
in: "outdated.jsonl",
121+
want: "outdated.go",
111122
},
112123
}
113124

@@ -135,7 +146,7 @@ func TestWriteGoToStdout(t *testing.T) {
135146
}
136147

137148
func TestWriteJSONLFile(t *testing.T) {
138-
in := filepath.Join("testdata", "actions", "test.jsonl")
149+
in := filepath.Join("testdata", "actions", "no_new_version.jsonl")
139150
b, err := os.ReadFile(in)
140151
if err != nil {
141152
panic(err)
@@ -164,7 +175,7 @@ func TestWriteJSONLFile(t *testing.T) {
164175
}
165176

166177
func TestWriteGoFile(t *testing.T) {
167-
in := filepath.Join("testdata", "actions", "test.jsonl")
178+
in := filepath.Join("testdata", "actions", "no_new_version.jsonl")
168179
out := filepath.Join("testdata", "go", "out.go")
169180
defer os.Remove(out)
170181

@@ -175,7 +186,7 @@ func TestWriteGoFile(t *testing.T) {
175186
t.Fatal("exit status is non-zero:", status)
176187
}
177188

178-
b, err := os.ReadFile(filepath.Join("testdata", "go", "want.go"))
189+
b, err := os.ReadFile(filepath.Join("testdata", "go", "no_new_version.go"))
179190
if err != nil {
180191
panic(err)
181192
}
@@ -199,6 +210,7 @@ func TestFetchRemoteYAML(t *testing.T) {
199210
}{
200211
{"fetch.json", "fetched.go"},
201212
{"outdated.json", "outdated.go"},
213+
{"skip_both.json", "skip_both.go"},
202214
}
203215

204216
for _, tc := range tests {
@@ -234,14 +246,18 @@ func TestWriteOutdatedActionAsJSONL(t *testing.T) {
234246
t.Fatal("exit status is non-zero:", status)
235247
}
236248

237-
out := stdout.String()
238-
if len(out) > 0 {
239-
t.Fatalf("empty output was expected but got %q", out)
249+
b, err := os.ReadFile(filepath.Join("testdata", "actions", "outdated.jsonl"))
250+
if err != nil {
251+
panic(err)
252+
}
253+
want, have := string(b), stdout.String()
254+
if want != have {
255+
t.Fatal(cmp.Diff(want, have))
240256
}
241257
}
242258

243259
func TestLogOutput(t *testing.T) {
244-
f := filepath.Join("testdata", "actions", "test.jsonl")
260+
f := filepath.Join("testdata", "actions", "no_new_version.jsonl")
245261
stdout := &bytes.Buffer{}
246262
logged := &bytes.Buffer{}
247263
status := newGen(stdout, io.Discard, logged).run([]string{"test", "-s", f, "-f", "jsonl"})
@@ -357,7 +373,7 @@ func TestCouldNotReadJSONLFile(t *testing.T) {
357373
}
358374

359375
func TestCouldNotCreateOutputFile(t *testing.T) {
360-
f := filepath.Join("testdata", "actions", "test.jsonl")
376+
f := filepath.Join("testdata", "actions", "no_new_version.jsonl")
361377
out := filepath.Join("testdata", "this-dir-does-not-exit", "foo.jsonl")
362378
stdout := io.Discard
363379
stderr := &bytes.Buffer{}
@@ -382,7 +398,7 @@ func (w testErrorWriter) Write(b []byte) (int, error) {
382398
func TestWriteError(t *testing.T) {
383399
for _, format := range []string{"go", "jsonl"} {
384400
t.Run(format, func(t *testing.T) {
385-
f := filepath.Join("testdata", "actions", "test.jsonl")
401+
f := filepath.Join("testdata", "actions", "no_new_version.jsonl")
386402
stdout := testErrorWriter{}
387403
stderr := &bytes.Buffer{}
388404

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"spec":"rhysd/action-setup-vim@v1","metadata":{"name":"Setup Vim","inputs":{"configure-args":{"name":"configure-args","required":false},"neovim":{"name":"neovim","required":false},"token":{"name":"token","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":false,"skip_outputs":false,"runs":{"using":"node20","main":"src/index.js","pre":"","pre-if":"","post":"","post-if":"","steps":null,"image":"","pre-entrypoint":"","entrypoint":"","post-entrypoint":"","args":null,"env":null}},"outdated":false}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"spec":"rhysd/[email protected]","metadata":{"name":"Setup Vim","inputs":{"github-token":{"name":"github-token","required":false},"neovim":{"name":"neovim","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":false,"skip_outputs":false,"runs":{"using":"node12","main":"src/index.js","pre":"","pre-if":"","post":"","post-if":"","steps":null,"image":"","pre-entrypoint":"","entrypoint":"","post-entrypoint":"","args":null,"env":null}},"outdated":true}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"spec":"rhysd/action-setup-vim@v1","metadata":{"name":"Setup Vim","inputs":{"configure-args":{"name":"configure-args","required":false},"neovim":{"name":"neovim","required":false},"token":{"name":"token","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":true,"skip_outputs":true,"runs":{"using":"node20","main":"src/index.js","pre":"","pre-if":"","post":"","post-if":"","steps":null,"image":"","pre-entrypoint":"","entrypoint":"","post-entrypoint":"","args":null,"env":null}},"outdated":false}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"spec":"rhysd/action-setup-vim@v1","metadata":{"name":"Setup Vim","inputs":{"neovim":{"name":"neovim","required":false},"token":{"name":"token","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":true,"skip_outputs":false}}
1+
{"spec":"rhysd/action-setup-vim@v1","metadata":{"name":"Setup Vim","inputs":{"configure-args":{"name":"configure-args","required":false},"neovim":{"name":"neovim","required":false},"token":{"name":"token","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":true,"skip_outputs":false,"runs":{"using":"node20","main":"src/index.js","pre":"","pre-if":"","post":"","post-if":"","steps":null,"image":"","pre-entrypoint":"","entrypoint":"","post-entrypoint":"","args":null,"env":null}},"outdated":false}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"spec":"rhysd/action-setup-vim@v1","metadata":{"name":"Setup Vim","inputs":{"neovim":{"name":"neovim","required":false},"token":{"name":"token","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":false,"skip_outputs":true}}
1+
{"spec":"rhysd/action-setup-vim@v1","metadata":{"name":"Setup Vim","inputs":{"configure-args":{"name":"configure-args","required":false},"neovim":{"name":"neovim","required":false},"token":{"name":"token","required":false},"version":{"name":"version","required":false}},"outputs":{"executable":{"name":"executable"}},"skip_inputs":false,"skip_outputs":true,"runs":{"using":"node20","main":"src/index.js","pre":"","pre-if":"","post":"","post-if":"","steps":null,"image":"","pre-entrypoint":"","entrypoint":"","post-entrypoint":"","args":null,"env":null}},"outdated":false}

scripts/generate-popular-actions/testdata/actions/test.jsonl

-1
This file was deleted.

scripts/generate-popular-actions/testdata/go/want.go renamed to scripts/generate-popular-actions/testdata/go/no_new_version.go

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-popular-actions/testdata/go/skip_both.go

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-popular-actions/testdata/go/skip_outputs_want.go renamed to scripts/generate-popular-actions/testdata/go/skip_outputs.go

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-popular-actions/testdata/registry/no_new_version.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
33
"slug": "rhysd/action-setup-vim",
4+
"skip_inputs": true,
45
"tags": ["v1"],
56
"next": "this-is-awesome-new-version"
67
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"slug": "rhysd/action-setup-vim",
4+
"tags": ["v1"],
5+
"next": "this-is-awesome-new-version",
6+
"skip_inputs": true,
7+
"skip_outputs": true
8+
}
9+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"slug": "rhysd/action-setup-vim",
4+
"tags": ["v1"],
5+
"next": "this-is-awesome-new-version",
6+
"skip_inputs": true
7+
}
8+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"slug": "rhysd/action-setup-vim",
4+
"skip_outputs": true,
5+
"tags": ["v1"],
6+
"next": "this-is-awesome-new-version"
7+
}
8+
]

0 commit comments

Comments
 (0)