From 6a6fd7bace3fa14c4c0198e5862757afce483d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 26 Sep 2022 10:44:24 +0200 Subject: [PATCH] Recognize `.yaml` in addition to `.yml` suffix as workflow file name --- pkg/cmd/workflow/run/run_test.go | 20 ++++++++++++++++++++ pkg/cmd/workflow/shared/shared.go | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/workflow/run/run_test.go b/pkg/cmd/workflow/run/run_test.go index 42fc6e962..c90c9a09e 100644 --- a/pkg/cmd/workflow/run/run_test.go +++ b/pkg/cmd/workflow/run/run_test.go @@ -470,6 +470,26 @@ jobs: wantErr: true, errOut: "could not create workflow dispatch event: HTTP 422 (https://api.github.com/repos/OWNER/REPO/actions/workflows/12345/dispatches)", }, + { + name: "yaml file extension", + tty: false, + opts: &RunOptions{ + Selector: "workflow.yaml", + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/workflow.yaml"), + httpmock.StatusStringResponse(200, `{"id": 12345}`)) + reg.Register( + httpmock.REST("POST", "repos/OWNER/REPO/actions/workflows/12345/dispatches"), + httpmock.StatusStringResponse(204, "")) + }, + wantBody: map[string]interface{}{ + "inputs": map[string]interface{}{}, + "ref": "trunk", + }, + wantErr: false, + }, { // TODO this test is somewhat silly; it's more of a placeholder in case I decide to handle the API error more elegantly name: "input fields, missing required", diff --git a/pkg/cmd/workflow/shared/shared.go b/pkg/cmd/workflow/shared/shared.go index ae5541824..efd21529e 100644 --- a/pkg/cmd/workflow/shared/shared.go +++ b/pkg/cmd/workflow/shared/shared.go @@ -124,7 +124,7 @@ func FindWorkflow(client *api.Client, repo ghrepo.Interface, workflowSelector st return nil, errors.New("empty workflow selector") } - if _, err := strconv.Atoi(workflowSelector); err == nil || strings.HasSuffix(workflowSelector, ".yml") { + if _, err := strconv.Atoi(workflowSelector); err == nil || isWorkflowFile(workflowSelector) { workflow, err := getWorkflowByID(client, repo, workflowSelector) if err != nil { return nil, err @@ -139,6 +139,11 @@ func GetWorkflow(client *api.Client, repo ghrepo.Interface, workflowID int64) (* return getWorkflowByID(client, repo, strconv.FormatInt(workflowID, 10)) } +func isWorkflowFile(f string) bool { + name := strings.ToLower(f) + return strings.HasSuffix(name, ".yml") || strings.HasSuffix(name, ".yaml") +} + // ID can be either a numeric database ID or the workflow file name func getWorkflowByID(client *api.Client, repo ghrepo.Interface, ID string) (*Workflow, error) { var workflow Workflow