Skip to content

Commit

Permalink
ci: test newly added tag
Browse files Browse the repository at this point in the history
We run test with the tag set (to make sure nothing is broken),
and also the check-binary-size target (for informational purposes only).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Apr 25, 2022
1 parent 49e43be commit b8cb475
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ jobs:
- name: vet
run: go run internal/build/build.go vet

- name: test with tags
run: go run internal/build/build.go -tags urfave_cli_no_docs test

- name: test
run: go run internal/build/build.go test

- name: check-binary-size
run: go run internal/build/build.go check-binary-size

- name: check-binary-size with tags (informational only)
run: go run internal/build/build.go -tags urfave_cli_no_docs check-binary-size || true

- name: Upload coverage to Codecov
if: success() && matrix.go == '1.18.x' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v2
Expand Down
20 changes: 15 additions & 5 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func main() {
Action: checkBinarySizeActionFunc,
},
}
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "tags",
Usage: "set build tags",
},
}

err := app.Run(os.Args)
if err != nil {
Expand All @@ -68,6 +74,8 @@ func VetActionFunc(_ *cli.Context) error {
}

func TestActionFunc(c *cli.Context) error {
tags := c.String("tags")

for _, pkg := range packages {
var packageName string

Expand All @@ -79,7 +87,7 @@ func TestActionFunc(c *cli.Context) error {

coverProfile := fmt.Sprintf("--coverprofile=%s.coverprofile", pkg)

err := runCmd("go", "test", "-v", coverProfile, packageName)
err := runCmd("go", "test", "-tags", tags, "-v", coverProfile, packageName)
if err != nil {
return err
}
Expand Down Expand Up @@ -201,14 +209,16 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) {
mbStringFormatter = "%.1fMB"
)

tags := c.String("tags")

// get cli example size
cliSize, err := getSize(cliSourceFilePath, cliBuiltFilePath)
cliSize, err := getSize(cliSourceFilePath, cliBuiltFilePath, tags)
if err != nil {
return err
}

// get hello world size
helloSize, err := getSize(helloSourceFilePath, helloBuiltFilePath)
helloSize, err := getSize(helloSourceFilePath, helloBuiltFilePath, tags)
if err != nil {
return err
}
Expand Down Expand Up @@ -270,9 +280,9 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) {
return nil
}

func getSize(sourcePath string, builtPath string) (size int64, err error) {
func getSize(sourcePath string, builtPath string, tags string) (size int64, err error) {
// build example binary
err = runCmd("go", "build", "-o", builtPath, "-ldflags", "-s -w", sourcePath)
err = runCmd("go", "build", "-tags", tags, "-o", builtPath, "-ldflags", "-s -w", sourcePath)
if err != nil {
fmt.Println("issue getting size for example binary")
return 0, err
Expand Down

0 comments on commit b8cb475

Please sign in to comment.