Skip to content

Commit 0f60294

Browse files
committed
do not include metadata for actions which are known to be outdated
1 parent f00f5b3 commit 0f60294

11 files changed

+38
-41
lines changed

popular_actions.go

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

scripts/generate-popular-actions/main.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import (
2020
"gopkg.in/yaml.v3"
2121
)
2222

23+
// List of known outdated actions which cannot be detected from 'runs' in action.yml
24+
var outdatedActions = []string{
25+
"actions/labeler@v1",
26+
"actions/checkout@v1",
27+
"actions/upload-artifact@v1",
28+
"actions/download-artifact@v1",
29+
}
30+
2331
type actionOutput struct {
2432
Spec string `json:"spec"`
2533
Meta *actionlint.ActionMetadata `json:"metadata"`
@@ -65,11 +73,16 @@ var defaultPopularActionsJSON []byte
6573

6674
const minNodeRunnerVersion = 20
6775

68-
func isOutdatedRunner(r string) bool {
69-
if !strings.HasPrefix(r, "node") {
76+
func isOutdated(spec, runs string) bool {
77+
for _, s := range outdatedActions {
78+
if s == spec {
79+
return true
80+
}
81+
}
82+
if !strings.HasPrefix(runs, "node") {
7083
return false
7184
}
72-
v, err := strconv.ParseUint(r[len("node"):], 10, 8)
85+
v, err := strconv.ParseUint(runs[len("node"):], 10, 8)
7386
return err == nil && v < minNodeRunnerVersion
7487
}
7588

@@ -213,7 +226,7 @@ func (g *gen) fetchRemote() (map[string]*actionlint.ActionMetadata, error) {
213226
func (g *gen) writeJSONL(out io.Writer, actions map[string]*actionlint.ActionMetadata) error {
214227
enc := json.NewEncoder(out)
215228
for spec, meta := range actions {
216-
j := actionOutput{spec, meta, isOutdatedRunner(meta.Runs.Using)}
229+
j := actionOutput{spec, meta, isOutdated(spec, meta.Runs.Using)}
217230
if err := enc.Encode(&j); err != nil {
218231
return fmt.Errorf("could not encode action %q data into JSON: %w", spec, err)
219232
}
@@ -242,7 +255,7 @@ var PopularActions = map[string]*ActionMetadata{
242255
outdated := []string{}
243256
for _, spec := range specs {
244257
meta := actions[spec]
245-
if isOutdatedRunner(meta.Runs.Using) {
258+
if isOutdated(spec, meta.Runs.Using) {
246259
outdated = append(outdated, spec)
247260
continue
248261
}

scripts/generate-popular-actions/main_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ func TestReadWriteJSONL(t *testing.T) {
6868
"skip_both.jsonl",
6969
"skip_both.jsonl",
7070
"outdated.jsonl",
71+
"known_outdated.jsonl",
7172
}
7273

7374
for _, file := range files {
7475
t.Run(file, func(t *testing.T) {
75-
f := filepath.Join("testdata", "actions", file)
76+
f := filepath.Join("testdata", "jsonl", file)
7677
stdout := &bytes.Buffer{}
7778
stderr := &bytes.Buffer{}
7879

@@ -126,7 +127,7 @@ func TestWriteGoToStdout(t *testing.T) {
126127
t.Run(tc.in, func(t *testing.T) {
127128
stdout := &bytes.Buffer{}
128129
stderr := &bytes.Buffer{}
129-
status := newGen(stdout, stderr, io.Discard).run([]string{"test", "-s", filepath.Join("testdata", "actions", tc.in)})
130+
status := newGen(stdout, stderr, io.Discard).run([]string{"test", "-s", filepath.Join("testdata", "jsonl", tc.in)})
130131
if status != 0 {
131132
t.Fatalf("exit status is non-zero: %d: %s", status, stderr.Bytes())
132133
}
@@ -146,7 +147,7 @@ func TestWriteGoToStdout(t *testing.T) {
146147
}
147148

148149
func TestWriteJSONLFile(t *testing.T) {
149-
in := filepath.Join("testdata", "actions", "no_new_version.jsonl")
150+
in := filepath.Join("testdata", "jsonl", "no_new_version.jsonl")
150151
b, err := os.ReadFile(in)
151152
if err != nil {
152153
panic(err)
@@ -175,7 +176,7 @@ func TestWriteJSONLFile(t *testing.T) {
175176
}
176177

177178
func TestWriteGoFile(t *testing.T) {
178-
in := filepath.Join("testdata", "actions", "no_new_version.jsonl")
179+
in := filepath.Join("testdata", "jsonl", "no_new_version.jsonl")
179180
out := filepath.Join("testdata", "go", "out.go")
180181
defer os.Remove(out)
181182

@@ -246,7 +247,7 @@ func TestWriteOutdatedActionAsJSONL(t *testing.T) {
246247
t.Fatal("exit status is non-zero:", status)
247248
}
248249

249-
b, err := os.ReadFile(filepath.Join("testdata", "actions", "outdated.jsonl"))
250+
b, err := os.ReadFile(filepath.Join("testdata", "jsonl", "outdated.jsonl"))
250251
if err != nil {
251252
panic(err)
252253
}
@@ -257,7 +258,7 @@ func TestWriteOutdatedActionAsJSONL(t *testing.T) {
257258
}
258259

259260
func TestLogOutput(t *testing.T) {
260-
f := filepath.Join("testdata", "actions", "no_new_version.jsonl")
261+
f := filepath.Join("testdata", "jsonl", "no_new_version.jsonl")
261262
stdout := &bytes.Buffer{}
262263
logged := &bytes.Buffer{}
263264
status := newGen(stdout, io.Discard, logged).run([]string{"test", "-s", f, "-f", "jsonl"})
@@ -355,7 +356,7 @@ func TestCouldNotReadJSONLFile(t *testing.T) {
355356
}
356357
for _, tc := range testCases {
357358
t.Run(tc.file, func(t *testing.T) {
358-
f := filepath.Join("testdata", "actions", tc.file)
359+
f := filepath.Join("testdata", "jsonl", tc.file)
359360
stdout := io.Discard
360361
stderr := &bytes.Buffer{}
361362

@@ -373,7 +374,7 @@ func TestCouldNotReadJSONLFile(t *testing.T) {
373374
}
374375

375376
func TestCouldNotCreateOutputFile(t *testing.T) {
376-
f := filepath.Join("testdata", "actions", "no_new_version.jsonl")
377+
f := filepath.Join("testdata", "jsonl", "no_new_version.jsonl")
377378
out := filepath.Join("testdata", "this-dir-does-not-exit", "foo.jsonl")
378379
stdout := io.Discard
379380
stderr := &bytes.Buffer{}
@@ -398,7 +399,7 @@ func (w testErrorWriter) Write(b []byte) (int, error) {
398399
func TestWriteError(t *testing.T) {
399400
for _, format := range []string{"go", "jsonl"} {
400401
t.Run(format, func(t *testing.T) {
401-
f := filepath.Join("testdata", "actions", "no_new_version.jsonl")
402+
f := filepath.Join("testdata", "jsonl", "no_new_version.jsonl")
402403
stdout := testErrorWriter{}
403404
stderr := &bytes.Buffer{}
404405

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"spec":"actions/checkout@v1","metadata":{"name":"Checkout","inputs":{"clean":{"name":"clean","required":false},"fetch-depth":{"name":"fetch-depth","required":false},"lfs":{"name":"lfs","required":false},"path":{"name":"path","required":false},"ref":{"name":"ref","required":false},"repository":{"name":"repository","required":false},"submodules":{"name":"submodules","required":false},"token":{"name":"token","required":false}},"outputs":null,"skip_inputs":false,"skip_outputs":false,"runs":{"using":"","main":"","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,6 @@
1+
[
2+
{
3+
"slug": "actions/checkout",
4+
"tags": ["v1"]
5+
}
6+
]

0 commit comments

Comments
 (0)