From 08e51ae2c332413f38871bb6b1215afb6ff2a817 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Fri, 24 Sep 2021 17:36:01 -0300 Subject: [PATCH 1/6] chore: update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b3eda77..9e67889 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ bin/ *.out *.sample +todo # Additional generated artifacts artifacts/ From 1cb825c4b04979cc15c1b114fcca8329f501d464 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Fri, 24 Sep 2021 17:49:58 -0300 Subject: [PATCH 2/6] fix: print error output at git sv tag --- sv/git.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sv/git.go b/sv/git.go index 4290310..68dcded 100644 --- a/sv/git.go +++ b/sv/git.go @@ -128,12 +128,15 @@ func (g GitImpl) Tag(version semver.Version) error { tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch()) tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg) - if err := tagCommand.Run(); err != nil { - return err + if out, err := tagCommand.CombinedOutput(); err != nil { + return combinedOutputErr(err, out) } pushCommand := exec.Command("git", "push", "origin", tag) - return pushCommand.Run() + if out, err := pushCommand.CombinedOutput(); err != nil { + return combinedOutputErr(err, out) + } + return nil } // Tags list repository tags. From d02c8b59f6c2a966236448fe966415d4668710fe Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Fri, 24 Sep 2021 17:50:59 -0300 Subject: [PATCH 3/6] refactor: better log on cli failure --- cmd/git-sv/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index 6b154f4..dc3e59f 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -140,7 +140,7 @@ func main() { } if apperr := app.Run(os.Args); apperr != nil { - log.Fatal("failed to run cli, error: ", apperr) + log.Fatal("ERROR: ", apperr) } } From 84e8c9d168610c33d1f0be704884cfbfd41378cc Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Fri, 24 Sep 2021 17:59:38 -0300 Subject: [PATCH 4/6] feat: print tag name on git sv tag --- cmd/git-sv/handlers.go | 6 +++--- sv/git.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/git-sv/handlers.go b/cmd/git-sv/handlers.go index 36de37a..d37cfb5 100644 --- a/cmd/git-sv/handlers.go +++ b/cmd/git-sv/handlers.go @@ -263,9 +263,9 @@ func tagHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) func(c *c } nextVer, _ := semverProcessor.NextVersion(currentVer, commits) - fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch()) - - if err := git.Tag(nextVer); err != nil { + tagname, err := git.Tag(nextVer) + fmt.Println(tagname) + if err != nil { return fmt.Errorf("error generating tag version: %s, message: %v", nextVer.String(), err) } return nil diff --git a/sv/git.go b/sv/git.go index 68dcded..bab6d14 100644 --- a/sv/git.go +++ b/sv/git.go @@ -23,7 +23,7 @@ type Git interface { LastTag() string Log(lr LogRange) ([]GitCommitLog, error) Commit(header, body, footer string) error - Tag(version semver.Version) error + Tag(version semver.Version) (string, error) Tags() ([]GitTag, error) Branch() string IsDetached() (bool, error) @@ -123,20 +123,20 @@ func (g GitImpl) Commit(header, body, footer string) error { } // Tag create a git tag. -func (g GitImpl) Tag(version semver.Version) error { +func (g GitImpl) Tag(version semver.Version) (string, error) { tag := fmt.Sprintf(g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch()) tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch()) tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg) if out, err := tagCommand.CombinedOutput(); err != nil { - return combinedOutputErr(err, out) + return tag, combinedOutputErr(err, out) } pushCommand := exec.Command("git", "push", "origin", tag) if out, err := pushCommand.CombinedOutput(); err != nil { - return combinedOutputErr(err, out) + return tag, combinedOutputErr(err, out) } - return nil + return tag, nil } // Tags list repository tags. From 53f25edf84d0f2ef66abf86d61d3067bd4e52740 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Fri, 24 Sep 2021 18:38:38 -0300 Subject: [PATCH 5/6] ci: config gh actions on pull-request and master --- .github/workflows/ci.yml | 92 +++++++++++++++++++++++++----- .github/workflows/pull-request.yml | 35 ++++++++++++ 2 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1da25a8..77de8c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,18 +2,21 @@ name: ci on: push: - branches: [ master ] - pull_request: - branches: [ master ] + branches: [main] + paths-ignore: + - "**.md" + - "**/.gitignore" + - ".github/workflows/**" jobs: - golangci: + lint: name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: golangci-lint + - name: Check out code + uses: actions/checkout@v2 + - name: Run golangci lint uses: golangci/golangci-lint-action@v2 with: version: latest @@ -22,15 +25,78 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - - name: Set up Go 1.x + - name: Check out code + uses: actions/checkout@v2 + - name: Set up Go uses: actions/setup-go@v2 with: go-version: ^1.16 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: Build run: make build + + tag: + name: Tag + runs-on: ubuntu-latest + needs: [lint, build] + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set GitHub Actions as commit author + shell: bash + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Setup sv4git + run: | + curl -s https://api.github.com/repos/bvieira/sv4git/releases/latest | jq -r '.assets[] | select(.browser_download_url | contains("linux")) | .browser_download_url' | wget -O /tmp/sv4git.tar.gz -qi - \ + && tar -C /usr/local/bin -xzf /tmp/sv4git.tar.gz + + - name: Create tag + id: create-tag + run: | + git sv tag + VERSION=$(git sv cv) + echo "::set-output name=tag::v$VERSION" + outputs: + tag: ${{ steps.create-tag.outputs.tag }} + + release: + name: Release + runs-on: ubuntu-latest + needs: [tag] + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup sv4git + run: | + curl -s https://api.github.com/repos/bvieira/sv4git/releases/latest | jq -r '.assets[] | select(.browser_download_url | contains("linux")) | .browser_download_url' | wget -O /tmp/sv4git.tar.gz -qi - \ + && tar -C /usr/local/bin -xzf /tmp/sv4git.tar.gz + + - name: Set up Go + id: go + uses: actions/setup-go@v2 + with: + go-version: ^1.16 + + - name: Create release notes + run: | + git sv rn -t "${{ needs.tag.outputs.tag }}" > release-notes.md + + - name: Build releases + run: make release-all + + - name: Release + uses: softprops/action-gh-release@v1 + with: + body_path: release-notes.md + tag_name: ${{ needs.tag.outputs.tag }} + fail_on_unmatched_files: true + files: | + bin/git-sv_* diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..30972ca --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,35 @@ +name: pull_request + +on: + pull_request: + branches: [ main ] + paths-ignore: + - '**.md' + - '**/.gitignore' + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Run golangci lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest + + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ^1.16 + id: go + - name: Build + run: make build From 2ad08a207a38b1e5042011c1380c587aa246fcee Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Fri, 24 Sep 2021 18:42:36 -0300 Subject: [PATCH 6/6] ci: fix branch name --- .github/workflows/ci.yml | 2 +- .github/workflows/pull-request.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77de8c5..13ca557 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: ci on: push: - branches: [main] + branches: [master] paths-ignore: - "**.md" - "**/.gitignore" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 30972ca..2921440 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,7 +2,7 @@ name: pull_request on: pull_request: - branches: [ main ] + branches: [ master ] paths-ignore: - '**.md' - '**/.gitignore'