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
|
name: Go
|
||||||
on:
|
on:
|
||||||
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
strategy:
|
strategy:
|
||||||
@@ -21,11 +21,10 @@ jobs:
|
|||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
- name: Lint
|
- name: golangci-lint
|
||||||
run: |
|
uses: golangci/golangci-lint-action@v2
|
||||||
export PATH=$PATH:$(go env GOPATH)/bin
|
with:
|
||||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.35.2
|
version: v1.29
|
||||||
golangci-lint run ./...
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: go test ./...
|
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=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/
|
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
|
- name: Build Docker image
|
||||||
if: matrix.go == '1.15'
|
if: matrix.go == '1.15' && github.repository == 'Nightapes/go-semantic-release'
|
||||||
run: |
|
run: |
|
||||||
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 login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
|
||||||
@@ -66,6 +65,7 @@ jobs:
|
|||||||
name: build
|
name: build
|
||||||
path: build
|
path: build
|
||||||
- name: Release
|
- name: Release
|
||||||
|
if: github.repository == 'Nightapes/go-semantic-release'
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
@@ -73,3 +73,10 @@ jobs:
|
|||||||
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
|
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
|
||||||
|
- 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"}})
|
# My custom release template v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||||
{{ .Commits -}}
|
{{ template "commitList" .CommitsContent -}}
|
||||||
|
|
||||||
{{ if .HasDocker}}
|
{{ if .HasDocker}}
|
||||||
## Docker image
|
## Docker image
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package changelog
|
package changelog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -31,9 +32,11 @@ introduced by commit:
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}`
|
{{ end -}}`
|
||||||
|
const defaultCommitListSubTemplate string = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
|
||||||
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
||||||
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||||
{{ .Commits -}}
|
{{ template "commitList" .CommitsContent -}}
|
||||||
|
|
||||||
{{ if .HasDocker}}
|
{{ if .HasDocker}}
|
||||||
## Docker image
|
## Docker image
|
||||||
|
|
||||||
@@ -51,7 +54,8 @@ or
|
|||||||
`
|
`
|
||||||
|
|
||||||
type changelogContent struct {
|
type changelogContent struct {
|
||||||
Commits string
|
Commits string
|
||||||
|
CommitsContent commitsContent
|
||||||
Version string
|
Version string
|
||||||
Now time.Time
|
Now time.Time
|
||||||
Backtick string
|
Backtick string
|
||||||
@@ -130,6 +134,7 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
changelogContent := changelogContent{
|
changelogContent := changelogContent{
|
||||||
|
CommitsContent: commitsContent,
|
||||||
Version: templateConfig.Version,
|
Version: templateConfig.Version,
|
||||||
Now: c.releaseTime,
|
Now: c.releaseTime,
|
||||||
Backtick: "`",
|
Backtick: "`",
|
||||||
@@ -137,7 +142,7 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
|||||||
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
||||||
DockerRepository: c.config.Changelog.Docker.Repository,
|
DockerRepository: c.config.Changelog.Docker.Repository,
|
||||||
}
|
}
|
||||||
template := defaultChangelog
|
template := defaultCommitListSubTemplate + defaultChangelog
|
||||||
if c.config.Changelog.TemplatePath != "" {
|
if c.config.Changelog.TemplatePath != "" {
|
||||||
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
|
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,8 +169,8 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Tracef("Commits %s", renderedCommitList)
|
log.Tracef("Commits %s", renderedCommitList)
|
||||||
|
|
||||||
changelogContent.Commits = renderedCommitList
|
changelogContent.Commits = renderedCommitList
|
||||||
|
|
||||||
log.Debugf("Render changelog")
|
log.Debugf("Render changelog")
|
||||||
renderedContent, err := generateTemplate(template, changelogContent)
|
renderedContent, err := generateTemplate(template, changelogContent)
|
||||||
|
|
||||||
@@ -176,6 +181,10 @@ func generateTemplate(text string, values interface{}) (string, error) {
|
|||||||
|
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"replace": replace,
|
"replace": replace,
|
||||||
|
"lower": lower,
|
||||||
|
"upper": upper,
|
||||||
|
"capitalize": capitalize,
|
||||||
|
"addPrefixToLines": addPrefixToLines,
|
||||||
}
|
}
|
||||||
|
|
||||||
var tpl bytes.Buffer
|
var tpl bytes.Buffer
|
||||||
@@ -193,3 +202,30 @@ func generateTemplate(text string, values interface{}) (string, error) {
|
|||||||
func replace(input, from, to string) string {
|
func replace(input, from, to string) string {
|
||||||
return strings.Replace(input, from, to, -1)
|
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