Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
2cd7e71
feat: added --flow gitflow branch support.
jbcpollak Jun 13, 2017
320923b
fix: removed unnecessary logging
jbcpollak Jun 13, 2017
1b4d1db
fix: take the first release version if there is no prerelease to cons…
jbcpollak Jun 13, 2017
994f0b3
fix: disabled logging but left it commented
jbcpollak Jun 13, 2017
9fe9c03
fix: re-enabled logging for debugging
jbcpollak Jun 13, 2017
f5f2913
fix: don't write npmrc
jbcpollak Jun 14, 2017
640cba1
fix: if we are working on a beta release, use the last production rel…
jbcpollak Jun 14, 2017
9d5b651
fix: removed extra logging, don't recursively load commits
jbcpollak Jun 14, 2017
04ea290
fix: removed git specification from glide dependency, its no longer n…
jbcpollak Jun 14, 2017
c479f59
revert: add back writing npmrc
jbcpollak Jun 14, 2017
e7f97e9
fix: convert branch-names to camel case
jbcpollak Jun 14, 2017
91e5bf5
fix: remove npmrc code again
jbcpollak Jun 14, 2017
40a1bcc
fix: re-enabled logging for debugging
jbcpollak Jul 6, 2017
fb3c06b
fix: updated semrel to fix sorting of pre-release versions
jbcpollak Aug 2, 2017
676e4f3
feat: add nochange option which will get the current release if no ch…
joshughes Dec 8, 2017
cbcaca3
fix: release for specific arch... need arm64
joshughes Dec 10, 2017
8abb97e
feat: allow branch to be an ENV var for shallow clone situations
joshughes Dec 10, 2017
6fc8f6c
fix: env var for branch info
joshughes Dec 10, 2017
be8dc4a
fix: unused variable
joshughes Dec 10, 2017
b8cc78f
feat: add nochange option
dantwinkler May 23, 2018
4178dc4
fix: always increment base release, not just for betas
mgabeler-lee-6rs Aug 21, 2019
0d978b2
fix: Merge pull request #4 from 6RiverSystems/fix/all-builds-update-b…
mgabeler-lee-6rs Aug 22, 2019
04123ea
fix: does not set prelease if current branch is the default branch
Shockolate Jan 24, 2020
ab07af5
Merge pull request #6 from 6RiverSystems/fix/defaultBranch
AeroNotix Jan 28, 2020
adb5162
fix: tidy
AeroNotix Feb 18, 2020
b883bcf
fix: more tidy
AeroNotix Feb 18, 2020
64f2c44
feat: remove vendoring
AeroNotix Feb 18, 2020
28b7be5
fix: master no longer special
AeroNotix Mar 9, 2020
d2fe39e
fix: always bump a version (DV-617)
AeroNotix Mar 15, 2020
ebba03e
Merge pull request #7 from 6RiverSystems/tidy
AeroNotix Mar 16, 2020
7d2e314
fix: better error when not in git repo
AeroNotix May 6, 2020
a046f1f
Merge pull request #8 from 6RiverSystems/fix/better-error-message-whe…
AeroNotix May 6, 2020
7c13749
fix: misc cleanups, don't force major version to be 1.0.0 or higher
mgabeler-lee-6rs Mar 9, 2021
54aa86f
fix: just remove the unwanted code
mgabeler-lee-6rs Mar 10, 2021
b435efe
fix: Merge pull request #9 from 6RiverSystems/fix/cleanup-and-allow-z…
mgabeler-lee-6rs Mar 10, 2021
57648f5
feat: support an env var / cli flag to override the default branch fo…
mgabeler-lee-6rs Jun 30, 2021
6e85a20
feat: Merge pull request #10 from 6RiverSystems/feat/default-branch-o…
mgabeler-lee-6rs Jun 30, 2021
0ee7540
fix: merge master
joshughes Mar 10, 2022
5addfa8
fix: some merge errors
joshughes Mar 10, 2022
f1e1319
fix: slight change
joshughes Mar 10, 2022
73d70ea
fix: version bump
joshughes Mar 10, 2022
8596642
fix: version bump
joshughes Mar 10, 2022
a97ffc8
fix: version bump
joshughes Mar 10, 2022
92da108
fix: version bump
joshughes Mar 10, 2022
02f4e44
fix: version bump
joshughes Mar 10, 2022
7a3286a
fix: version bump
joshughes Mar 10, 2022
da68d21
fix: version bump
joshughes Mar 10, 2022
c1f93bc
fix: version bump
joshughes Mar 10, 2022
a95c6e7
fix: version bump
joshughes Mar 10, 2022
340aec5
fix: version bump
joshughes Mar 10, 2022
b7a438f
fix: version bump
joshughes Mar 10, 2022
8b5d041
fix: make it all work
joshughes Mar 10, 2022
3140da3
fix: test files
joshughes Mar 10, 2022
38925c2
fix: add back default branch override
joshughes Mar 10, 2022
3a797a2
fix: replaying all 6RS PRs
joshughes Mar 10, 2022
01e88bc
fix: broken test
joshughes Mar 11, 2022
5f5293d
fix: tests
joshughes Mar 11, 2022
fd4b075
fix: publish action
joshughes Mar 11, 2022
9fcf53b
fix: yaml
joshughes Mar 11, 2022
7ee30a3
fix: use flow in publish
joshughes Mar 11, 2022
31f203f
fix: use env var for slug
joshughes Mar 11, 2022
c8f1bdf
fix: version bump
joshughes Mar 11, 2022
b45a2f1
fix: version bump
joshughes Mar 11, 2022
1ee942c
fix: compare the right thing for flow
joshughes Mar 11, 2022
41ab598
fix: logging statements
joshughes Mar 11, 2022
7b57b19
fix: version bump
joshughes Mar 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v1
with:
registry: registry.gitlab.com
username: ${{ secrets.GITLAB_USER }}
password: ${{ secrets.GITLAB_TOKEN }}
- run: ./scripts/release || exit 0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
27 changes: 25 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
.envrc
test/.npmrc
### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
bin/
semantic-release

