You've already forked go-semantic-release
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a375f3bab | ||
|
|
d4627a9d46 | ||
|
|
af2addbffd | ||
|
|
7157d64b7b | ||
|
|
575ba5d5bd | ||
|
|
a8b68f9182 | ||
|
|
f6a2d837b1 | ||
|
|
279509c922 | ||
|
|
d0035d6bca |
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@@ -35,9 +35,12 @@ jobs:
|
|||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
if: github.ref != 'refs/heads/master'
|
if: github.ref != 'refs/heads/master'
|
||||||
run: |
|
run: |
|
||||||
docker build -t nightapes/go-semantic-release:development .
|
|
||||||
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
|
||||||
|
docker build -t nightapes/go-semantic-release:development .
|
||||||
docker push nightapes/go-semantic-release:development
|
docker push nightapes/go-semantic-release:development
|
||||||
|
docker tag nightapes/go-semantic-release:development docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development
|
||||||
|
docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development
|
||||||
|
|
||||||
- name: Push Docker image
|
- name: Push Docker image
|
||||||
if: github.ref != 'refs/heads/master'
|
if: github.ref != 'refs/heads/master'
|
||||||
@@ -48,4 +51,5 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
docker login -u nightapes -p $GITHUB_TOKEN docker.pkg.github.com
|
||||||
./build/go-semantic-release-temp release --loglevel trace
|
./build/go-semantic-release-temp release --loglevel trace
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ changelog:
|
|||||||
hooks:
|
hooks:
|
||||||
preRelease:
|
preRelease:
|
||||||
- docker build -t nightapes/go-semantic-release:latest .
|
- docker build -t nightapes/go-semantic-release:latest .
|
||||||
- docker build -t nightapes/go-semantic-release:$RELEASE_VERSION .
|
- docker tag nightapes/go-semantic-release:latest docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:$RELEASE_VERSION
|
||||||
|
- docker tag nightapes/go-semantic-release:latest nightapes/go-semantic-release:$RELEASE_VERSION
|
||||||
postRelease:
|
postRelease:
|
||||||
- docker push nightapes/go-semantic-release:latest
|
- docker push nightapes/go-semantic-release:latest
|
||||||
- docker push nightapes/go-semantic-release:$RELEASE_VERSION
|
- docker push nightapes/go-semantic-release:$RELEASE_VERSION
|
||||||
|
- docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:$RELEASE_VERSION
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
## Release Types
|
## Release Types
|
||||||
|
|
||||||
| Type | Implemendet | Git tag | Changelog | Release | Write access git | Api token |
|
| Type | Implemendet | Git tag | Changelog | Release | Write access git | Api token |
|
||||||
| ---------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
|
| ----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
|
||||||
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
||||||
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
||||||
| `git` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | |
|
| `git` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | |
|
||||||
| `bitbuckt` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
| `bitbucket` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||||
|
|
||||||
|
|
||||||
## Supported CI Pipelines
|
## Supported CI Pipelines
|
||||||
|
|||||||
64
cmd/go-semantic-release/commands/hooks.go
Normal file
64
cmd/go-semantic-release/commands/hooks.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/hooks"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(hooksCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hooksCmd = &cobra.Command{
|
||||||
|
Use: "hooks",
|
||||||
|
Short: "Run all hooks",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
config, err := cmd.Flags().GetString("config")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repository, err := cmd.Flags().GetString("repository")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
force, err := cmd.Flags().GetBool("no-cache")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseConfig := readConfig(config)
|
||||||
|
|
||||||
|
s, err := semanticrelease.New(releaseConfig, repository, !ignoreConfigChecks)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := s.GetCIProvider()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion, err := s.GetNextVersion(provider, force)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
hook := hooks.New(releaseConfig, releaseVersion)
|
||||||
|
|
||||||
|
err = hook.PreRelease()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return hook.PostRelease()
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -18,15 +18,16 @@ const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}
|
|||||||
{{ if eq $index 0 }}
|
{{ if eq $index 0 }}
|
||||||
## BREAKING CHANGES
|
## BREAKING CHANGES
|
||||||
{{ end}}
|
{{ end}}
|
||||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedBreakingChangeMessage}}
|
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
|
||||||
introduced by commit:
|
introduced by commit:
|
||||||
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})) {{end}}
|
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ range $key := .Order }}
|
{{ range $key := .Order }}
|
||||||
{{ $commits := index $.Commits $key}} {{if $commits -}}
|
{{ $commits := index $.Commits $key -}}
|
||||||
|
{{ if $commits }}
|
||||||
### {{ $key }}
|
### {{ $key }}
|
||||||
{{ range $index,$commit := $commits -}}
|
{{ range $index,$commit := $commits }}
|
||||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})) {{end}}
|
* {{ if $commit.Scope}}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{end}}{{$commit.ParsedMessage}}{{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}`
|
{{ end -}}`
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
"minor": []shared.AnalyzedCommit{
|
"minor": []shared.AnalyzedCommit{
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
Commit: shared.Commit{
|
Commit: shared.Commit{
|
||||||
Message: "feat(test): my first commit",
|
Message: "feat(internal/changelog): my first commit",
|
||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345667",
|
Hash: "12345667",
|
||||||
},
|
},
|
||||||
@@ -46,7 +46,30 @@ func TestChangelog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
result: &shared.GeneratedChangelog{
|
result: &shared.GeneratedChangelog{
|
||||||
Title: "v1.0.0 (2019-07-19)",
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
Content: "# v1.0.0 (2019-07-19)\n\n ### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url)) \n\n ",
|
Content: "# v1.0.0 (2019-07-19)\n\n\n### Features\n\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n",
|
||||||
|
},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "feat no scope",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"minor": []shared.AnalyzedCommit{
|
||||||
|
shared.AnalyzedCommit{
|
||||||
|
Commit: shared.Commit{
|
||||||
|
Message: "feat: my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
ParsedMessage: "my first commit",
|
||||||
|
Tag: "feat",
|
||||||
|
TagString: "Features",
|
||||||
|
Print: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
result: &shared.GeneratedChangelog{
|
||||||
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
|
Content: "# v1.0.0 (2019-07-19)\n\n\n### Features\n\n* my first commit ([1234566](https://commit.url))\n\n",
|
||||||
},
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
@@ -56,7 +79,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
"minor": []shared.AnalyzedCommit{
|
"minor": []shared.AnalyzedCommit{
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
Commit: shared.Commit{
|
Commit: shared.Commit{
|
||||||
Message: "feat(test): my first commit",
|
Message: "feat(internal/changelog): my first commit",
|
||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345667",
|
Hash: "12345667",
|
||||||
},
|
},
|
||||||
@@ -68,7 +91,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
Commit: shared.Commit{
|
Commit: shared.Commit{
|
||||||
Message: "feat(test): my first break: BREAKING CHANGE: change api to v2",
|
Message: "feat(internal/changelog): my first break: BREAKING CHANGE: change api to v2",
|
||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345668",
|
Hash: "12345668",
|
||||||
},
|
},
|
||||||
@@ -83,7 +106,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
result: &shared.GeneratedChangelog{
|
result: &shared.GeneratedChangelog{
|
||||||
Title: "v1.0.0 (2019-07-19)",
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
Content: "# v1.0.0 (2019-07-19)\n\n## BREAKING CHANGES\n\n* **`internal/changelog`** change api to v2 \nintroduced by commit: \nmy first break ([1234566](https://commit.url)) \n\n ### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url)) \n\n ",
|
Content: "# v1.0.0 (2019-07-19)\n\n## BREAKING CHANGES\n\n* **`internal/changelog`** change api to v2 \nintroduced by commit: \nmy first break ([1234566](https://commit.url))\n\n\n### Features\n\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n",
|
||||||
},
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) {
|
|||||||
|
|
||||||
err = gitTags.ForEach(func(p *plumbing.Reference) error {
|
err = gitTags.ForEach(func(p *plumbing.Reference) error {
|
||||||
v, err := semver.NewVersion(p.Name().Short())
|
v, err := semver.NewVersion(p.Name().Short())
|
||||||
log.Tracef("Tag %+v with hash: %s", p.Target(), p.Hash())
|
log.Tracef("Tag %+v with hash: %s", p.Name().Short(), p.Hash())
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tags = append(tags, v)
|
tags = append(tags, v)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package hooks
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
@@ -51,9 +52,14 @@ func (h *Hooks) PostRelease() error {
|
|||||||
|
|
||||||
func (h *Hooks) runCommand(command string) error {
|
func (h *Hooks) runCommand(command string) error {
|
||||||
|
|
||||||
splittedCmd := strings.Split(strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String()), " ")
|
cmdReplaced := strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String())
|
||||||
|
|
||||||
cmd := exec.Command(splittedCmd[0], splittedCmd[1:]...)
|
var cmd *exec.Cmd
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
cmd = exec.Command("cmd.exe", "/C", cmdReplaced)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command("sh", "-c", cmdReplaced)
|
||||||
|
}
|
||||||
|
|
||||||
cmdReader, err := cmd.StdoutPipe()
|
cmdReader, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -63,7 +69,7 @@ func (h *Hooks) runCommand(command string) error {
|
|||||||
scanner := bufio.NewScanner(cmdReader)
|
scanner := bufio.NewScanner(cmdReader)
|
||||||
go func() {
|
go func() {
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
log.WithField("cmd", splittedCmd[0]).Infof("%s\n", scanner.Text())
|
log.WithField("cmd", strings.Fields(cmdReplaced)[0]).Infof("%s\n", scanner.Text())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user