From 70af21a8c9287cc4245462d9ffc9be7496cfc055 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 23 Sep 2022 12:06:03 +0900 Subject: [PATCH 1/4] ci: improve test --- .github/workflows/test.yaml | 396 ++++++++++++++++-------------- cmd/list/main.go | 29 +++ cmd/setter/main.go | 44 ++++ cmd/tester/main.go | 47 ++++ go.mod | 10 + go.sum | 9 + testdata/pull_request/normal.yaml | 49 ++++ 7 files changed, 403 insertions(+), 181 deletions(-) create mode 100644 cmd/list/main.go create mode 100644 cmd/setter/main.go create mode 100644 cmd/tester/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 testdata/pull_request/normal.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0e06201..793ef19 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,194 +7,228 @@ on: branches: [main] jobs: - test-pull-request: + list-files: runs-on: ubuntu-latest + outputs: + files: ${{env.FILES}} steps: - uses: actions/checkout@v3 - - uses: ./ + - uses: actions/setup-go@v3 with: - data: | - { - "event_name": "pull_request", - "event": { - "number": 149, - "sender": { - "login": "suzuki-shunsuke" - }, - "repository": { - "full_name": "gha-trigger/gha-trigger", - "name": "gha-trigger", - "owner": { - "login": "gha-trigger" - } - }, - "pull_request": { - "base": { - "ref": "main" - }, - "head": { - "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", - "ref": "renovate/github.com-aws-aws-sdk-go-1.x" - }, - "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" - } - }, - "pull_request": { - "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", - "base": { - "ref": "main" - }, - "head": { - "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", - "ref": "renovate/github.com-aws-aws-sdk-go-1.x" - }, - "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" - } - } - - name: Test GHA_ACTOR - run: | - [ "$GHA_ACTOR" = suzuki-shunsuke ] - - name: Test GHA_EVENT_NAME - run: | - [ "$GHA_EVENT_NAME" = pull_request ] - - name: Test GHA_REPOSITORY - run: | - [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] - - name: Test GHA_REPOSITORY_OWNER - run: | - [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] - - name: Test GHA_REPOSITORY_NAME - run: | - [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - - name: Test GHA_SHA - run: | - [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] - - name: Test GHA_COMMIT_STATUS_SHA - run: | - [ "$GHA_COMMIT_STATUS_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] - - name: Test GHA_BASE_REF - run: | - [ "$GHA_BASE_REF" = main ] - - name: Test GHA_HEAD_SHA - run: | - [ "$GHA_HEAD_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] - - name: Test GHA_REF - run: | - [ "$GHA_REF" = refs/pull/149/merge ] - - name: Test GHA_REF_NAME - run: | - [ "$GHA_REF_NAME" = 149/merge ] - - name: Test GHA_PULL_REQUEST_NUMBER - run: | - [ "$GHA_PULL_REQUEST_NUMBER" = 149 ] - - name: Test GHA_ENV - run: | - [ -n "$GHA_ENV" ] - test-push: + go-version: "1.19.1" + cache: true + - run: go run ./cmd/list + + test: runs-on: ubuntu-latest + name: "test (${{matrix.file}})" + needs: list-files + env: + FILE: ${{matrix.file}} + strategy: + fail-fast: false + matrix: + file: ${{fromJSON(needs.list-files.outputs.files)}} steps: - uses: actions/checkout@v3 - - uses: ./ + - uses: actions/setup-go@v3 with: - data: | - { - "event_name": "push", - "event": { - "ref": "refs/heads/renovate/github.com-aws-aws-sdk-go-1.x", - "sender": { - "login": "suzuki-shunsuke" - }, - "head_commit": { - "id": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2" - }, - "repository": { - "full_name": "gha-trigger/gha-trigger", - "name": "gha-trigger", - "owner": { - "login": "gha-trigger" - } - } - } - } - - name: Test GHA_ACTOR - run: | - [ "$GHA_ACTOR" = suzuki-shunsuke ] - - name: Test GHA_EVENT_NAME - run: | - [ "$GHA_EVENT_NAME" = push ] - - name: Test GHA_REPOSITORY - run: | - [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] - - name: Test GHA_REPOSITORY_OWNER - run: | - [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] - - name: Test GHA_REPOSITORY_NAME - run: | - [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - - name: Test GHA_SHA - run: | - [ "$GHA_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] - - name: Test GHA_COMMIT_STATUS_SHA - run: | - [ "$GHA_COMMIT_STATUS_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] - - name: Test GHA_REF - run: | - [ "$GHA_REF" = refs/heads/renovate/github.com-aws-aws-sdk-go-1.x ] - - name: Test GHA_REF_NAME - run: | - [ "$GHA_REF_NAME" = renovate/github.com-aws-aws-sdk-go-1.x ] - - name: Test GHA_ENV - run: | - [ -n "$GHA_ENV" ] - test-release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + go-version: "1.19.1" + cache: true + - run: go run ./cmd/setter "$FILE" - uses: ./ with: - data: | - { - "event_name": "release", - "event": { - "sender": { - "login": "suzuki-shunsuke" - }, - "release": { - "tag_name": "v0.1.0" - }, - "repository": { - "full_name": "gha-trigger/gha-trigger", - "name": "gha-trigger", - "owner": { - "login": "gha-trigger" - } - } - } - } - - name: Test GHA_ACTOR - run: | - [ "$GHA_ACTOR" = suzuki-shunsuke ] - - name: Test GHA_EVENT_NAME - run: | - [ "$GHA_EVENT_NAME" = release ] - - name: Test GHA_REPOSITORY - run: | - [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] - - name: Test GHA_REPOSITORY_OWNER - run: | - [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] - - name: Test GHA_REPOSITORY_NAME - run: | - [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - - name: Test GHA_SHA - run: | - [ "$GHA_SHA" = "" ] - - name: Test GHA_REF - run: | - [ "$GHA_REF" = v0.1.0 ] - - name: Test GHA_REF_NAME - run: | - [ "$GHA_REF_NAME" = v0.1.0 ] - - name: Test GHA_ENV - run: | - [ -n "$GHA_ENV" ] + data: ${{toJSON(fromJSON(env.DATA).data)}} + - run: go run ./cmd/tester "$FILE" + + # test-pull-request: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - uses: ./ + # with: + # data: | + # { + # "event_name": "pull_request", + # "event": { + # "number": 149, + # "sender": { + # "login": "suzuki-shunsuke" + # }, + # "repository": { + # "full_name": "gha-trigger/gha-trigger", + # "name": "gha-trigger", + # "owner": { + # "login": "gha-trigger" + # } + # }, + # "pull_request": { + # "base": { + # "ref": "main" + # }, + # "head": { + # "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", + # "ref": "renovate/github.com-aws-aws-sdk-go-1.x" + # }, + # "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" + # } + # }, + # "pull_request": { + # "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", + # "base": { + # "ref": "main" + # }, + # "head": { + # "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", + # "ref": "renovate/github.com-aws-aws-sdk-go-1.x" + # }, + # "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" + # } + # } + # - name: Test GHA_ACTOR + # run: | + # [ "$GHA_ACTOR" = suzuki-shunsuke ] + # - name: Test GHA_EVENT_NAME + # run: | + # [ "$GHA_EVENT_NAME" = pull_request ] + # - name: Test GHA_REPOSITORY + # run: | + # [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] + # - name: Test GHA_REPOSITORY_OWNER + # run: | + # [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] + # - name: Test GHA_REPOSITORY_NAME + # run: | + # [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + # - name: Test GHA_SHA + # run: | + # [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + # - name: Test GHA_COMMIT_STATUS_SHA + # run: | + # [ "$GHA_COMMIT_STATUS_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] + # - name: Test GHA_BASE_REF + # run: | + # [ "$GHA_BASE_REF" = main ] + # - name: Test GHA_HEAD_SHA + # run: | + # [ "$GHA_HEAD_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] + # - name: Test GHA_REF + # run: | + # [ "$GHA_REF" = refs/pull/149/merge ] + # - name: Test GHA_REF_NAME + # run: | + # [ "$GHA_REF_NAME" = 149/merge ] + # - name: Test GHA_PULL_REQUEST_NUMBER + # run: | + # [ "$GHA_PULL_REQUEST_NUMBER" = 149 ] + # - name: Test GHA_ENV + # run: | + # [ -n "$GHA_ENV" ] + # test-push: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - uses: ./ + # with: + # data: | + # { + # "event_name": "push", + # "event": { + # "ref": "refs/heads/renovate/github.com-aws-aws-sdk-go-1.x", + # "sender": { + # "login": "suzuki-shunsuke" + # }, + # "head_commit": { + # "id": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2" + # }, + # "repository": { + # "full_name": "gha-trigger/gha-trigger", + # "name": "gha-trigger", + # "owner": { + # "login": "gha-trigger" + # } + # } + # } + # } + # - name: Test GHA_ACTOR + # run: | + # [ "$GHA_ACTOR" = suzuki-shunsuke ] + # - name: Test GHA_EVENT_NAME + # run: | + # [ "$GHA_EVENT_NAME" = push ] + # - name: Test GHA_REPOSITORY + # run: | + # [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] + # - name: Test GHA_REPOSITORY_OWNER + # run: | + # [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] + # - name: Test GHA_REPOSITORY_NAME + # run: | + # [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + # - name: Test GHA_SHA + # run: | + # [ "$GHA_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] + # - name: Test GHA_COMMIT_STATUS_SHA + # run: | + # [ "$GHA_COMMIT_STATUS_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] + # - name: Test GHA_REF + # run: | + # [ "$GHA_REF" = refs/heads/renovate/github.com-aws-aws-sdk-go-1.x ] + # - name: Test GHA_REF_NAME + # run: | + # [ "$GHA_REF_NAME" = renovate/github.com-aws-aws-sdk-go-1.x ] + # - name: Test GHA_ENV + # run: | + # [ -n "$GHA_ENV" ] + # test-release: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - uses: ./ + # with: + # data: | + # { + # "event_name": "release", + # "event": { + # "sender": { + # "login": "suzuki-shunsuke" + # }, + # "release": { + # "tag_name": "v0.1.0" + # }, + # "repository": { + # "full_name": "gha-trigger/gha-trigger", + # "name": "gha-trigger", + # "owner": { + # "login": "gha-trigger" + # } + # } + # } + # } + # - name: Test GHA_ACTOR + # run: | + # [ "$GHA_ACTOR" = suzuki-shunsuke ] + # - name: Test GHA_EVENT_NAME + # run: | + # [ "$GHA_EVENT_NAME" = release ] + # - name: Test GHA_REPOSITORY + # run: | + # [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] + # - name: Test GHA_REPOSITORY_OWNER + # run: | + # [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] + # - name: Test GHA_REPOSITORY_NAME + # run: | + # [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + # - name: Test GHA_SHA + # run: | + # [ "$GHA_SHA" = "" ] + # - name: Test GHA_REF + # run: | + # [ "$GHA_REF" = v0.1.0 ] + # - name: Test GHA_REF_NAME + # run: | + # [ "$GHA_REF_NAME" = v0.1.0 ] + # - name: Test GHA_ENV + # run: | + # [ -n "$GHA_ENV" ] diff --git a/cmd/list/main.go b/cmd/list/main.go new file mode 100644 index 0000000..477fa85 --- /dev/null +++ b/cmd/list/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "encoding/json" + "log" + "path/filepath" + + "github.com/sethvargo/go-githubactions" +) + +func main() { + if err := core(); err != nil { + log.Fatal(err) + } +} + +func core() error { + files, err := filepath.Glob("testdata/*/*") + if err != nil { + return err + } + b, err := json.Marshal(files) + if err != nil { + return err + } + + githubactions.SetEnv("FILES", string(b)) + return nil +} diff --git a/cmd/setter/main.go b/cmd/setter/main.go new file mode 100644 index 0000000..ff37154 --- /dev/null +++ b/cmd/setter/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/json" + "log" + "os" + + "github.com/sethvargo/go-githubactions" + "gopkg.in/yaml.v3" +) + +func main() { + if err := core(); err != nil { + log.Fatal(err) + } +} + +type Config struct { + Envs map[string]string + Data interface{} +} + +func core() error { + // read config file + // test envs + file := os.Args[1] + cfg := &Config{} + f, err := os.Open(file) + if err != nil { + return err + } + defer f.Close() + if err := yaml.NewDecoder(f).Decode(cfg); err != nil { + return err + } + + b, err := json.Marshal(cfg) + if err != nil { + return err + } + + githubactions.SetEnv("DATA", string(b)) + return nil +} diff --git a/cmd/tester/main.go b/cmd/tester/main.go new file mode 100644 index 0000000..314ba98 --- /dev/null +++ b/cmd/tester/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "errors" + "log" + "os" + + "gopkg.in/yaml.v3" +) + +func main() { + if err := core(); err != nil { + log.Fatal(err) + } +} + +type Config struct { + Envs map[string]string + Data interface{} +} + +func core() error { + // read config file + // test envs + file := os.Args[1] + cfg := &Config{} + f, err := os.Open(file) + if err != nil { + return err + } + defer f.Close() + if err := yaml.NewDecoder(f).Decode(cfg); err != nil { + return err + } + failed := false + for envName, expValue := range cfg.Envs { + actValue := os.Getenv(envName) + if expValue != actValue { + log.Printf("[ERROR] the environment variable %s is wrong: wanted %s, got %s", envName, expValue, actValue) + failed = true + } + } + if failed { + return errors.New("[ERROR] Some environment variables are wrong") + } + return nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ad34a8f --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/gha-trigger/set-env-action + +go 1.19 + +require ( + github.com/sethvargo/go-githubactions v1.0.0 + gopkg.in/yaml.v3 v3.0.1 +) + +require github.com/sethvargo/go-envconfig v0.6.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..36f579c --- /dev/null +++ b/go.sum @@ -0,0 +1,9 @@ +github.com/google/go-cmp v0.4.1 h1:/exdXoGamhu5ONeUJH0deniYLWYvQwW66yvlfiiKTu0= +github.com/sethvargo/go-envconfig v0.6.0 h1:GxxdoeiNpWgGiVEphNFNObgMYRN/ZvI2dN7rBwadyss= +github.com/sethvargo/go-envconfig v0.6.0/go.mod h1:00S1FAhRUuTNJazWBWcJGvEHOM+NO6DhoRMAOX7FY5o= +github.com/sethvargo/go-githubactions v1.0.0 h1:5mYGPNxIwIXaS8MLj4uYGWM8QM8giUVqA4FuSYOZjXE= +github.com/sethvargo/go-githubactions v1.0.0/go.mod h1:UaidDD1ENTLXzTtj/4MnYjY40/5WLijgn2O8KBsdv7o= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/testdata/pull_request/normal.yaml b/testdata/pull_request/normal.yaml new file mode 100644 index 0000000..d91340b --- /dev/null +++ b/testdata/pull_request/normal.yaml @@ -0,0 +1,49 @@ +envs: + GHA_ACTOR: suzuki-shunsuke + GHA_EVENT_NAME: pull_request + GHA_REPOSITORY: gha-trigger/gha-trigger + GHA_REPOSITORY_OWNER: gha-trigger + GHA_REPOSITORY_NAME: gha-trigger + GHA_SHA: 4528ea7ab7a8eef7e596097934a78eab90fb8b33 + GHA_COMMIT_STATUS_SHA: b6d8f3331c6845997b9408163a127e01fd32c120 + GHA_BASE_REF: main + GHA_HEAD_SHA: b6d8f3331c6845997b9408163a127e01fd32c120 + GHA_REF: refs/pull/149/merge + GHA_REF_NAME: 149/merge + GHA_PULL_REQUEST_NUMBER: "149" +data: + { + "event_name": "pull_request", + "event": + { + "number": 149, + "sender": { "login": "suzuki-shunsuke" }, + "repository": + { + "full_name": "gha-trigger/gha-trigger", + "name": "gha-trigger", + "owner": { "login": "gha-trigger" }, + }, + "pull_request": + { + "base": { "ref": "main" }, + "head": + { + "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", + "ref": "renovate/github.com-aws-aws-sdk-go-1.x", + }, + "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9", + }, + }, + "pull_request": + { + "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", + "base": { "ref": "main" }, + "head": + { + "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", + "ref": "renovate/github.com-aws-aws-sdk-go-1.x", + }, + "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9", + }, + } From 0a767a24457323b5e724a1784dce3598c56b8a17 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 23 Sep 2022 12:16:10 +0900 Subject: [PATCH 2/4] chore: fix testdata --- testdata/pull_request/normal.yaml | 52 ++++++++++--------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/testdata/pull_request/normal.yaml b/testdata/pull_request/normal.yaml index d91340b..3b66f75 100644 --- a/testdata/pull_request/normal.yaml +++ b/testdata/pull_request/normal.yaml @@ -12,38 +12,20 @@ envs: GHA_REF_NAME: 149/merge GHA_PULL_REQUEST_NUMBER: "149" data: - { - "event_name": "pull_request", - "event": - { - "number": 149, - "sender": { "login": "suzuki-shunsuke" }, - "repository": - { - "full_name": "gha-trigger/gha-trigger", - "name": "gha-trigger", - "owner": { "login": "gha-trigger" }, - }, - "pull_request": - { - "base": { "ref": "main" }, - "head": - { - "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", - "ref": "renovate/github.com-aws-aws-sdk-go-1.x", - }, - "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9", - }, - }, - "pull_request": - { - "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", - "base": { "ref": "main" }, - "head": - { - "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", - "ref": "renovate/github.com-aws-aws-sdk-go-1.x", - }, - "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9", - }, - } + event_name: pull_request + event: + number: 149 + sender: + login: suzuki-shunsuke + repository: + full_name: gha-trigger/gha-trigger + name: gha-trigger + owner: + login: gha-trigger + pull_request: + merge_commit_sha: 4528ea7ab7a8eef7e596097934a78eab90fb8b33 + base: + ref: main + head: + sha: b6d8f3331c6845997b9408163a127e01fd32c120 + ref: renovate/github.com-aws-aws-sdk-go-1.x From 14fd5cf88dcba3b8f44dff7183b671d8936deee7 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 23 Sep 2022 12:20:28 +0900 Subject: [PATCH 3/4] ci: add testdata push/normal --- .github/workflows/test.yaml | 113 ------------------------------------ testdata/push/normal.yaml | 24 ++++++++ 2 files changed, 24 insertions(+), 113 deletions(-) create mode 100644 testdata/push/normal.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 793ef19..e74b253 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -41,89 +41,6 @@ jobs: data: ${{toJSON(fromJSON(env.DATA).data)}} - run: go run ./cmd/tester "$FILE" - # test-pull-request: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - uses: ./ - # with: - # data: | - # { - # "event_name": "pull_request", - # "event": { - # "number": 149, - # "sender": { - # "login": "suzuki-shunsuke" - # }, - # "repository": { - # "full_name": "gha-trigger/gha-trigger", - # "name": "gha-trigger", - # "owner": { - # "login": "gha-trigger" - # } - # }, - # "pull_request": { - # "base": { - # "ref": "main" - # }, - # "head": { - # "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", - # "ref": "renovate/github.com-aws-aws-sdk-go-1.x" - # }, - # "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" - # } - # }, - # "pull_request": { - # "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", - # "base": { - # "ref": "main" - # }, - # "head": { - # "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", - # "ref": "renovate/github.com-aws-aws-sdk-go-1.x" - # }, - # "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" - # } - # } - # - name: Test GHA_ACTOR - # run: | - # [ "$GHA_ACTOR" = suzuki-shunsuke ] - # - name: Test GHA_EVENT_NAME - # run: | - # [ "$GHA_EVENT_NAME" = pull_request ] - # - name: Test GHA_REPOSITORY - # run: | - # [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] - # - name: Test GHA_REPOSITORY_OWNER - # run: | - # [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] - # - name: Test GHA_REPOSITORY_NAME - # run: | - # [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - # - name: Test GHA_SHA - # run: | - # [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] - # - name: Test GHA_COMMIT_STATUS_SHA - # run: | - # [ "$GHA_COMMIT_STATUS_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] - # - name: Test GHA_BASE_REF - # run: | - # [ "$GHA_BASE_REF" = main ] - # - name: Test GHA_HEAD_SHA - # run: | - # [ "$GHA_HEAD_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] - # - name: Test GHA_REF - # run: | - # [ "$GHA_REF" = refs/pull/149/merge ] - # - name: Test GHA_REF_NAME - # run: | - # [ "$GHA_REF_NAME" = 149/merge ] - # - name: Test GHA_PULL_REQUEST_NUMBER - # run: | - # [ "$GHA_PULL_REQUEST_NUMBER" = 149 ] - # - name: Test GHA_ENV - # run: | - # [ -n "$GHA_ENV" ] # test-push: # runs-on: ubuntu-latest # steps: @@ -150,36 +67,6 @@ jobs: # } # } # } - # - name: Test GHA_ACTOR - # run: | - # [ "$GHA_ACTOR" = suzuki-shunsuke ] - # - name: Test GHA_EVENT_NAME - # run: | - # [ "$GHA_EVENT_NAME" = push ] - # - name: Test GHA_REPOSITORY - # run: | - # [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] - # - name: Test GHA_REPOSITORY_OWNER - # run: | - # [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] - # - name: Test GHA_REPOSITORY_NAME - # run: | - # [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - # - name: Test GHA_SHA - # run: | - # [ "$GHA_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] - # - name: Test GHA_COMMIT_STATUS_SHA - # run: | - # [ "$GHA_COMMIT_STATUS_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] - # - name: Test GHA_REF - # run: | - # [ "$GHA_REF" = refs/heads/renovate/github.com-aws-aws-sdk-go-1.x ] - # - name: Test GHA_REF_NAME - # run: | - # [ "$GHA_REF_NAME" = renovate/github.com-aws-aws-sdk-go-1.x ] - # - name: Test GHA_ENV - # run: | - # [ -n "$GHA_ENV" ] # test-release: # runs-on: ubuntu-latest # steps: diff --git a/testdata/push/normal.yaml b/testdata/push/normal.yaml new file mode 100644 index 0000000..1b90c92 --- /dev/null +++ b/testdata/push/normal.yaml @@ -0,0 +1,24 @@ +envs: + GHA_ACTOR: suzuki-shunsuke + GHA_EVENT_NAME: push + GHA_REPOSITORY: gha-trigger/gha-trigger + GHA_REPOSITORY_OWNER: gha-trigger + GHA_REPOSITORY_NAME: gha-trigger + GHA_SHA: a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 + GHA_COMMIT_STATUS_SHA: a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 + GHA_REF: refs/heads/renovate/github.com-aws-aws-sdk-go-1.x + GHA_REF_NAME: renovate/github.com-aws-aws-sdk-go-1.x + +data: + event_name: push + event: + ref: refs/heads/renovate/github.com-aws-aws-sdk-go-1.x + sender: + login: suzuki-shunsuke + head_commit: + id: a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 + repository: + full_name: gha-trigger/gha-trigger + name: gha-trigger + owner: + login: gha-trigger From 354d47329ace8ea54882b6835b007c0100dc8fba Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 23 Sep 2022 12:28:10 +0900 Subject: [PATCH 4/4] ci: add testdata --- .github/workflows/test.yaml | 79 ------------------------------------ testdata/release/normal.yaml | 23 +++++++++++ 2 files changed, 23 insertions(+), 79 deletions(-) create mode 100644 testdata/release/normal.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e74b253..5c13d17 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,82 +40,3 @@ jobs: with: data: ${{toJSON(fromJSON(env.DATA).data)}} - run: go run ./cmd/tester "$FILE" - - # test-push: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - uses: ./ - # with: - # data: | - # { - # "event_name": "push", - # "event": { - # "ref": "refs/heads/renovate/github.com-aws-aws-sdk-go-1.x", - # "sender": { - # "login": "suzuki-shunsuke" - # }, - # "head_commit": { - # "id": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2" - # }, - # "repository": { - # "full_name": "gha-trigger/gha-trigger", - # "name": "gha-trigger", - # "owner": { - # "login": "gha-trigger" - # } - # } - # } - # } - # test-release: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - uses: ./ - # with: - # data: | - # { - # "event_name": "release", - # "event": { - # "sender": { - # "login": "suzuki-shunsuke" - # }, - # "release": { - # "tag_name": "v0.1.0" - # }, - # "repository": { - # "full_name": "gha-trigger/gha-trigger", - # "name": "gha-trigger", - # "owner": { - # "login": "gha-trigger" - # } - # } - # } - # } - # - name: Test GHA_ACTOR - # run: | - # [ "$GHA_ACTOR" = suzuki-shunsuke ] - # - name: Test GHA_EVENT_NAME - # run: | - # [ "$GHA_EVENT_NAME" = release ] - # - name: Test GHA_REPOSITORY - # run: | - # [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] - # - name: Test GHA_REPOSITORY_OWNER - # run: | - # [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] - # - name: Test GHA_REPOSITORY_NAME - # run: | - # [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - # - name: Test GHA_SHA - # run: | - # [ "$GHA_SHA" = "" ] - # - name: Test GHA_REF - # run: | - # [ "$GHA_REF" = v0.1.0 ] - # - name: Test GHA_REF_NAME - # run: | - # [ "$GHA_REF_NAME" = v0.1.0 ] - # - name: Test GHA_ENV - # run: | - # [ -n "$GHA_ENV" ] diff --git a/testdata/release/normal.yaml b/testdata/release/normal.yaml new file mode 100644 index 0000000..9f33075 --- /dev/null +++ b/testdata/release/normal.yaml @@ -0,0 +1,23 @@ +envs: + GHA_ACTOR: suzuki-shunsuke + GHA_EVENT_NAME: release + GHA_REPOSITORY: gha-trigger/gha-trigger + GHA_REPOSITORY_OWNER: gha-trigger + GHA_REPOSITORY_NAME: gha-trigger + GHA_SHA: + GHA_COMMIT_STATUS_SHA: + GHA_REF: v0.1.0 + GHA_REF_NAME: v0.1.0 + +data: + event_name: release + event: + sender: + login: suzuki-shunsuke + release: + tag_name: v0.1.0 + repository: + full_name: gha-trigger/gha-trigger + name: gha-trigger + owner: + login: gha-trigger