-
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 #1 from chrisgavin/initial-code
Add the initial code.
- Loading branch information
Showing
15 changed files
with
667 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17.1 | ||
- name: Build | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: --rm-dist --snapshot | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17.1 | ||
- name: Test | ||
run: go test ./... | ||
|
||
lint: | ||
name: Lint | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17.1 | ||
- name: Check Modules | ||
run: | | ||
go mod tidy | ||
if [ ! -z "$(git status --porcelain=v1)" ]; then | ||
>&2 echo "Please run \`go mod tidy\` and commit the result." | ||
exit 1 | ||
fi | ||
- name: Lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.29 |
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,26 @@ | ||
name: CodeQL | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
schedule: | ||
- cron: 0 0 * * 0 | ||
|
||
jobs: | ||
analyse: | ||
name: Analyse | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v1 | ||
with: | ||
languages: go | ||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v1 |
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,27 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "**" | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17.1 | ||
- name: Release | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,2 @@ | ||
/dist/ | ||
/gh-dispatch |
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,12 @@ | ||
project_name: gh-dispatch | ||
|
||
builds: | ||
- goos: [linux, darwin, windows] | ||
goarch: [amd64, arm64] | ||
ldflags: | ||
- -X github.com/chrisgavin/gh-dispatch/internal/version.version={{.Version}} | ||
- -X github.com/chrisgavin/gh-dispatch/internal/version.commit={{.Commit}} | ||
|
||
archives: | ||
- format: binary | ||
name_template: "gh-dispatch-{{.Os}}-{{.Arch}}" |
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,111 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/chrisgavin/gh-dispatch/internal/dispatcher" | ||
"github.com/chrisgavin/gh-dispatch/internal/locator" | ||
"github.com/chrisgavin/gh-dispatch/internal/version" | ||
"github.com/cli/go-gh" | ||
"github.com/go-git/go-git/v5" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type rootFlagFields struct { | ||
} | ||
|
||
var rootFlags = rootFlagFields{} | ||
|
||
var SilentErr = errors.New("SilentErr") | ||
|
||
var rootCmd = &cobra.Command{ | ||
Short: "A GitHub CLI extension that makes it easy to dispatch GitHub Actions workflows.", | ||
Version: fmt.Sprintf("%s (%s)", version.Version(), version.Commit()), | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
workflows, err := locator.ListWorkflowsInRepository() | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to list workflows in repository.") | ||
} | ||
if len(workflows) == 0 { | ||
log.Error("No dispatchable workflows found in repository.") | ||
return SilentErr | ||
} | ||
workflowNames := []string{} | ||
for workflowName := range workflows { | ||
workflowNames = append(workflowNames, workflowName) | ||
} | ||
workflowQuestion := &survey.Select{ | ||
Message: "What workflow do you want to dispatch?", | ||
Options: workflowNames, | ||
} | ||
|
||
var workflowName string | ||
if err := survey.AskOne(workflowQuestion, &workflowName); err != nil { | ||
return errors.Wrap(err, "Unable to ask for workflow.") | ||
} | ||
|
||
workflow := workflows[workflowName] | ||
|
||
inputQuestions := []*survey.Question{} | ||
for _, input := range workflow.Inputs { | ||
inputQuestions = append(inputQuestions, &survey.Question{ | ||
Name: input.Name, | ||
Prompt: &survey.Input{ | ||
Message: fmt.Sprintf("Input for %s:", input.Name), | ||
Help: input.Description, | ||
}, | ||
}) | ||
} | ||
inputAnswers := map[string]interface{}{} | ||
if err := survey.Ask(inputQuestions, &inputAnswers); err != nil { | ||
return errors.Wrap(err, "Unable to ask for inputs.") | ||
} | ||
|
||
currentRepository, err := gh.CurrentRepository() | ||
if err != nil { | ||
return errors.Wrap(err, "Unable to determine current repository. Has it got a remote on GitHub?") | ||
} | ||
|
||
gitRepository, err := git.PlainOpen(".") | ||
if err != nil { | ||
return errors.Wrap(err, "Unable to open git repository.") | ||
} | ||
head, err := gitRepository.Head() | ||
if err != nil { | ||
return errors.Wrap(err, "Unable to get repository HEAD.") | ||
} | ||
reference := head.Name().String() | ||
|
||
err = dispatcher.DispatchWorkflow(currentRepository, reference, workflowName, inputAnswers) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func (f *rootFlagFields) Init(cmd *cobra.Command) error { | ||
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error { | ||
cmd.PrintErrln(err) | ||
cmd.PrintErrln() | ||
cmd.PrintErr(cmd.UsageString()) | ||
return SilentErr | ||
}) | ||
|
||
return nil | ||
} | ||
|
||
func Execute(ctx context.Context) error { | ||
err := rootFlags.Init(rootCmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return rootCmd.ExecuteContext(ctx) | ||
} |
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 @@ | ||
module github.com/chrisgavin/gh-dispatch | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/AlecAivazis/survey/v2 v2.3.2 | ||
github.com/cli/go-gh v0.0.3 | ||
github.com/go-git/go-git/v5 v5.4.2 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/spf13/cobra v1.4.0 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/Microsoft/go-winio v0.4.16 // indirect | ||
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect | ||
github.com/acomagu/bufpipe v1.0.3 // indirect | ||
github.com/cli/safeexec v1.0.0 // indirect | ||
github.com/cli/shurcooL-graphql v0.0.1 // indirect | ||
github.com/emirpasic/gods v1.12.0 // indirect | ||
github.com/go-git/gcfg v1.5.0 // indirect | ||
github.com/go-git/go-billy/v5 v5.3.1 // indirect | ||
github.com/henvic/httpretty v0.0.6 // indirect | ||
github.com/imdario/mergo v0.3.12 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | ||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | ||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect | ||
github.com/mattn/go-colorable v0.1.2 // indirect | ||
github.com/mattn/go-isatty v0.0.8 // indirect | ||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/sergi/go-diff v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/xanzy/ssh-agent v0.3.0 // indirect | ||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect | ||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect | ||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect | ||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect | ||
golang.org/x/text v0.3.6 // indirect | ||
gopkg.in/warnings.v0 v0.1.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
Oops, something went wrong.