Skip to content

Commit

Permalink
do not try to fetch next version of action metadata when next field…
Browse files Browse the repository at this point in the history
… is empty
  • Loading branch information
rhysd committed Mar 5, 2024
1 parent abb47d8 commit 5e32104
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
18 changes: 9 additions & 9 deletions scripts/generate-popular-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Please see output of `-help` flag for more details.
The data source of the popular actions is defined in [`popular_actions.json`](./popular_actions.json). This file contains an array
of each action registry. Each registry is a JSON object containing the following keys:

| Key | Description | Example | Required? |
|----------------|----------------------------------------------------------------|----------------------------|-----------|
| `slug` | GitHub repository slug | `"actions/checkout"` | Yes |
| `tags` | Known release tags | `["v1", "v2", "v3", "v4"]` | Yes |
| `next` | The next release tag | `"v5"` | Yes |
| `path` | Absolute path to the action from the repository root | `"/path/to/action"` | No |
| `skip_inputs` | Skipping checking inputs of this action or not | `true` | No |
| `skip_outputs` | Skipping checking outputs of this action or not | `true` | No |
| `file_ext` | File extension of action metadata file. The default is `"yml"` | `"yaml"` | No |
| Key | Description | Example | Required? |
|----------------|-----------------------------------------------------------------|----------------------------|-----------|
| `slug` | GitHub repository slug | `"actions/checkout"` | Yes |
| `tags` | Known release tags | `["v1", "v2", "v3", "v4"]` | Yes |
| `next` | The next release tag. Empty means new version won't be detected | `"v5"` | No |
| `path` | Absolute path to the action from the repository root | `"/path/to/action"` | No |
| `skip_inputs` | Skipping checking inputs of this action or not | `true` | No |
| `skip_outputs` | Skipping checking outputs of this action or not | `true` | No |
| `file_ext` | File extension of action metadata file. The default is `"yml"` | `"yaml"` | No |

Alternative actions registry JSON file can be used via `-r` option.
19 changes: 14 additions & 5 deletions scripts/generate-popular-actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,21 @@ func (g *gen) readJSONL(file string) (map[string]*actionlint.ActionMetadata, err
}

func (g *gen) detectNewReleaseURLs() ([]string, error) {
actions, err := g.registry()
all, err := g.registry()
if err != nil {
return nil, err
}

// Filter actions which have no next versions
actions := []*registry{}
for _, a := range all {
if a.Next != "" {
actions = append(actions, a)
}
}

g.log.Println("Start detecting new versions in", len(actions), "repositories")

urls := make(chan string)
done := make(chan struct{})
errs := make(chan error)
Expand All @@ -314,10 +324,6 @@ func (g *gen) detectNewReleaseURLs() ([]string, error) {
for {
select {
case r := <-reqs:
if r.Next == "" {
ret <- ""
break
}
url := r.rawURL(r.Next)
g.log.Println("Checking", url)
res, err := c.Head(url)
Expand Down Expand Up @@ -368,6 +374,8 @@ func (g *gen) detectNewReleaseURLs() ([]string, error) {
close(done)

sort.Strings(us)

g.log.Println("Done detecting new versions in", len(actions), "repositories")
return us, nil
}

Expand Down Expand Up @@ -439,6 +447,7 @@ Flags:`)
return 1
}
if len(urls) == 0 {
fmt.Fprintln(g.stdout, "No new release was found")
return 0
}
fmt.Fprintln(g.stdout, "Detected some new releases")
Expand Down
6 changes: 4 additions & 2 deletions scripts/generate-popular-actions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func TestDefaultPopularActions(t *testing.T) {

slugs := map[string]int{}
for i, a := range popularActions {
if j, ok := slugs[a.Slug]; ok && popularActions[i].Path == popularActions[j].Path {
t.Errorf("slug %q at popularActions[%d] was already added at popularActions[%d]", a.Slug, i, j)
if a.Slug == "" {
t.Errorf("repository slug must not empty at popularActions[%d]", i)
} else if j, ok := slugs[a.Slug]; ok && popularActions[i].Path == popularActions[j].Path {
t.Errorf("duplicate registry. action %q at popularActions[%d] was already added at popularActions[%d]", a.Slug, i, j)
} else {
slugs[a.Slug] = i
}
Expand Down
6 changes: 2 additions & 4 deletions scripts/generate-popular-actions/popular_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
},
{
"slug": "dtolnay/rust-toolchain",
"tags": ["stable", "beta", "nightly"],
"next": ""
"tags": ["stable", "beta", "nightly"]
},
{
"slug": "actions-rs/clippy-check",
Expand Down Expand Up @@ -319,8 +318,7 @@
},
{
"slug": "marvinpinto/action-automatic-releases",
"tags": ["latest"],
"next": ""
"tags": ["latest"]
},
{
"slug": "microsoft/playwright-github-action",
Expand Down

0 comments on commit 5e32104

Please sign in to comment.