# Make sure we don't exclude directories with that name
!semantic-release/

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# IDE Files
.idea/
main
.version
.ghr
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dry-run against test repo",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/semantic-release",
"args": [
"-vf",
"-dry",
"-slug",
"mgabeler-lee-6rs/semrel-test",
"-noci",
"-flow"
],
"env": {
"GITHUB_TOKEN": "${input:ghtok}",
},
"cwd": "/tmp/semrel-test",
},
],
"inputs": [
{
"id": "ghtok",
"password": true,
"description": "GitHub PAT",
"type": "promptString",
},
],
}
76 changes: 70 additions & 6 deletions cmd/semantic-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"syscall"

"github.com/Masterminds/semver/v3"
"github.com/go-git/go-git/v5"
"github.com/go-semantic-release/semantic-release/v2/pkg/config"
"github.com/go-semantic-release/semantic-release/v2/pkg/generator"
"github.com/go-semantic-release/semantic-release/v2/pkg/hooks"
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/manager"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
"github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
"github.com/iancoleman/strcase"
"github.com/spf13/cobra"
)

Expand All @@ -41,6 +43,30 @@ func errorHandler(logger *log.Logger) func(error, ...int) {
}
}

type CommitInfo struct {
Branch string
SHA string
}

func GetCurCommitInfo() (*CommitInfo, error) {

repo, err := git.PlainOpen(".")
if err != nil {
return nil, err
}

headRef, err := repo.Head()

if err != nil {
return nil, err
}

return &CommitInfo{
Branch: headRef.Name().Short(),
SHA: headRef.Hash().String(),
}, nil
}

