forked from dionomusuko/gh-release-with-wf-dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (32 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"context"
"log"
"github.com/kelseyhightower/envconfig"
)
type env struct {
GithubToken string `envconfig:"GITHUB_TOKEN"`
ReleaseFilePath string `envconfig:"RELEASE_FILE_PATH"`
Owner string `envconfig:"OWNER"`
RepoFullName string `envconfig:"REPO_FULL_NAME"`
Repo string `envconfig:"REPO"`
BaseBranch string `envconfig:"BASE_BRANCH"`
NewTag string `envconfig:"NEW_TAG"`
}
func main() {
ctx := context.Background()
var e env
if err := envconfig.Process("INPUT", &e); err != nil {
log.Fatal(err.Error())
}
gitCli := newGitClient(ctx, e.GithubToken, e.RepoFullName)
oldTag, newNode, yamlPath, parseFile := readReleaseFile(gitCli.file, e.ReleaseFilePath)
newNode, newTag := generateTag(newNode, oldTag, e.NewTag)
log.Printf("tag: %v", newTag)
branch := gitCli.Checkout(newTag)
writeFile(yamlPath, gitCli.file, parseFile, newNode, e.ReleaseFilePath)
gitCli.Commit(e.ReleaseFilePath, newTag)
gitCli.Push(ctx, e.Owner)
ghCli := newGHClient(e.GithubToken)
ghCli.newPullRequest(ctx, newTag, e.BaseBranch, e.Repo, e.Owner, branch)
}