Compare commits

...

6 Commits

8 changed files with 71 additions and 25 deletions
+20
View File
@@ -0,0 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug, to be confirmed
assignees: lukaszraczylo
---
**Describe the bug**
A clear and concise description of what the bug is.
**Output with debug**
[ paste output of the command with `-d` flag here ]
**Expected behavior**
A clear and concise description of what you expected to happen.
**Additional context**
Add any other context about the problem here.
+9 -9
View File
@@ -43,7 +43,6 @@ jobs:
TMP_GITHUB_COMMITS_COUNT=$(git rev-list --count HEAD)
TMP_GITHUB_COUNT_NUMBER=$(echo ${GITHUB_RUN_NUMBER})
TMP_RELEASE_VERSION=$(./semver-gen generate -l -c config-release.yaml | sed -e 's|SEMVER ||g')
TMP_RELEASE_VERSION=1.4.3
echo "::set-output name=SANITISED_REPOSITORY_NAME::$TMP_SANITISED_REPOSITORY_NAME"
echo "::set-output name=DOCKER_IMAGE::ghcr.io/${{ github.repository_owner }}/$TMP_SANITISED_REPOSITORY_NAME"
echo "::set-output name=GITHUB_COMMIT_NUMBER::$TMP_GITHUB_COMMITS_COUNT"
@@ -202,14 +201,15 @@ jobs:
# body_path: .release_notes
# draft: false
prerelease: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }}
# - name: Delete previous v1 release asset
# uses: mknejp/delete-release-assets@v1
# with:
# token: ${{ github.token }}
# fail-if-no-assets: false
# fail-if-no-release: false
# tag: v1
# assets: 'semver-gen-*'
- name: Delete previous v1 release asset
uses: mknejp/delete-release-assets@v1
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
with:
token: ${{ github.token }}
fail-if-no-assets: false
fail-if-no-release: false
tag: v1
assets: 'semver-gen-*'
- name: Create Release V1
id: create_release_global
uses: marvinpinto/action-automatic-releases@latest
+22 -7
View File
@@ -1,4 +1,4 @@
LOCAL_VERSION?=$(shell semver-gen generate -l -c config-release.yaml | sed -e 's|SEMVER ||g')
LOCAL_VERSION?=""
CI_RUN?=false
ADDITIONAL_BUILD_FLAGS=""
@@ -6,16 +6,31 @@ ifeq ($(CI_RUN), true)
ADDITIONAL_BUILD_FLAGS="-test.short"
endif
all: build
ifneq ($(shell which semver-gen), "")
LOCAL_VERSION="0.0.0-dev"
else
LOCAL_VERSION=$(shell semver-gen generate -l -c config-release.yaml | sed -e 's|SEMVER ||g')
endif
build:
.PHONY: help
help: ## display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
.PHONY: all
all: build ## Build all targets
.PHONY: build
build: ## Build binary
go build -o semver-gen -ldflags="-s -w -X main.PKG_VERSION=${LOCAL_VERSION}" *.go
run: build
@./semver-gen
# .PHONY: run
# run: build ## Build binary and execute it
# @./semver-gen
test:
.PHONY: test
test: ## Run whole test suite
@go test ./... $(ADDITIONAL_BUILD_FLAGS) -v -race -cover -coverprofile=coverage.out
update:
.PHONY: update
update: ## Update all dependencies and sub-packages
@go get -u ./...
-1
View File
@@ -102,7 +102,6 @@ func checkLatestRelease() (string, bool) {
fmt.Println("Query error >>", err)
return "", false
}
fmt.Println(result)
result = gjson.Get(result, "repository.releases.nodes.0.tag.name").String()
if result == "v1" {
result = gjson.Get(result, "repository.releases.nodes.1.tag.name").String()
+11 -6
View File
@@ -55,6 +55,7 @@ type Force struct {
Major int
Commit string
Existing bool
Strict bool
}
type SemVer struct {
@@ -115,9 +116,14 @@ func debugPrint(content string) {
var extractNumber = regexp.MustCompile("[0-9]+")
func parseExistingSemver(tagName string) (semanticVersion SemVer) {
func parseExistingSemver(tagName string, currentSemver SemVer) (semanticVersion SemVer) {
debugPrint(fmt.Sprintln("Parsing existing semver:", tagName))
var tagNameParts []string
tagNameParts = strings.Split(tagName, ".")
if len(tagNameParts) < 3 {
debugPrint("Unable to parse incompatible semver ( non x.y.z )")
return currentSemver
}
semanticVersion.Major, _ = strconv.Atoi(extractNumber.FindAllString(tagNameParts[0], -1)[0])
semanticVersion.Minor, _ = strconv.Atoi(extractNumber.FindAllString(tagNameParts[1], -1)[0])
semanticVersion.Patch, _ = strconv.Atoi(extractNumber.FindAllString(tagNameParts[2], -1)[0])
@@ -134,13 +140,13 @@ func (s *Setup) CalculateSemver() SemVer {
for _, tagHash := range s.Tags {
if commit.Hash == tagHash.Hash {
debugPrint(fmt.Sprintln("Found existing tag:", tagHash.Name, "related to", commit.Message))
s.Semver = parseExistingSemver(tagHash.Name)
s.Semver = parseExistingSemver(tagHash.Name, s.Semver)
continue
}
}
}
if !params.varStrict {
if !params.varStrict && !s.Force.Strict {
s.Semver.Patch++
debugPrint(fmt.Sprintln("Incrementing patch (DEFAULT) on ", strings.TrimSuffix(commit.Message, "\n"), "| Semver:", s.getSemver()))
}
@@ -321,8 +327,7 @@ func main() {
if repo.Generate || params.varGenerateInTest {
err := repo.ReadConfig(repo.LocalConfigFile)
if err != nil {
fmt.Println("Unable to find config file", repo.LocalConfigFile)
os.Exit(1)
fmt.Println("Unable to find config file semver.yaml. Using defaults and flags.", repo.LocalConfigFile)
}
err = repo.Prepare()
if err != nil {
@@ -330,7 +335,7 @@ func main() {
os.Exit(1)
}
repo.ListCommits()
if params.varExisting {
if params.varExisting || repo.Force.Existing {
repo.ListExistingTags()
}
repo.ForcedVersioning()
+5 -1
View File
@@ -569,7 +569,11 @@ func (suite *Tests) Test_parseExistingSemver() {
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {
got := parseExistingSemver(tt.args.tagName)
got := parseExistingSemver(tt.args.tagName, SemVer{
Major: 1,
Minor: 1,
Patch: 1,
})
assert.Equal(tt.wantSemanticVersion.Major, got.Major, "Unexpected MAJOR semver result in "+tt.name)
assert.Equal(tt.wantSemanticVersion.Minor, got.Minor, "Unexpected MINOR semver result in "+tt.name)
assert.Equal(tt.wantSemanticVersion.Patch, got.Patch, "Unexpected PATCH semver result in "+tt.name)
+2
View File
@@ -3,6 +3,8 @@ force:
major: 1
minor: 4
existing: true
strict: false
commit: 960207e4677476ad31a9f389f74eaf9f33d49613
wording:
patch:
- update
+2 -1
View File
@@ -1,7 +1,8 @@
version: 1
force:
major: 1
existing: true
existing: false
strict: false
wording:
patch:
- update