Skip to content

Commit

Permalink
feat: support workflow dispatch inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
olegsu committed Dec 5, 2021
1 parent 8346e9e commit 6d9e880
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: docs
on:
push:
branches: [ 'main' ]

concurrency: docs-release
jobs:
deploy:
runs-on: ubuntu-latest
Expand Down
32 changes: 28 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
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

concurrency: server-release

jobs:
release:
name: Build
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)
semver-cli inc ${{ github.event.inputs.bump }} $current > next_version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- id: 'auth'
Expand All @@ -16,11 +38,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)

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
privatekey*.pem
Makefile
next_version
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

21 changes: 18 additions & 3 deletions pkg/http/handlers/github_webook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d9e880

Please sign in to comment.