0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-14 07:40:40 +00:00

Merge pull request #32 from bvieira/minor-improvement

Feature: return tag name on git sv tag
This commit is contained in:
Beatriz Vieira 2021-09-24 18:48:20 -03:00 committed by GitHub
commit d53ef6588d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 127 additions and 22 deletions

View File

@ -2,18 +2,21 @@ name: ci
on: on:
push: push:
branches: [ master ] branches: [master]
pull_request: paths-ignore:
branches: [ master ] - "**.md"
- "**/.gitignore"
- ".github/workflows/**"
jobs: jobs:
golangci: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - name: Check out code
- name: golangci-lint uses: actions/checkout@v2
- name: Run golangci lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
version: latest version: latest
@ -22,15 +25,78 @@ jobs:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out code
- name: Set up Go 1.x uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: ^1.16 go-version: ^1.16
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build - name: Build
run: make 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_*

35
.github/workflows/pull-request.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: pull_request
on:
pull_request:
branches: [ master ]
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

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ bin/
*.out *.out
*.sample *.sample
todo
# Additional generated artifacts # Additional generated artifacts
artifacts/ artifacts/

View File

@ -263,9 +263,9 @@ func tagHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) func(c *c
} }
nextVer, _ := semverProcessor.NextVersion(currentVer, commits) nextVer, _ := semverProcessor.NextVersion(currentVer, commits)
fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch()) tagname, err := git.Tag(nextVer)
fmt.Println(tagname)
if err := git.Tag(nextVer); err != nil { if err != nil {
return fmt.Errorf("error generating tag version: %s, message: %v", nextVer.String(), err) return fmt.Errorf("error generating tag version: %s, message: %v", nextVer.String(), err)
} }
return nil return nil

View File

@ -140,7 +140,7 @@ func main() {
} }
if apperr := app.Run(os.Args); apperr != nil { if apperr := app.Run(os.Args); apperr != nil {
log.Fatal("failed to run cli, error: ", apperr) log.Fatal("ERROR: ", apperr)
} }
} }

View File

@ -23,7 +23,7 @@ type Git interface {
LastTag() string LastTag() string
Log(lr LogRange) ([]GitCommitLog, error) Log(lr LogRange) ([]GitCommitLog, error)
Commit(header, body, footer string) error Commit(header, body, footer string) error
Tag(version semver.Version) error Tag(version semver.Version) (string, error)
Tags() ([]GitTag, error) Tags() ([]GitTag, error)
Branch() string Branch() string
IsDetached() (bool, error) IsDetached() (bool, error)
@ -123,17 +123,20 @@ func (g GitImpl) Commit(header, body, footer string) error {
} }
// Tag create a git tag. // 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()) 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()) tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())
tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg) tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
if err := tagCommand.Run(); err != nil { if out, err := tagCommand.CombinedOutput(); err != nil {
return err return tag, combinedOutputErr(err, out)
} }
pushCommand := exec.Command("git", "push", "origin", tag) pushCommand := exec.Command("git", "push", "origin", tag)
return pushCommand.Run() if out, err := pushCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out)
}
return tag, nil
} }
// Tags list repository tags. // Tags list repository tags.