diff --git a/.github/workflows/301-flow-pull-request-checks.yaml b/.github/workflows/301-flow-pull-request-checks.yaml index 0a649b1..111bad5 100644 --- a/.github/workflows/301-flow-pull-request-checks.yaml +++ b/.github/workflows/301-flow-pull-request-checks.yaml @@ -25,7 +25,12 @@ jobs: checkout-ref: '${{ github.ref }}' checkout-token: '${{ secrets.GITHUB_TOKEN }}' setup-go: 'true' - go-version: '1.26.0' + go-version: '1.26.1' + + - name: Install Task + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 + with: + version: 3.x - name: Build run: | diff --git a/.github/workflows/302-flow-publish-release.yaml b/.github/workflows/302-flow-publish-release.yaml index 7613dc7..c18e1b7 100644 --- a/.github/workflows/302-flow-publish-release.yaml +++ b/.github/workflows/302-flow-publish-release.yaml @@ -21,10 +21,12 @@ jobs: checkout: 'true' checkout-token: '${{ secrets.GITHUB_TOKEN }}' setup-go: 'true' - go-version: '1.25' + go-version: '1.26.1' - name: Install Task - run: go install github.com/go-task/task/v3/cmd/task@latest + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 + with: + version: 3.x - name: Run tests run: task test @@ -84,10 +86,12 @@ jobs: checkout: 'true' checkout-token: '${{ secrets.GITHUB_TOKEN }}' setup-go: 'true' - go-version: '1.25' + go-version: '1.26.1' - name: Install Task - run: go install github.com/go-task/task/v3/cmd/task@latest + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 + with: + version: 3.x - name: Build release binaries run: task build-release VERSION=${{ needs.release.outputs.new_release_version }} diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index cc7648f..cf2fd0c 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -30,5 +30,4 @@ jobs: - name: Setup Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: - go-version: 1.26.0 - + go-version: 1.26.1 diff --git a/Taskfile.yml b/Taskfile.yml index 5cd69fe..b08ac4f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,4 @@ -version: '0.0.1' +version: '3' tasks: default: @@ -88,4 +88,3 @@ tasks: - GOOS=linux GOARCH=arm64 go build -o ../dist/chewie-linux-arm64 ./cmd/chewie - GOOS=darwin GOARCH=amd64 go build -o ../dist/chewie-darwin-amd64 ./cmd/chewie - GOOS=darwin GOARCH=arm64 go build -o ../dist/chewie-darwin-arm64 ./cmd/chewie - diff --git a/chewie/cmd/chewie/main.go b/chewie/cmd/chewie/main.go new file mode 100644 index 0000000..05dd590 --- /dev/null +++ b/chewie/cmd/chewie/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "flag" + "fmt" + "io" + "os" +) + +const version = "0.0.1" + +const helpText = `chewie - Chewie CLI + +USAGE: + chewie [OPTIONS] + +OPTIONS + -h, --help Show this help message + -v, --version Show version information + +DESCRIPTION: + The chewie CLI tool interfaces with the Chewie GitHub App (github.com/swirldslabs/chewie). + It provides commands to manage and interact with Chewie's features, such as creating requests + and polling request status. The chewie CLI also allows for configuration of a repositories chewie + config for authorized users. The tool is intended to primarily be used in GitHub CI/CD environments. + +EXAMPLES: + chewie -h + chewie -v + +EXIT CODES: + 0 Command executed successfully + 2 Error Occurred +` + +var osExit = os.Exit + +func run(args []string, stdout, stderr io.Writer, stdin io.Reader) int { + fs := flag.NewFlagSet("chewie", flag.ContinueOnError) + fs.SetOutput(stderr) + + var ( + showHelp bool + showVer bool + ) + + fs.BoolVar(&showHelp, "h", false, "show help") + fs.BoolVar(&showHelp, "help", false, "show help") + fs.BoolVar(&showVer, "v", false, "show version") + fs.BoolVar(&showVer, "version", false, "show version") + + if err := fs.Parse(args); err != nil { + return 2 + } + + if showHelp || len(args) == 0 { + fmt.Fprint(stdout, helpText) + } + + if showVer { + fmt.Fprintf(stdout, "chewie CLI version %s\n", version) + } + + return 0 +} + +func main() { + osExit(run(os.Args[1:], os.Stdout, os.Stderr, os.Stdin)) +} diff --git a/chewie/cmd/chewie/main_test.go b/chewie/cmd/chewie/main_test.go new file mode 100644 index 0000000..001f670 --- /dev/null +++ b/chewie/cmd/chewie/main_test.go @@ -0,0 +1,81 @@ +package main + +import ( + "bytes" + "strings" + "testing" +) + +func TestRun_NoArgs(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), "chewie - Chewie CLI") { + t.Errorf("expected help text in stdout, got: %q", stdout.String()) + } +} + +func TestRun_ShortHelp(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"-h"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), "chewie - Chewie CLI") { + t.Errorf("expected help text in stdout, got: %q", stdout.String()) + } +} + +func TestRun_LongHelp(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"--help"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), "chewie - Chewie CLI") { + t.Errorf("expected help text in stdout, got: %q", stdout.String()) + } +} + +func TestRun_ShortVersion(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"-v"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), version) { + t.Errorf("expected version %q in stdout, got: %q", version, stdout.String()) + } +} + +func TestRun_LongVersion(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"--version"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), version) { + t.Errorf("expected version %q in stdout, got: %q", version, stdout.String()) + } +} + +func TestRun_InvalidFlag(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"--unknown"}, &stdout, &stderr, nil) + if code != 2 { + t.Errorf("expected exit code 2, got %d", code) + } +} + +func TestRun_HelpContainsUsage(t *testing.T) { + var stdout, stderr bytes.Buffer + run([]string{"-h"}, &stdout, &stderr, nil) + out := stdout.String() + for _, expected := range []string{"USAGE:", "OPTIONS", "DESCRIPTION:", "EXAMPLES:", "EXIT CODES:"} { + if !strings.Contains(out, expected) { + t.Errorf("help text missing section %q", expected) + } + } +}