You've already forked go-semantic-release
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81bdb68ee4 | ||
|
|
c485c3ee85 | ||
|
|
86c9512479 | ||
|
|
4574d00c28 | ||
|
|
0c4310d60b | ||
|
|
3a37a5e1db | ||
|
|
9594f39caa |
21
.github/workflows/main.yml
vendored
21
.github/workflows/main.yml
vendored
@@ -1,9 +1,9 @@
|
||||
name: Go
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
@@ -21,11 +21,10 @@ jobs:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
export PATH=$PATH:$(go env GOPATH)/bin
|
||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.35.2
|
||||
golangci-lint run ./...
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
version: v1.29
|
||||
|
||||
- name: Run tests
|
||||
run: go test ./...
|
||||
@@ -41,7 +40,7 @@ jobs:
|
||||
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_x86_64.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
||||
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.darwin_x86_64 -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
||||
- name: Build Docker image
|
||||
if: matrix.go == '1.15'
|
||||
if: matrix.go == '1.15' && github.repository == 'Nightapes/go-semantic-release'
|
||||
run: |
|
||||
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||
docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
|
||||
@@ -66,6 +65,7 @@ jobs:
|
||||
name: build
|
||||
path: build
|
||||
- name: Release
|
||||
if: github.repository == 'Nightapes/go-semantic-release'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
@@ -73,3 +73,10 @@ jobs:
|
||||
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
|
||||
- name: Release fork
|
||||
if: github.repository != 'Nightapes/go-semantic-release'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
chmod -R +x build
|
||||
./build/go-semantic-release-temp release --loglevel trace
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
{{ define "commitList" }}
|
||||
{{ range $index,$commit := .BreakingChanges -}}
|
||||
{{ if eq $index 0 -}}
|
||||
## BREAKING CHANGES
|
||||
{{ end -}}
|
||||
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
|
||||
introduced by commit:
|
||||
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
||||
{{ end -}}
|
||||
{{ range $key := .Order -}}
|
||||
{{ $commits := index $.Commits $key -}}
|
||||
{{ if $commits -}}
|
||||
### {{ $key }}
|
||||
{{ range $index,$commit := $commits -}}
|
||||
* {{ 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 -}}
|
||||
|
||||
# My custom release template v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||
{{ .Commits -}}
|
||||
{{ template "commitList" .CommitsContent -}}
|
||||
|
||||
{{ if .HasDocker}}
|
||||
## Docker image
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package changelog
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
@@ -31,9 +32,11 @@ introduced by commit:
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}`
|
||||
const defaultCommitListSubTemplate string = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
|
||||
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
||||
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||
{{ .Commits -}}
|
||||
{{ template "commitList" .CommitsContent -}}
|
||||
|
||||
{{ if .HasDocker}}
|
||||
## Docker image
|
||||
|
||||
@@ -51,7 +54,8 @@ or
|
||||
`
|
||||
|
||||
type changelogContent struct {
|
||||
Commits string
|
||||
Commits string
|
||||
CommitsContent commitsContent
|
||||
Version string
|
||||
Now time.Time
|
||||
Backtick string
|
||||
@@ -130,6 +134,7 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
||||
}
|
||||
|
||||
changelogContent := changelogContent{
|
||||
CommitsContent: commitsContent,
|
||||
Version: templateConfig.Version,
|
||||
Now: c.releaseTime,
|
||||
Backtick: "`",
|
||||
@@ -137,7 +142,7 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
||||
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
||||
DockerRepository: c.config.Changelog.Docker.Repository,
|
||||
}
|
||||
template := defaultChangelog
|
||||
template := defaultCommitListSubTemplate + defaultChangelog
|
||||
if c.config.Changelog.TemplatePath != "" {
|
||||
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
|
||||
if err != nil {
|
||||
@@ -164,8 +169,8 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
||||
}
|
||||
|
||||
log.Tracef("Commits %s", renderedCommitList)
|
||||
|
||||
changelogContent.Commits = renderedCommitList
|
||||
|
||||
log.Debugf("Render changelog")
|
||||
renderedContent, err := generateTemplate(template, changelogContent)
|
||||
|
||||
@@ -176,6 +181,10 @@ func generateTemplate(text string, values interface{}) (string, error) {
|
||||
|
||||
funcMap := template.FuncMap{
|
||||
"replace": replace,
|
||||
"lower": lower,
|
||||
"upper": upper,
|
||||
"capitalize": capitalize,
|
||||
"addPrefixToLines": addPrefixToLines,
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
@@ -193,3 +202,30 @@ func generateTemplate(text string, values interface{}) (string, error) {
|
||||
func replace(input, from, to string) string {
|
||||
return strings.Replace(input, from, to, -1)
|
||||
}
|
||||
|
||||
func lower(input string) string {
|
||||
return strings.ToLower(input)
|
||||
}
|
||||
|
||||
func upper(input string) string {
|
||||
return strings.ToUpper(input)
|
||||
}
|
||||
|
||||
func capitalize(input string) string {
|
||||
if len(input) > 0 {
|
||||
return strings.ToUpper(string(input[0])) + input[1:]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Adds a prefix to each line of the given text block
|
||||
// this can be helpful in rendering correct indentation or bullets for multi-line texts
|
||||
func addPrefixToLines(input, prefix string) string {
|
||||
output := ""
|
||||
scanner := bufio.NewScanner(strings.NewReader(input))
|
||||
for scanner.Scan() {
|
||||
output += prefix + scanner.Text() + "\n"
|
||||
}
|
||||
output = strings.TrimRight(output, "\n")
|
||||
return output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user