This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from gha-trigger/ci/improve-test
ci: improve test
- Loading branch information
Showing
9 changed files
with
240 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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: | ||
merge_commit_sha: 4528ea7ab7a8eef7e596097934a78eab90fb8b33 | ||
base: | ||
ref: main | ||
head: | ||
sha: b6d8f3331c6845997b9408163a127e01fd32c120 | ||
ref: renovate/github.com-aws-aws-sdk-go-1.x |
Oops, something went wrong.