func main() {
cmd := &cobra.Command{
Use: "semantic-release",
Expand Down Expand Up @@ -119,19 +145,57 @@ func cliHandler(cmd *cobra.Command, args []string) {
logger.Println("repo is private")
}

defaultBranch := ""

if conf.DefaultBranch != "" {
logger.Println("using overridden default branch:", conf.DefaultBranch, "instead of detected:", repoInfo.DefaultBranch)
defaultBranch = conf.DefaultBranch
} else {
defaultBranch = repoInfo.DefaultBranch
logger.Println("found default branch: " + defaultBranch)
}

currentBranch := ci.GetCurrentBranch()
if currentBranch == "" {
exitIfError(fmt.Errorf("current branch not found"))
}
logger.Println("found current branch: " + currentBranch)

if !conf.AllowMaintainedVersionOnDefaultBranch && conf.MaintainedVersion != "" && currentBranch == repoInfo.DefaultBranch {
curCommitInfo, err := GetCurCommitInfo()
if err == git.ErrRepositoryNotExists {
logger.Println(`Repository (.git directory) does not exist in local directory. Be sure to
run go-semantic-release in a git repository`)
}
exitIfError(err)
logger.Println("found current branch: " + curCommitInfo.Branch)

prerelease := ""
if conf.Flow && conf.MaintainedVersion == "" && currentBranch != defaultBranch {
switch curCommitInfo.Branch {
// If branch is master -> no pre-latestRelease version
case "master":
prerelease = ""
// If branch is develop -> beta latestRelease
case "develop":
prerelease = "beta"
default:
branchPath := strings.Split(curCommitInfo.Branch, "/")
prerelease = branchPath[len(branchPath)-1]
prerelease = strcase.ToLowerCamel(prerelease)
}
}

if prerelease != "" {
logger.Println("Determined prerelease version: " + prerelease)
}

if !conf.AllowMaintainedVersionOnDefaultBranch && conf.MaintainedVersion != "" && currentBranch == defaultBranch {
exitIfError(fmt.Errorf("maintained version not allowed on default branch"))
}

if conf.MaintainedVersion != "" {
logger.Println("found maintained version: " + conf.MaintainedVersion)
repoInfo.DefaultBranch = "*"
defaultBranch = "*"
}

currentSha := ci.GetCurrentSHA()
Expand All @@ -150,7 +214,7 @@ func cliHandler(cmd *cobra.Command, args []string) {
"ci": ciName,
"currentBranch": currentBranch,
"currentSha": currentSha,
"defaultBranch": repoInfo.DefaultBranch,
"defaultBranch": defaultBranch,
"prerelease": fmt.Sprintf("%t", conf.Prerelease),
}
for k, v := range conf.HooksOpts {
Expand All @@ -162,7 +226,7 @@ func cliHandler(cmd *cobra.Command, args []string) {
logger.Println("running CI condition...")
conditionConfig := map[string]string{
"token": conf.Token,
"defaultBranch": repoInfo.DefaultBranch,
"defaultBranch": defaultBranch,
"private": fmt.Sprintf("%t", repoInfo.Private),
}
for k, v := range conf.CIConditionOpts {
Expand Down Expand Up @@ -191,7 +255,7 @@ func cliHandler(cmd *cobra.Command, args []string) {
}
releases, err := prov.GetReleases(matchRegex)
exitIfError(err)
release, err := semrel.GetLatestReleaseFromReleases(releases, conf.MaintainedVersion)
release, err := semrel.GetLatestReleaseFromReleases(releases, conf.MaintainedVersion, prerelease)
exitIfError(err)
logger.Println("found version: " + release.Version)

Expand All @@ -212,7 +276,7 @@ func cliHandler(cmd *cobra.Command, args []string) {
commits := commitAnalyzer.Analyze(rawCommits)

logger.Println("calculating new version...")
newVer := semrel.GetNewVersion(conf, commits, release)
newVer := semrel.GetNewVersion(conf, commits, release, prerelease)
if newVer == "" {
herr := hooksExecutor.NoRelease(&hooks.NoReleaseConfig{
Reason: hooks.NoReleaseReason_NO_CHANGE,
Expand Down
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ go 1.17
require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/cavaliergopher/grab/v3 v3.0.1
github.com/go-git/go-git/v5 v5.4.2
github.com/hashicorp/go-hclog v1.1.0
github.com/hashicorp/go-plugin v1.4.3
github.com/iancoleman/strcase v0.2.0
github.com/jbcpollak/strcase v0.0.0-20170614182632-a2c126df64d8
github.com/schollz/progressbar/v3 v3.8.5
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.10.1
Expand All @@ -16,36 +19,49 @@ require (
)

require (
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/afero v1.8.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 // indirect
gopkg.in/ini.v1 v1.66.3 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading