From eb0ffcb266a8f4166175443faa9c46425d759eab Mon Sep 17 00:00:00 2001 From: Oleg Sucharevich Date: Sun, 5 Dec 2021 19:02:18 +0200 Subject: [PATCH] feat: support workflow dispatch inputs --- .github/workflows/docs.yaml | 2 +- .github/workflows/release.yaml | 36 ++++++++++++++++++++++++++---- .gitignore | 1 + VERSION | 1 - pkg/http/handlers/github_webook.go | 21 ++++++++++++++--- 5 files changed, 52 insertions(+), 9 deletions(-) delete mode 100644 VERSION diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index cb9f1d8..f2a48b0 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -4,7 +4,7 @@ name: docs on: push: branches: [ 'main' ] - +concurrency: docs-release jobs: deploy: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 59c4c97..36c6bc5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,6 +1,19 @@ name: release -on: workflow_dispatch +on: + workflow_dispatch: + inputs: + bump: + type: choice + description: 'Type of the bump (major | minor | patch)' + required: true + options: + - major + - minor + - patch + default: 'patch' + +concurrency: server-release jobs: release: @@ -8,6 +21,19 @@ jobs: runs-on: "ubuntu-18.04" steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '^1.17' + - name: Calculate Next Release Version + run: | + echo ${{ secrets.GITHUB_TOKEN }} > token + gh auth login --with-token < token + go install github.com/davidrjonas/semver-cli@latest + current=$(gh release list | awk '{print $1}' | awk 'NR==1' | sed s/v//g) + echo "current version $current" + next=$(semver-cli inc ${{ github.event.inputs.bump }} $current) + echo $next > next_version + echo "next version $next" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - id: 'auth' @@ -16,11 +42,13 @@ jobs: with: credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' - name: Build - run: docker build -t $(cat docker-repository.txt):$(cat VERSION) . + run: docker build -t $(cat docker-repository.txt):$(cat next_version) . - name: Push run: | gcloud auth configure-docker us-central1-docker.pkg.dev - docker push $(cat docker-repository.txt):$(cat VERSION) + docker push $(cat docker-repository.txt):$(cat next_version) - name: Update Cloud run - run: gcloud run services update server --region us-central1 --image $(cat docker-repository.txt):$(cat VERSION) + run: gcloud run services update server --region us-central1 --image $(cat docker-repository.txt):$(cat next_version) + - name: Release + run: gh release create v$(cat next_version) diff --git a/.gitignore b/.gitignore index 10dd26c..fa9d437 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ privatekey*.pem Makefile +next_version diff --git a/VERSION b/VERSION deleted file mode 100644 index c04c650..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.2.7 diff --git a/pkg/http/handlers/github_webook.go b/pkg/http/handlers/github_webook.go index 7760b43..c0c987d 100644 --- a/pkg/http/handlers/github_webook.go +++ b/pkg/http/handlers/github_webook.go @@ -157,8 +157,12 @@ func processComment(ctx context.Context, lgr *logger.Logger, body GithubWebhookB } case "workflow": file := tokens[2] + inputs := []string{} + if len(tokens) >= 3 { + inputs = tokens[3:] + } lgr.Info("starting workflow", "file", file) - if err := onWorkflow(ctx, lgr, client, body, prbot, file); err != nil { + if err := onWorkflow(ctx, lgr, client, body, prbot, file, inputs); err != nil { errs = append(errs, err) } default: @@ -203,11 +207,22 @@ func onMerge(ctx context.Context, client *github.Client, body GithubWebhookBody, return err } -func onWorkflow(ctx context.Context, lgr *logger.Logger, client *github.Client, body GithubWebhookBody, prbot PrBotFile, file string) error { +func onWorkflow(ctx context.Context, lgr *logger.Logger, client *github.Client, body GithubWebhookBody, prbot PrBotFile, file string, inputs []string) error { repo := body.Repository.Owner.Login name := body.Repository.Name + j := map[string]interface{}{} + + if len(inputs) > 0 { + for _, in := range inputs { + kv := strings.Split(in, "=") + if (len(kv)) == 2 { + j[kv[0]] = kv[1] + } + } + } _, err := client.Actions.CreateWorkflowDispatchEventByFileName(ctx, repo, name, file, github.CreateWorkflowDispatchEventRequest{ - Ref: body.Repository.DefaultBranch, + Ref: body.Repository.DefaultBranch, + Inputs: j, }) if err != nil { return err