Compare commits

...

25 Commits

Author SHA1 Message Date
github-actions[bot] 5b279c7f24 chore: pin action.yml Docker image to v1.17.3 2026-05-22 22:39:03 +00:00
lukaszraczylo 888415366a feat(telemetry): switch to SendForModule for auto-version resolution
Replace telemetry.Send(name, PKG_VERSION) with telemetry.SendForModule
so the binary reports its release version automatically from
runtime/debug.BuildInfo whenever PKG_VERSION isn't injected (e.g.
`go install` without ldflags). The goreleaser path still wins because
goreleaser's -X main.PKG_VERSION={{.Version}} populates the fallback,
but `go install github.com/lukaszraczylo/semver-generator@vX.Y.Z`
users now also get the correct version without ldflag plumbing.

Bumps oss-telemetry to v0.2.1.
2026-05-22 23:34:58 +01:00
github-actions[bot] dfbc4d4012 chore: pin action.yml Docker image to v1.17.1 2026-05-21 23:47:12 +00:00
lukaszraczylo dfeb03b8bb fix(semver): skip non-semver tags when picking latest existing tag
Rolling tags like 'v1' (and any other tag that doesn't parse as x.y.z
after prefix stripping) used to enter the latest-tag candidate set in
CalculateSemver. When such a tag shared a commit with a real semver tag
(e.g. v1 and v1.16.3 both pointing at the same release commit), go-git's
alphabetical tag iteration made 'v1' win, ParseExistingSemver bailed out
because '1' has only one component, and the calculator silently reset
the baseline to 0.0.0 — producing nonsense like 0.0.5 on this branch.

ListExistingTags now filters tags through a new IsParseableSemverTag
helper before recording them, so non-semver tags never participate in
latest-tag selection. The behavior change is invisible for repos that
only use proper vX.Y.Z tags, and it's covered by a new test table.
2026-05-22 00:39:59 +01:00
lukaszraczylo ab52de167e fixup! docs: add Telemetry section linking to oss-telemetry opt-out docs 2026-05-22 00:09:10 +01:00
lukaszraczylo 564f39ed10 docs: add Telemetry section linking to oss-telemetry opt-out docs
Discloses the single anonymous adoption ping sent on startup and points
users to the upstream README section for full opt-out instructions
instead of duplicating the table here.
2026-05-21 04:06:20 +01:00
lukaszraczylo 99b8bf937b fix(config-release): remove hardcoded force.commit and force.minor
The hardcoded force.commit (960207e4, from 2022) combined with
force.minor: 16 made semver-generator emit deterministic versions that
already existed as tags (v1.16.1-v1.16.5), causing goreleaser to fail
with 'git tag vX was not made against commit HEAD'.

Restores the intent of 99338e8 which was undone by the later fixup
commits a77bc0c and 5f205e9.

Also fixes 2-space leading indentation.
2026-05-21 03:43:25 +01:00
lukaszraczylo b555e410cc fixup! feat: anonymous usage telemetry via oss-telemetry 2026-05-21 03:24:42 +01:00
lukaszraczylo 521e5c1ff1 feat: anonymous usage telemetry via oss-telemetry
Send a single fire-and-forget ping at startup to help track adoption
and version spread. No persistent identifiers are collected.

Opt out via any of:
  DO_NOT_TRACK=1
  OSS_TELEMETRY_DISABLED=1
  SEMVER_GENERATOR_DISABLE_TELEMETRY=1
2026-05-21 02:45:29 +01:00
lukaszraczylo a223f15e1c Update dependencies 2026-05-21 01:37:58 +01:00
lukaszraczylo d1b8192b78 fixup! feat: auto-pin Docker image version in action.yml after release (#58) 2026-05-21 01:31:27 +01:00
Mateo a3aed9ef93 feat: auto-pin Docker image version in action.yml after release (#58)
Add update-action-version job that automatically updates action.yml
to reference the specific Docker image version after each release.

This ensures users pinning the action version get the matching Docker
image instead of :latest.
2026-01-22 19:21:25 +00:00
lukaszraczylo 5f205e9856 fixup! fixup! fix(config-release): remove hardcoded version and commit overrides 2026-01-09 14:15:16 +00:00
lukaszraczylo a77bc0c7ae fixup! fix(config-release): remove hardcoded version and commit overrides 2026-01-09 14:03:20 +00:00
lukaszraczylo 99338e8527 fix(config-release): remove hardcoded version and commit overrides
- [x] Remove hardcoded major version (1)
- [x] Remove hardcoded minor version (4)
- [x] Remove hardcoded commit hash override
2026-01-09 13:58:45 +00:00
lukaszraczylo 911513c106 fixup! fix(config-release): update semantic versioning configuration 2026-01-09 13:48:52 +00:00
lukaszraczylo c2a7a4e156 fix(config-release): update semantic versioning configuration
- [x] Remove minor version override (4)
- [x] Remove commit hash reference
- [x] Add blacklist for merge commits and feature branch patterns
- [x] Add release-candidate to major wording triggers
- [x] Remove commented tag_prefixes section
2026-01-09 13:47:17 +00:00
lukaszraczylo 21b87300cc Fix the commit annotation tags. 2025-12-15 13:51:26 +00:00
lukaszraczylo 3e0a7239c4 Fix ignoring strict.force and strict.commit. 2025-12-15 13:37:07 +00:00
lukaszraczylo 49a46a74c1 Add signing of the builds. 2025-12-15 00:43:42 +00:00
lukaszraczylo 3a48a67c75 Improve calculation logic, add ability to strip prefixes. 2025-12-10 14:37:38 +00:00
lukaszraczylo 18b9b474e0 fix: remove unnecessary verified parameter from homebrew cask
The verified parameter is only needed when the URL domain differs
from the homepage domain. Since both point to github.com, Homebrew
audit flags this as unnecessary.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 02:06:43 +00:00
lukaszraczylo f5a118fd1a Use shared PR workflow. 2025-12-08 02:06:43 +00:00
lukaszraczylo a1c4133e94 Update go.mod and go.sum (#57) 2025-12-08 01:22:53 +00:00
lukaszraczylo 2a51752663 Trigger autoupdate. 2025-12-08 01:14:40 +00:00
29 changed files with 674 additions and 462 deletions
+2
View File
@@ -8,6 +8,7 @@ on:
permissions:
contents: write
actions: write
pull-requests: write
jobs:
autoupdate:
@@ -15,3 +16,4 @@ jobs:
with:
go-version: "1.24"
release-workflow: "release.yaml"
secrets: inherit
+16
View File
@@ -0,0 +1,16 @@
name: Pull Request
on:
pull_request:
branches:
- main
push:
branches:
- "**"
- "!main"
jobs:
pr-checks:
uses: lukaszraczylo/shared-actions/.github/workflows/go-pr.yaml@main
with:
go-version: "1.24"
+33 -2
View File
@@ -6,11 +6,11 @@ on:
paths-ignore:
- '**.md'
- '**/release.yaml'
- 'action.yml'
branches:
- main
permissions:
id-token: write
contents: write
packages: write
@@ -18,8 +18,39 @@ jobs:
release:
uses: lukaszraczylo/shared-actions/.github/workflows/go-release.yaml@main
with:
go-version: "1.24"
go-version: ">=1.24"
docker-enabled: true
rolling-release-tag: "v1"
semver-config: "config-release.yaml"
secrets: inherit
update-action-version:
needs: release
runs-on: ubuntu-latest
if: needs.release.outputs.version != ''
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update action.yml with release version
env:
VERSION: ${{ needs.release.outputs.version }}
run: |
echo "Updating action.yml to version: ${VERSION}"
sed -i "s|ghcr.io/lukaszraczylo/semver-generator:[^\"]*|ghcr.io/lukaszraczylo/semver-generator:${VERSION}|" action.yml
echo "Updated action.yml:"
grep "image:" action.yml
- name: Commit and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add action.yml
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: pin action.yml Docker image to v${{ needs.release.outputs.version }}"
git push
fi
+20 -2
View File
@@ -80,8 +80,6 @@ homebrew_casks:
homepage: https://github.com/lukaszraczylo/semver-generator
description: "Automatic semantic version generator based on git commit messages"
license: MIT
url:
verified: github.com/lukaszraczylo/semver-generator
hooks:
post:
install: |
@@ -89,3 +87,23 @@ homebrew_casks:
system_command "/usr/bin/xattr",
args: ["-dr", "com.apple.quarantine", "#{staged_path}/semver-generator"]
end
signs:
- cmd: cosign
signature: "${artifact}.sigstore.json"
args:
- sign-blob
- "--bundle=${signature}"
- "${artifact}"
- "--yes"
artifacts: checksum
output: true
docker_signs:
- cmd: cosign
artifacts: manifests
output: true
args:
- sign
- "${artifact}@${digest}"
- "--yes"
+74 -1
View File
@@ -11,13 +11,19 @@ Project created overnight, to prove that management of semantic versioning is NO
- [Usage](#usage)
- [Authentication](#authentication)
- [As a binary](#as-a-binary)
- [Homebrew (macOS)](#homebrew-macos)
- [Manual Download](#manual-download)
- [Self-Update](#self-update)
- [As a github action](#as-a-github-action)
- [As a docker container](#as-a-docker-container)
- [Verifying Release Signatures](#verifying-release-signatures)
- [Calculations example \[standard\]](#calculations-example-standard)
- [Calculations example \[strict matching\]](#calculations-example-strict-matching)
- [Release candidates](#release-candidates)
- [Tag prefix stripping](#tag-prefix-stripping)
- [Example configuration](#example-configuration)
- [Good to know](#good-to-know)
- [Good to knows](#good-to-knows)
- [Telemetry](#telemetry)
### How does it work
@@ -29,6 +35,7 @@ Project created overnight, to prove that management of semantic versioning is NO
* With flag `-e` or config `force.existing: true` the existing tags in versioning will be respected, helping you to avoid the version conflicts.
* With config `force.commit: deadbeef` where `deadbeef` is the commit hash - calculations will start from the specified commit.
* Tag prefix stripping: The `v` prefix is automatically stripped from tags (e.g., `v1.2.3``1.2.3`). Additional prefixes can be configured via `tag_prefixes` for monorepo setups (e.g., `app-1.2.3`, `infra-1.2.3`).
### Important changes
@@ -144,6 +151,25 @@ jobs:
docker pull ghcr.io/lukaszraczylo/semver-generator:latest
```
#### Verifying Release Signatures
All release checksums and Docker images are signed with [cosign](https://github.com/sigstore/cosign) using keyless signing. To verify:
```bash
# Verify checksum signature
cosign verify-blob \
--certificate-identity-regexp "https://github.com/lukaszraczylo/semver-generator/.*" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
--bundle "<checksums-file>.sigstore.json" \
<checksums-file>
# Verify Docker image
cosign verify \
--certificate-identity-regexp "https://github.com/lukaszraczylo/semver-generator/.*" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
ghcr.io/lukaszraczylo/semver-generator:latest
```
**Docker supported architectures:**
Linux/arm64, Linux/amd64
@@ -182,6 +208,36 @@ to generate the appropriate release in format `1.3.37-rc.1` and counting up unti
- add-rc
```
#### Tag prefix stripping
When using the `-e` (existing tags) flag, the semver-generator needs to parse existing git tags to determine the current version. Tags often include prefixes that need to be stripped before version parsing.
**Automatic `v` prefix stripping:**
The `v` prefix is always stripped automatically from tags. For example:
- `v1.2.3` → parsed as `1.2.3`
- `v0.5.0` → parsed as `0.5.0`
**Custom prefixes for monorepos:**
In monorepo setups where different components have their own versioned tags, you can configure additional prefixes to strip:
```yaml
tag_prefixes:
- "app-"
- "infra-"
- "api-"
- "frontend-"
```
With this configuration:
- `app-1.2.3` → parsed as `1.2.3`
- `infra-0.5.0` → parsed as `0.5.0`
- `api-2.0.0-rc.1` → parsed as `2.0.0-rc.1` (release candidate)
This is particularly useful when:
- You have multiple services/components in a single repository
- Your CI/CD creates tags with component prefixes
- You want to track versions separately for different parts of your codebase
#### Example configuration
```yaml
@@ -196,6 +252,10 @@ blacklist:
- "Merge pull request"
- "feature/"
- "feature:"
tag_prefixes:
- "app-"
- "infra-"
- "service-"
wording:
patch:
- update
@@ -215,6 +275,7 @@ wording:
* `force`: sets the "starting" version, you don't need to specify this section as the default is always `0`
* `force.commit`: allows you to set commit hash from which the calculations should start
* `blacklist`: terms to ignore when processing commits. Any commit containing these terms will be skipped in version calculations. Useful for ignoring merge commits, feature branch names, and other unwanted triggers.
* `tag_prefixes`: prefixes to strip from existing tags before parsing version numbers. Useful for monorepos where tags are prefixed with component names (e.g., `app-1.2.3`, `infra-0.5.0`). The `v` prefix is always stripped automatically.
* `wording`: words the program should look for in the git commits to increment (patch|minor|major)
### Good to knows
@@ -222,3 +283,15 @@ wording:
* Word matching uses fuzzy search AND is case INSENSITIVE
* I do not recommend using common words ( like "the" from the example configuration )
* You can specify env variable `LOG_LEVEL=debug` to see what exactly happens during the calculations
### Telemetry
On startup this binary sends a single anonymous adoption ping — project name,
version, timestamp; no identifiers, no commit content, no repository data.
Fire-and-forget with a 2-second timeout; cannot block startup or panic.
See **[oss-telemetry — Disabling telemetry](https://github.com/lukaszraczylo/oss-telemetry#disabling-telemetry)**
for the exact wire format, source, and full opt-out documentation.
Quick opt-out: set any of `DO_NOT_TRACK=1`, `OSS_TELEMETRY_DISABLED=1`,
or `SEMVER_GENERATOR_DISABLE_TELEMETRY=1`.
+1 -1
View File
@@ -36,4 +36,4 @@ outputs:
description: "Calculated semantic version"
runs:
using: "docker"
image: "docker://ghcr.io/lukaszraczylo/semver-generator:latest"
image: "docker://ghcr.io/lukaszraczylo/semver-generator:1.17.3"
-16
View File
@@ -1,16 +0,0 @@
package cmd
import (
"github.com/lukaszraczylo/semver-generator/cmd/utils"
)
// These functions are now in the utils package
// They are kept here as stubs for backward compatibility
func updatePackage() bool {
return utils.UpdatePackage()
}
func checkLatestRelease() (string, bool) {
return utils.CheckLatestRelease()
}
-52
View File
@@ -1,52 +0,0 @@
package cmd
import (
"testing"
"github.com/lukaszraczylo/semver-generator/cmd/utils"
)
func Test_checkLatestRelease(t *testing.T) {
utils.InitLogger(true)
tests := []struct {
name string
want string
want1 bool
}{
{
name: "Check latest release",
want1: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, got1 := checkLatestRelease()
if got1 != tt.want1 {
t.Errorf("checkLatestRelease() got1 = %v, want %v", got1, tt.want1)
}
})
}
}
func Test_updatePackage(t *testing.T) {
utils.InitLogger(true)
if testing.Short() {
t.Skip("Skipping test in short / CI mode")
}
tests := []struct {
name string
want bool
}{
{
name: "Run autoupdater",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := updatePackage(); got != tt.want {
t.Errorf("updatePackage() = %v, want %v", got, tt.want)
}
})
}
}
+7 -2
View File
@@ -121,11 +121,15 @@ func main() {
}
// List commits
utils.ListCommits(&repo.GitRepo)
if _, err := utils.ListCommits(&repo.GitRepo); err != nil {
utils.Error("Unable to list commits", map[string]interface{}{
"error": err.Error(),
})
}
// List existing tags if needed
if params.varExisting || repo.Config.Force.Existing {
utils.ListExistingTags(&repo.GitRepo)
utils.ListExistingTags(&repo.GitRepo, repo.Config.TagPrefixes)
}
// Apply forced versioning
@@ -140,6 +144,7 @@ func main() {
repo.Semver,
params.varExisting || repo.Config.Force.Existing,
params.varStrict || repo.Config.Force.Strict,
repo.Config.TagPrefixes,
)
// Print semantic version
+39 -18
View File
@@ -267,7 +267,7 @@ func (suite *Tests) Test_checkMatches() {
if tt.name == "No match" {
return nil
}
// For other test cases, match if the needle is in the haystack
for _, h := range haystack {
if strings.Contains(h, needle) || strings.Contains(needle, h) {
@@ -276,7 +276,7 @@ func (suite *Tests) Test_checkMatches() {
}
return nil
}
got := utils.CheckMatches(tt.args.content, tt.args.targets, tt.blacklist)
assertObj.Equal(tt.want, got, "Unexpected result in "+tt.name)
})
@@ -285,7 +285,8 @@ func (suite *Tests) Test_checkMatches() {
func (suite *Tests) Test_parseExistingSemver() {
type args struct {
tagName string
tagName string
prefixes []string
}
tests := []struct {
name string
@@ -296,7 +297,8 @@ func (suite *Tests) Test_parseExistingSemver() {
{
name: "Test parsing existing semver",
args: args{
tagName: "1.2.3",
tagName: "1.2.3",
prefixes: []string{},
},
currentSemver: utils.SemVer{Major: 1, Minor: 1, Patch: 1},
wantSemanticVersion: utils.SemVer{
@@ -308,7 +310,8 @@ func (suite *Tests) Test_parseExistingSemver() {
{
name: "Test parsing existing semver with v",
args: args{
tagName: "v1.2.3",
tagName: "v1.2.3",
prefixes: []string{"v"},
},
currentSemver: utils.SemVer{Major: 1, Minor: 1, Patch: 1},
wantSemanticVersion: utils.SemVer{
@@ -320,7 +323,8 @@ func (suite *Tests) Test_parseExistingSemver() {
{
name: "Test parsing existing semver with rc",
args: args{
tagName: "1.2.5-rc.7",
tagName: "1.2.5-rc.7",
prefixes: []string{},
},
currentSemver: utils.SemVer{Major: 1, Minor: 1, Patch: 1},
wantSemanticVersion: utils.SemVer{
@@ -331,10 +335,25 @@ func (suite *Tests) Test_parseExistingSemver() {
EnableReleaseCandidate: true,
},
},
{
name: "Test parsing prefixed tag without rc",
args: args{
tagName: "app-0.0.16",
prefixes: []string{"app-", "infra-"},
},
currentSemver: utils.SemVer{Major: 1, Minor: 1, Patch: 1},
wantSemanticVersion: utils.SemVer{
Major: 0,
Minor: 0,
Patch: 16,
EnableReleaseCandidate: false,
},
},
{
name: "Test invalid semver format",
args: args{
tagName: "invalid",
tagName: "invalid",
prefixes: []string{},
},
currentSemver: utils.SemVer{Major: 2, Minor: 3, Patch: 4},
wantSemanticVersion: utils.SemVer{
@@ -346,7 +365,8 @@ func (suite *Tests) Test_parseExistingSemver() {
{
name: "Test partial semver",
args: args{
tagName: "1.2",
tagName: "1.2",
prefixes: []string{},
},
currentSemver: utils.SemVer{Major: 2, Minor: 3, Patch: 4},
wantSemanticVersion: utils.SemVer{
@@ -358,7 +378,8 @@ func (suite *Tests) Test_parseExistingSemver() {
{
name: "Test empty tag",
args: args{
tagName: "",
tagName: "",
prefixes: []string{},
},
currentSemver: utils.SemVer{Major: 2, Minor: 3, Patch: 4},
wantSemanticVersion: utils.SemVer{
@@ -370,7 +391,7 @@ func (suite *Tests) Test_parseExistingSemver() {
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {
got := utils.ParseExistingSemver(tt.args.tagName, tt.currentSemver)
got := utils.ParseExistingSemver(tt.args.tagName, tt.currentSemver, tt.args.prefixes)
assertObj.Equal(tt.wantSemanticVersion.Major, got.Major, "Unexpected MAJOR semver result in "+tt.name)
assertObj.Equal(tt.wantSemanticVersion.Minor, got.Minor, "Unexpected MINOR semver result in "+tt.name)
assertObj.Equal(tt.wantSemanticVersion.Patch, got.Patch, "Unexpected PATCH semver result in "+tt.name)
@@ -382,10 +403,10 @@ func (suite *Tests) Test_parseExistingSemver() {
func (suite *Tests) TestSetup_ListCommits() {
type fields struct {
RepositoryName string
RepositoryBranch string
LocalConfigFile string
GitRepo utils.GitRepository
RepositoryName string
RepositoryBranch string
LocalConfigFile string
GitRepo utils.GitRepository
}
tests := []struct {
@@ -441,23 +462,23 @@ func (suite *Tests) TestSetup_ListCommits() {
if tt.name == "List commits from existing repository" {
t.Skip("Skipping test that requires repository access")
}
s := &Setup{
RepositoryName: tt.fields.RepositoryName,
RepositoryBranch: tt.fields.RepositoryBranch,
GitRepo: tt.fields.GitRepo,
}
config, _ := utils.ReadConfig(tt.fields.LocalConfigFile)
s.Config = config
err := utils.PrepareRepository(&s.GitRepo)
if err != nil && !tt.wantErr {
if tt.name != "List commits starting with certain hash" {
t.Fatalf("Failed to prepare repository: %v", err)
}
}
if err == nil {
listOfCommits, err := utils.ListCommits(&s.GitRepo)
if !tt.wantErr {
+3 -3
View File
@@ -30,13 +30,13 @@ func TestExecute(t *testing.T) {
Short: "Test command",
Run: func(cmd *cobra.Command, args []string) {},
}
// Add all the required flags to the test command
testCmd.Flags().Bool("version", false, "Print version information")
testCmd.Flags().String("repository", "test-repo", "Repository URL")
testCmd.Flags().String("branch", "test-branch", "Repository branch")
testCmd.Flags().String("config", "test-config", "Config file path")
rootCmd = testCmd
// Execute should not panic
@@ -82,4 +82,4 @@ func TestSetupCobra(t *testing.T) {
assertions.Equal(t, "test-branch", testRepo.RepositoryBranch, "Repository branch should be set")
assertions.Equal(t, "test-config", testRepo.LocalConfigFile, "Config file should be set")
assertions.True(t, testRepo.UseLocal, "UseLocal should be set to true")
}
}
+22 -12
View File
@@ -26,26 +26,36 @@ type Force struct {
// Config represents the application configuration
type Config struct {
Wording Wording
Force Force
Blacklist []string
Wording Wording
Force Force
Blacklist []string
TagPrefixes []string // Prefixes to strip from tags before parsing (e.g., "app-", "infra-", "v")
}
// ReadConfig reads the configuration from a file
func ReadConfig(file string) (*Config, error) {
config := &Config{}
viper.SetConfigFile(file)
err := viper.ReadInConfig()
if err != nil {
err = fmt.Errorf("fatal error config file: %s", err)
return config, err
}
viper.UnmarshalKey("wording", &config.Wording)
viper.UnmarshalKey("force", &config.Force)
viper.UnmarshalKey("blacklist", &config.Blacklist)
if err := viper.UnmarshalKey("wording", &config.Wording); err != nil {
return config, fmt.Errorf("error parsing wording config: %w", err)
}
if err := viper.UnmarshalKey("force", &config.Force); err != nil {
return config, fmt.Errorf("error parsing force config: %w", err)
}
if err := viper.UnmarshalKey("blacklist", &config.Blacklist); err != nil {
return config, fmt.Errorf("error parsing blacklist config: %w", err)
}
if err := viper.UnmarshalKey("tag_prefixes", &config.TagPrefixes); err != nil {
return config, fmt.Errorf("error parsing tag_prefixes config: %w", err)
}
return config, nil
}
@@ -55,14 +65,14 @@ func ApplyForcedVersioning(force Force, semver *SemVer) {
Debug("Forced versioning (MAJOR)", map[string]interface{}{"major": force.Major})
semver.Major = force.Major
}
if force.Minor > 0 {
Debug("Forced versioning (MINOR)", map[string]interface{}{"minor": force.Minor})
semver.Minor = force.Minor
}
if force.Patch > 0 {
Debug("Forced versioning (PATCH)", map[string]interface{}{"patch": force.Patch})
semver.Patch = force.Patch
}
}
}
+1 -1
View File
@@ -198,4 +198,4 @@ wording:
// Test reading a non-existent config
_, err = ReadConfig("non-existent-file.yaml")
assert.Error(t, err)
}
}
+70 -39
View File
@@ -29,14 +29,14 @@ type TagDetails struct {
// GitRepository represents a git repository
type GitRepository struct {
Handler *git.Repository
Name string
Branch string
LocalPath string
UseLocal bool
Commits []CommitDetails
Tags []TagDetails
StartCommit string
Handler *git.Repository
Name string
Branch string
LocalPath string
UseLocal bool
Commits []CommitDetails
Tags []TagDetails
StartCommit string
}
// PrepareRepository prepares the git repository for use
@@ -47,15 +47,15 @@ func PrepareRepository(repo *GitRepository) error {
u, err := url.Parse(repo.Name)
if err != nil {
Error("Unable to parse repository URL", map[string]interface{}{
"error": err.Error(),
"url": repo.Name,
"error": err.Error(),
"url": repo.Name,
})
return err
}
repo.LocalPath = fmt.Sprintf("/tmp/semver/%s/%s", u.Path, repo.Branch)
os.RemoveAll(repo.LocalPath)
_ = os.RemoveAll(repo.LocalPath) // Ignore error - directory may not exist
repo.Handler, err = git.PlainClone(repo.LocalPath, false, &git.CloneOptions{
URL: repo.Name,
ReferenceName: plumbing.NewBranchReferenceName(repo.Branch),
@@ -66,11 +66,11 @@ func PrepareRepository(repo *GitRepository) error {
},
Tags: git.AllTags,
})
if err != nil {
Error("Unable to clone repository", map[string]interface{}{
"error": err.Error(),
"url": repo.Name,
"error": err.Error(),
"url": repo.Name,
})
return err
}
@@ -79,14 +79,20 @@ func PrepareRepository(repo *GitRepository) error {
repo.Handler, err = git.PlainOpen(repo.LocalPath)
if err != nil {
Error("Unable to open local repository", map[string]interface{}{
"error": err.Error(),
"path": repo.LocalPath,
"error": err.Error(),
"path": repo.LocalPath,
})
return err
}
}
os.Chdir(repo.LocalPath)
if err := os.Chdir(repo.LocalPath); err != nil {
Error("Unable to change directory", map[string]interface{}{
"error": err.Error(),
"path": repo.LocalPath,
})
return err
}
return nil
}
@@ -105,14 +111,14 @@ func ListCommits(repo *GitRepository) ([]CommitDetails, error) {
if err != nil {
return []CommitDetails{}, err
}
commitsList, err := repo.Handler.Log(&git.LogOptions{From: ref.Hash()})
if err != nil {
return []CommitDetails{}, err
}
var tmpResults []CommitDetails
commitsList.ForEach(func(c *object.Commit) error {
if err := commitsList.ForEach(func(c *object.Commit) error {
tmpResults = append(tmpResults, CommitDetails{
Hash: c.Hash.String(),
Author: c.Author.String(),
@@ -123,22 +129,31 @@ func ListCommits(repo *GitRepository) ([]CommitDetails, error) {
return tmpResults[i].Timestamp.Unix() < tmpResults[j].Timestamp.Unix()
})
return nil
})
}); err != nil {
return []CommitDetails{}, err
}
Debug("Listing commits", map[string]interface{}{"commits": tmpResults})
// Filter commits starting from the specified commit if provided
// Filter commits starting after the specified commit if provided
if repo.StartCommit != "" {
found := false
for commitId, cmt := range tmpResults {
if cmt.Hash == repo.StartCommit {
Debug("Found commit match", map[string]interface{}{
"commit": cmt.Hash,
"index": commitId,
"index": commitId,
})
repo.Commits = tmpResults[commitId:]
// Start from the commit AFTER the specified one
repo.Commits = tmpResults[commitId+1:]
found = true
break
}
}
if !found {
// If specified commit not found, use all commits
repo.Commits = tmpResults
}
} else {
repo.Commits = tmpResults
}
@@ -148,34 +163,50 @@ func ListCommits(repo *GitRepository) ([]CommitDetails, error) {
}
// ListExistingTags lists all tags in the repository
func ListExistingTags(repo *GitRepository) {
// ListExistingTags lists all tags in the repository.
// Tags that don't parse as proper semver (rolling tags like "v1" or "latest")
// are skipped so they can't out-rank real semver tags pointing to the same
// commit during latest-tag selection.
func ListExistingTags(repo *GitRepository, tagPrefixes []string) {
Debug("Listing existing tags", nil)
// Check if Handler is nil to avoid panic
if repo.Handler == nil {
Debug("Repository handler is nil, skipping tag listing", nil)
return
}
refs, err := repo.Handler.Tags()
if err != nil {
Error("Unable to list tags", map[string]interface{}{"error": err.Error()})
return
}
if err := refs.ForEach(func(ref *plumbing.Reference) error {
tagName := ref.Name().Short()
if !IsParseableSemverTag(tagName, tagPrefixes) {
Debug("Skipping non-semver tag", map[string]interface{}{"tag": tagName})
return nil
}
commitHash := ref.Hash().String()
tagObj, err := repo.Handler.TagObject(ref.Hash())
if err == nil {
commitHash = tagObj.Target.String()
}
repo.Tags = append(repo.Tags, TagDetails{
Name: ref.Name().Short(),
Hash: ref.Hash().String(),
Name: tagName,
Hash: commitHash,
})
Debug("Found tag", map[string]interface{}{
"tag": ref.Name().Short(),
"hash": ref.Hash().String(),
"tag": tagName,
"hash": commitHash,
})
return nil
}); err != nil {
Error("Error iterating tags", map[string]interface{}{"error": err.Error()})
}
}
}
+14 -14
View File
@@ -64,7 +64,7 @@ func TestListCommits(t *testing.T) {
t.Run("Test commit filtering logic", func(t *testing.T) {
// Create a test repository with predefined commits
repo := &GitRepository{}
// Manually populate the commits for testing
repo.Commits = []CommitDetails{
{
@@ -83,7 +83,7 @@ func TestListCommits(t *testing.T) {
// Test with StartCommit specified
repo.StartCommit = "def456"
// Instead of calling ListCommits which would try to use the nil Handler,
// we'll just test the filtering logic directly
if repo.StartCommit != "" {
@@ -94,19 +94,19 @@ func TestListCommits(t *testing.T) {
}
}
}
// Verify the filtering worked correctly
assert.Len(t, repo.Commits, 1, "Should filter commits starting from specified hash")
assert.Equal(t, "def456", repo.Commits[0].Hash, "Commit hash should match")
})
t.Run("Test with nil Handler", func(t *testing.T) {
// Create a test repository with nil Handler
repo := &GitRepository{}
// Now we can safely call ListCommits since we've added a nil check
commits, err := ListCommits(repo)
// Verify the function returns without error
assert.NoError(t, err, "Should not error with nil Handler")
assert.Empty(t, commits, "Should return empty commits with nil Handler")
@@ -120,10 +120,10 @@ func TestListExistingTags(t *testing.T) {
t.Run("Test tag processing", func(t *testing.T) {
// Create a test repository
repo := &GitRepository{}
// Since we can't test the actual git operations, we'll test the function's behavior
// by manually setting up the repository state
// Manually add tags to verify they're processed correctly
repo.Tags = []TagDetails{
{
@@ -131,20 +131,20 @@ func TestListExistingTags(t *testing.T) {
Hash: "abc123",
},
}
assert.Len(t, repo.Tags, 1, "Should have 1 tag")
assert.Equal(t, "v1.0.0", repo.Tags[0].Name, "Tag name should match")
assert.Equal(t, "abc123", repo.Tags[0].Hash, "Tag hash should match")
})
t.Run("Test with nil Handler", func(t *testing.T) {
// Create a test repository with nil Handler
repo := &GitRepository{}
// Now we can safely call ListExistingTags since we've added a nil check
ListExistingTags(repo)
ListExistingTags(repo, nil)
// Verify no tags were added
assert.Empty(t, repo.Tags, "Should have no tags after calling with nil Handler")
})
}
}
+18 -82
View File
@@ -34,14 +34,6 @@ type ReleaseAsset struct {
BrowserDownloadURL string `json:"browser_download_url"`
}
// UpdateInfo contains information about an available update
type UpdateInfo struct {
CurrentVersion string
LatestVersion string
ReleaseURL string
DownloadURL string
}
// httpClient is the HTTP client used for requests (allows mocking in tests)
var httpClient = &http.Client{
Timeout: requestTimeout,
@@ -60,30 +52,6 @@ func CheckLatestRelease() (string, bool) {
return version, true
}
// CheckForUpdate checks if a newer version is available
// Returns UpdateInfo if an update is available, nil otherwise
func CheckForUpdate(currentVersion string) *UpdateInfo {
release, err := fetchLatestRelease(context.Background())
if err != nil {
return nil
}
latestVersion := normalizeVersion(release.TagName)
current := normalizeVersion(currentVersion)
if isNewerVersion(latestVersion, current) {
downloadURL := findBinaryAsset(release.Assets)
return &UpdateInfo{
CurrentVersion: current,
LatestVersion: latestVersion,
ReleaseURL: release.HTMLURL,
DownloadURL: downloadURL,
}
}
return nil
}
// UpdatePackage downloads and installs the latest version
func UpdatePackage() bool {
Info("Checking for updates", nil)
@@ -219,20 +187,23 @@ func downloadBinary(url string) (string, error) {
if strings.HasSuffix(url, ".tar.gz") {
// For tar.gz, we need to extract the binary
if err := extractTarGz(resp.Body, tempFile); err != nil {
tempFile.Close()
os.Remove(tempPath)
_ = tempFile.Close()
_ = os.Remove(tempPath)
return "", err
}
} else {
// Direct binary download
if _, err := io.Copy(tempFile, resp.Body); err != nil {
tempFile.Close()
os.Remove(tempPath)
_ = tempFile.Close()
_ = os.Remove(tempPath)
return "", err
}
}
tempFile.Close()
if err := tempFile.Close(); err != nil {
_ = os.Remove(tempPath)
return "", err
}
return tempPath, nil
}
@@ -250,10 +221,12 @@ func extractTarGz(r io.Reader, destFile *os.File) error {
defer os.Remove(archivePath)
if _, err := io.Copy(archiveFile, r); err != nil {
archiveFile.Close()
_ = archiveFile.Close()
return err
}
if err := archiveFile.Close(); err != nil {
return err
}
archiveFile.Close()
// Extract using tar command
extractDir, err := os.MkdirTemp("", "semver-generator-extract-*")
@@ -336,6 +309,7 @@ var runCommandFunc = func(cmdStr string) error {
// replaceBinary replaces the current binary with the new one
func replaceBinary(newBinary, currentBinary string) error {
// Make the new binary executable
// #nosec G302 -- 0755 is required for executable binaries
if err := os.Chmod(newBinary, 0755); err != nil {
return err
}
@@ -350,13 +324,17 @@ func replaceBinary(newBinary, currentBinary string) error {
}
// copyFile copies a file from src to dst
// Note: This function is only called internally with controlled paths from
// os.CreateTemp and os.Executable, not with user-supplied paths.
func copyFile(src, dst string) error {
// #nosec G304 -- src is from os.CreateTemp, not user input
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()
// #nosec G304 -- dst is from os.Executable, not user input
dstFile, err := os.Create(dst)
if err != nil {
return err
@@ -368,6 +346,7 @@ func copyFile(src, dst string) error {
}
// Make executable
// #nosec G302 -- 0755 is required for executable binaries
return os.Chmod(dst, 0755)
}
@@ -378,46 +357,3 @@ func normalizeVersion(v string) string {
v = strings.TrimPrefix(v, "V")
return v
}
// isNewerVersion compares two semver-like versions
// Returns true if latest is newer than current
func isNewerVersion(latest, current string) bool {
latestParts := parseVersionParts(latest)
currentParts := parseVersionParts(current)
for i := 0; i < len(latestParts) && i < len(currentParts); i++ {
if latestParts[i] > currentParts[i] {
return true
}
if latestParts[i] < currentParts[i] {
return false
}
}
return len(latestParts) > len(currentParts)
}
// parseVersionParts splits a version string into numeric parts
func parseVersionParts(v string) []int {
// Remove any suffix like -beta, -rc1, etc.
if idx := strings.IndexAny(v, "-+"); idx != -1 {
v = v[:idx]
}
parts := strings.Split(v, ".")
result := make([]int, 0, len(parts))
for _, p := range parts {
var num int
fmt.Sscanf(p, "%d", &num)
result = append(result, num)
}
return result
}
// FormatUpdateMessage formats a user-friendly update notification
func (u *UpdateInfo) FormatUpdateMessage() string {
return fmt.Sprintf("New version available: %s (current: %s) - %s",
u.LatestVersion, u.CurrentVersion, u.ReleaseURL)
}
-80
View File
@@ -30,57 +30,6 @@ func TestNormalizeVersion(t *testing.T) {
}
}
func TestParseVersionParts(t *testing.T) {
tests := []struct {
input string
expected []int
}{
{"1.0.0", []int{1, 0, 0}},
{"2.1.3", []int{2, 1, 3}},
{"1.0", []int{1, 0}},
{"10.20.30", []int{10, 20, 30}},
{"1.0.0-beta", []int{1, 0, 0}},
{"1.0.0-rc1", []int{1, 0, 0}},
{"1.0.0+build123", []int{1, 0, 0}},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
result := parseVersionParts(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
func TestIsNewerVersion(t *testing.T) {
tests := []struct {
name string
latest string
current string
expected bool
}{
{"major version bump", "2.0.0", "1.0.0", true},
{"minor version bump", "1.1.0", "1.0.0", true},
{"patch version bump", "1.0.1", "1.0.0", true},
{"same version", "1.0.0", "1.0.0", false},
{"current is newer major", "1.0.0", "2.0.0", false},
{"current is newer minor", "1.0.0", "1.1.0", false},
{"current is newer patch", "1.0.0", "1.0.1", false},
{"multi-digit versions", "1.10.0", "1.9.0", true},
{"longer version is newer", "1.0.1", "1.0", true},
{"shorter version is older", "1.0", "1.0.1", false},
{"complex comparison", "2.1.3", "2.1.2", true},
{"real world example", "0.2.0", "0.1.0", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isNewerVersion(tt.latest, tt.current)
assert.Equal(t, tt.expected, result)
})
}
}
func TestFindBinaryAsset(t *testing.T) {
assets := []ReleaseAsset{
{Name: "semver-gen-1.0.0-linux-amd64.tar.gz", BrowserDownloadURL: "https://example.com/linux-amd64.tar.gz"},
@@ -102,19 +51,6 @@ func TestFindBinaryAssetEmpty(t *testing.T) {
assert.Empty(t, url, "Should return empty string when no assets")
}
func TestUpdateInfo_FormatUpdateMessage(t *testing.T) {
info := &UpdateInfo{
CurrentVersion: "1.0.0",
LatestVersion: "2.0.0",
ReleaseURL: "https://github.com/lukaszraczylo/semver-generator/releases/tag/v2.0.0",
}
msg := info.FormatUpdateMessage()
assert.Contains(t, msg, "2.0.0")
assert.Contains(t, msg, "1.0.0")
assert.Contains(t, msg, "https://github.com/lukaszraczylo/semver-generator/releases/tag/v2.0.0")
}
func TestCheckLatestRelease(t *testing.T) {
// Initialize logger
InitLogger(false)
@@ -141,22 +77,6 @@ func TestCheckLatestRelease(t *testing.T) {
}
}
func TestCheckForUpdate(t *testing.T) {
InitLogger(false)
// Test with a very old version - should show update available if network works
info := CheckForUpdate("0.0.1")
// This will either return update info or nil depending on network
if info != nil {
assert.NotEmpty(t, info.LatestVersion)
assert.Equal(t, "0.0.1", info.CurrentVersion)
}
// Test with a very new version - should not show update
info = CheckForUpdate("999.999.999")
assert.Nil(t, info, "Should not show update for future version")
}
func TestFetchLatestReleaseError(t *testing.T) {
InitLogger(false)
+1 -1
View File
@@ -56,4 +56,4 @@ func Critical(message string, pairs map[string]interface{}) {
Pairs: pairs,
})
}
}
}
+9 -8
View File
@@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestInitLogger(t *testing.T) {
// Test with debug mode enabled
logger := InitLogger(true)
@@ -25,10 +26,10 @@ func TestLoggingFunctions(t *testing.T) {
Debug("Debug message", map[string]interface{}{"key": "value"})
Info("Info message", map[string]interface{}{"key": "value"})
Error("Error message", map[string]interface{}{"key": "value"})
// Skip testing Critical as it might call os.Exit
// Critical("Critical message", map[string]interface{}{"key": "value"})
// Test passes if we get here without panicking
assert.True(t, true)
}
@@ -43,10 +44,10 @@ func TestLoggingWithNilLogger(t *testing.T) {
Debug("Debug message", map[string]interface{}{"key": "value"})
Info("Info message", map[string]interface{}{"key": "value"})
Error("Error message", map[string]interface{}{"key": "value"})
// Skip testing Critical as it might call os.Exit
// Critical("Critical message", map[string]interface{}{"key": "value"})
// Test passes if we get here without panicking
assert.True(t, true)
}
@@ -56,15 +57,15 @@ func TestCriticalNilLogger(t *testing.T) {
// Save original logger and restore after test
originalLogger := Logger
defer func() { Logger = originalLogger }()
// Set logger to nil
Logger = nil
// This should not panic
Critical("Critical message", map[string]interface{}{"key": "value"})
// Test passes if we get here without panicking
assert.True(t, true)
}
// Note: We don't test Critical with an actual logger because it calls os.Exit
// Note: We don't test Critical with an actual logger because it calls os.Exit
+37 -21
View File
@@ -13,29 +13,45 @@ func CalculateSemver(
initialSemver SemVer,
respectExisting bool,
strictMode bool,
tagPrefixes []string,
) SemVer {
semver := initialSemver
startIndex := 0
for _, commit := range commits {
// Check for existing tags if enabled
if respectExisting {
for _, tagHash := range tags {
if commit.Hash == tagHash.Hash {
Debug("Found existing tag", map[string]interface{}{
"tag": tagHash.Name,
"commit": strings.TrimSuffix(commit.Message, "\n"),
})
semver = ParseExistingSemver(tagHash.Name, semver)
continue
// If respecting existing tags, find the latest tagged commit and start from there
if respectExisting && len(tags) > 0 {
latestTagIndex := -1
var latestTagName string
// Find the latest tagged commit (highest index since commits are oldest-first)
for i, commit := range commits {
for _, tag := range tags {
if commit.Hash == tag.Hash {
if i > latestTagIndex {
latestTagIndex = i
latestTagName = tag.Name
}
}
}
}
// If we found a tagged commit, use its version and start processing after it
if latestTagIndex >= 0 {
Debug("Found latest existing tag", map[string]interface{}{
"tag": latestTagName,
"commit": strings.TrimSuffix(commits[latestTagIndex].Message, "\n"),
})
semver = ParseExistingSemver(latestTagName, semver, tagPrefixes)
startIndex = latestTagIndex + 1
}
}
for _, commit := range commits[startIndex:] {
// In non-strict mode, increment patch by default
if !strictMode {
semver.Patch++
Debug("Incrementing patch (DEFAULT)", map[string]interface{}{
"commit": strings.TrimSuffix(commit.Message, "\n"),
"commit": strings.TrimSuffix(commit.Message, "\n"),
"semver": FormatSemver(semver),
})
}
@@ -55,44 +71,44 @@ func CalculateSemver(
semver.EnableReleaseCandidate = false
semver.Release = 0
Debug("Incrementing major (WORDING)", map[string]interface{}{
"commit": strings.TrimSuffix(commit.Message, "\n"),
"commit": strings.TrimSuffix(commit.Message, "\n"),
"semver": FormatSemver(semver),
})
continue
}
if matchMinor {
semver.Minor++
semver.Patch = 1
semver.EnableReleaseCandidate = false
semver.Release = 0
Debug("Incrementing minor (WORDING)", map[string]interface{}{
"commit": strings.TrimSuffix(commit.Message, "\n"),
"commit": strings.TrimSuffix(commit.Message, "\n"),
"semver": FormatSemver(semver),
})
continue
}
if matchReleaseCandidate {
semver.Release++
semver.Patch = 1
semver.EnableReleaseCandidate = true
Debug("Incrementing release candidate (WORDING)", map[string]interface{}{
"commit": strings.TrimSuffix(commit.Message, "\n"),
"commit": strings.TrimSuffix(commit.Message, "\n"),
"semver": FormatSemver(semver),
})
continue
}
if matchPatch {
semver.Patch++
Debug("Incrementing patch (WORDING)", map[string]interface{}{
"commit": strings.TrimSuffix(commit.Message, "\n"),
"commit": strings.TrimSuffix(commit.Message, "\n"),
"semver": FormatSemver(semver),
})
continue
}
}
return semver
}
}
+52 -11
View File
@@ -19,7 +19,7 @@ func TestCalculateSemver(t *testing.T) {
// More sophisticated mock implementation for testing
for _, h := range haystack {
// Check for substring match to better simulate fuzzy search
if h == needle || (len(h) >= 3 && len(needle) >= 3 &&
if h == needle || (len(h) >= 3 && len(needle) >= 3 &&
(h[:3] == needle[:3] || h[len(h)-3:] == needle[len(needle)-3:])) {
return []string{h}
}
@@ -29,7 +29,7 @@ func TestCalculateSemver(t *testing.T) {
// Test data
now := time.Now()
// Common wording and blacklist for all tests
wording := Wording{
Patch: []string{"update", "fix", "initial"},
@@ -49,6 +49,7 @@ func TestCalculateSemver(t *testing.T) {
initialSemver SemVer
respectExisting bool
strictMode bool
tagPrefixes []string
want SemVer
}{
{
@@ -76,11 +77,12 @@ func TestCalculateSemver(t *testing.T) {
initialSemver: SemVer{},
respectExisting: true,
strictMode: false,
tagPrefixes: []string{},
want: SemVer{
Major: 2,
Minor: 0,
Patch: 1, // Initial tag 2.0.0 + one patch increment
Release: 1,
Major: 2,
Minor: 0,
Patch: 1, // Initial tag 2.0.0 + one patch increment
Release: 1,
EnableReleaseCandidate: true,
},
},
@@ -109,11 +111,12 @@ func TestCalculateSemver(t *testing.T) {
initialSemver: SemVer{},
respectExisting: true,
strictMode: true,
tagPrefixes: []string{},
want: SemVer{
Major: 2,
Minor: 0,
Patch: 1, // Initial tag 2.0.0 + patch from "update" keyword
Release: 1,
Major: 2,
Minor: 0,
Patch: 1, // Initial tag 2.0.0 + patch from "update" keyword
Release: 1,
EnableReleaseCandidate: true,
},
},
@@ -142,6 +145,7 @@ func TestCalculateSemver(t *testing.T) {
initialSemver: SemVer{},
respectExisting: false,
strictMode: false,
tagPrefixes: []string{},
want: SemVer{
Major: 0,
Minor: 1,
@@ -173,6 +177,7 @@ func TestCalculateSemver(t *testing.T) {
initialSemver: SemVer{Major: 1},
respectExisting: false,
strictMode: true,
tagPrefixes: []string{},
want: SemVer{
Major: 1,
Minor: 1,
@@ -199,6 +204,7 @@ func TestCalculateSemver(t *testing.T) {
initialSemver: SemVer{},
respectExisting: false,
strictMode: false,
tagPrefixes: []string{},
want: SemVer{
Major: 0,
Minor: 0,
@@ -225,6 +231,7 @@ func TestCalculateSemver(t *testing.T) {
initialSemver: SemVer{},
respectExisting: false,
strictMode: false,
tagPrefixes: []string{},
want: SemVer{
Major: 0,
Minor: 0,
@@ -233,6 +240,39 @@ func TestCalculateSemver(t *testing.T) {
EnableReleaseCandidate: true,
},
},
{
name: "With prefixed tags should not be RC",
commits: []CommitDetails{
{
Hash: "commit1",
Message: "tagged commit",
Timestamp: now.Add(-3 * time.Hour),
},
{
Hash: "commit2",
Message: "another commit",
Timestamp: now.Add(-2 * time.Hour),
},
},
tags: []TagDetails{
{
Name: "app-0.0.16",
Hash: "commit1",
},
},
wording: wording,
blacklist: blacklist,
initialSemver: SemVer{},
respectExisting: true,
strictMode: true, // Use strict mode for predictable results
tagPrefixes: []string{"app-", "infra-"},
want: SemVer{
Major: 0,
Minor: 0,
Patch: 16, // From tag, no additional increments in strict mode
EnableReleaseCandidate: false,
},
},
}
for _, tt := range tests {
@@ -245,6 +285,7 @@ func TestCalculateSemver(t *testing.T) {
tt.initialSemver,
tt.respectExisting,
tt.strictMode,
tt.tagPrefixes,
)
assert.Equal(t, tt.want.Major, got.Major, "Major version mismatch")
@@ -254,4 +295,4 @@ func TestCalculateSemver(t *testing.T) {
assert.Equal(t, tt.want.EnableReleaseCandidate, got.EnableReleaseCandidate, "EnableReleaseCandidate mismatch")
})
}
}
}
+95 -22
View File
@@ -51,52 +51,125 @@ func FormatSemver(semver SemVer) string {
var extractNumber = regexp.MustCompile("[0-9]+")
// StripTagPrefix removes configured prefixes from a tag name
// The "v" prefix is always stripped by default (e.g., v1.2.3 -> 1.2.3)
func StripTagPrefix(tagName string, prefixes []string) string {
result := tagName
// Always strip "v" prefix by default
if strings.HasPrefix(result, "v") && len(result) > 1 {
// Only strip if followed by a digit (to avoid stripping "version-1.0.0")
if result[1] >= '0' && result[1] <= '9' {
result = result[1:]
Debug("Stripped default 'v' prefix from tag", map[string]interface{}{
"original": tagName,
"result": result,
})
}
}
// Then strip any user-configured prefixes
for _, prefix := range prefixes {
if strings.HasPrefix(result, prefix) {
result = strings.TrimPrefix(result, prefix)
Debug("Stripped prefix from tag", map[string]interface{}{
"original": tagName,
"prefix": prefix,
"result": result,
})
break // Only strip one prefix
}
}
return result
}
// IsParseableSemverTag reports whether tagName looks like a proper semver tag
// (X.Y.Z, optionally vX.Y.Z, optionally with -rc.N suffix) after configured
// prefixes are stripped. Rolling tags like "v1" or "latest" return false so the
// calculator can skip them when picking the latest existing tag — preventing a
// rolling tag tied to the same commit as a real semver tag from "winning" the
// alphabetical iteration in go-git and resetting the baseline to 0.0.0.
func IsParseableSemverTag(tagName string, prefixes []string) bool {
clean := StripTagPrefix(tagName, prefixes)
if idx := strings.Index(clean, "-rc."); idx != -1 {
clean = clean[:idx]
}
parts := strings.Split(clean, ".")
if len(parts) < 3 {
return false
}
for _, p := range parts[:3] {
if len(extractNumber.FindAllString(p, -1)) == 0 {
return false
}
}
return true
}
// ParseExistingSemver parses a semantic version from a tag name
func ParseExistingSemver(tagName string, currentSemver SemVer) SemVer {
func ParseExistingSemver(tagName string, currentSemver SemVer, prefixes []string) SemVer {
Debug("Parsing existing semver", map[string]interface{}{"tag": tagName})
tagNameParts := strings.Split(tagName, ".")
// Strip configured prefixes before parsing
cleanTagName := StripTagPrefix(tagName, prefixes)
// Check for release candidate pattern (-rc.X) before splitting
isReleaseCandidate := false
rcVersion := 0
if idx := strings.Index(cleanTagName, "-rc."); idx != -1 {
isReleaseCandidate = true
rcPart := cleanTagName[idx+4:] // Get everything after "-rc."
rcMatches := extractNumber.FindAllString(rcPart, 1)
if len(rcMatches) > 0 {
rcVersion, _ = strconv.Atoi(rcMatches[0])
}
// Remove the RC suffix for version parsing
cleanTagName = cleanTagName[:idx]
Debug("Detected release candidate", map[string]interface{}{
"rc_version": rcVersion,
"clean_tag_name": cleanTagName,
})
}
tagNameParts := strings.Split(cleanTagName, ".")
if len(tagNameParts) < 3 {
Debug("Unable to parse incompatible semver (non x.y.z)", map[string]interface{}{"tag": tagName})
return currentSemver
}
semanticVersion := SemVer{}
// Extract major version
majorMatches := extractNumber.FindAllString(tagNameParts[0], -1)
if len(majorMatches) > 0 {
semanticVersion.Major, _ = strconv.Atoi(majorMatches[0])
}
// Extract minor version
minorMatches := extractNumber.FindAllString(tagNameParts[1], -1)
if len(minorMatches) > 0 {
semanticVersion.Minor, _ = strconv.Atoi(minorMatches[0])
}
// Extract patch version
patchMatches := extractNumber.FindAllString(tagNameParts[2], -1)
if len(patchMatches) > 0 {
semanticVersion.Patch, _ = strconv.Atoi(patchMatches[0])
}
// Extract release candidate version if present
if len(tagNameParts) > 3 {
releaseMatches := extractNumber.FindAllString(tagNameParts[3], -1)
if len(releaseMatches) > 0 {
semanticVersion.Release, _ = strconv.Atoi(releaseMatches[0])
semanticVersion.EnableReleaseCandidate = true
}
// Set release candidate if detected
if isReleaseCandidate {
semanticVersion.Release = rcVersion
semanticVersion.EnableReleaseCandidate = true
}
return semanticVersion
}
// CheckMatches checks if any of the targets match the content
func CheckMatches(content []string, targets []string, blacklist []string) bool {
contentStr := strings.Join(content, " ")
// First check if any target matches
hasMatch := false
for _, tgt := range targets {
@@ -104,8 +177,8 @@ func CheckMatches(content []string, targets []string, blacklist []string) bool {
if len(matches) > 0 {
hasMatch = true
Debug("Found match", map[string]interface{}{
"target": tgt,
"match": strings.Join(matches, ","),
"target": tgt,
"match": strings.Join(matches, ","),
"content": contentStr,
})
break
@@ -117,14 +190,14 @@ func CheckMatches(content []string, targets []string, blacklist []string) bool {
for _, blacklistTerm := range blacklist {
if strings.Contains(strings.ToLower(contentStr), strings.ToLower(blacklistTerm)) {
Debug("Blacklisted term detected, ignoring commit", map[string]interface{}{
"content": contentStr,
"content": contentStr,
"blacklist_term": blacklistTerm,
})
return false
}
}
}
return hasMatch
}
@@ -132,4 +205,4 @@ func CheckMatches(content []string, targets []string, blacklist []string) bool {
var FuzzyFind = func(needle string, haystack []string) []string {
// This will be replaced with the actual implementation in main.go
return nil
}
}
+92 -11
View File
@@ -58,15 +58,17 @@ func TestParseExistingSemver(t *testing.T) {
InitLogger(false)
tests := []struct {
name string
tagName string
name string
tagName string
currentSemver SemVer
want SemVer
prefixes []string
want SemVer
}{
{
name: "Standard semver",
tagName: "1.2.3",
name: "Standard semver",
tagName: "1.2.3",
currentSemver: SemVer{},
prefixes: []string{},
want: SemVer{
Major: 1,
Minor: 2,
@@ -74,9 +76,10 @@ func TestParseExistingSemver(t *testing.T) {
},
},
{
name: "With v prefix",
tagName: "v2.3.4",
name: "With v prefix configured",
tagName: "v2.3.4",
currentSemver: SemVer{},
prefixes: []string{"v"},
want: SemVer{
Major: 2,
Minor: 3,
@@ -84,9 +87,32 @@ func TestParseExistingSemver(t *testing.T) {
},
},
{
name: "With release candidate",
tagName: "3.4.5-rc.2",
name: "With app- prefix configured",
tagName: "app-1.2.3",
currentSemver: SemVer{},
prefixes: []string{"app-", "infra-"},
want: SemVer{
Major: 1,
Minor: 2,
Patch: 3,
},
},
{
name: "With prefix but not in config - should still parse numbers",
tagName: "v2.3.4",
currentSemver: SemVer{},
prefixes: []string{}, // v not in prefixes
want: SemVer{
Major: 2,
Minor: 3,
Patch: 4,
},
},
{
name: "With release candidate",
tagName: "3.4.5-rc.2",
currentSemver: SemVer{},
prefixes: []string{},
want: SemVer{
Major: 3,
Minor: 4,
@@ -95,6 +121,31 @@ func TestParseExistingSemver(t *testing.T) {
EnableReleaseCandidate: true,
},
},
{
name: "With prefix and release candidate",
tagName: "app-1.0.0-rc.3",
currentSemver: SemVer{},
prefixes: []string{"app-"},
want: SemVer{
Major: 1,
Minor: 0,
Patch: 0,
Release: 3,
EnableReleaseCandidate: true,
},
},
{
name: "Prefixed tag without RC should NOT be RC",
tagName: "app-0.0.16",
currentSemver: SemVer{},
prefixes: []string{"app-"},
want: SemVer{
Major: 0,
Minor: 0,
Patch: 16,
EnableReleaseCandidate: false,
},
},
{
name: "Invalid format",
tagName: "not-a-semver",
@@ -103,6 +154,7 @@ func TestParseExistingSemver(t *testing.T) {
Minor: 1,
Patch: 1,
},
prefixes: []string{},
want: SemVer{
Major: 1,
Minor: 1,
@@ -117,6 +169,7 @@ func TestParseExistingSemver(t *testing.T) {
Minor: 5,
Patch: 5,
},
prefixes: []string{},
want: SemVer{
Major: 5,
Minor: 5,
@@ -127,7 +180,7 @@ func TestParseExistingSemver(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ParseExistingSemver(tt.tagName, tt.currentSemver)
got := ParseExistingSemver(tt.tagName, tt.currentSemver, tt.prefixes)
assert.Equal(t, tt.want.Major, got.Major, "Major version mismatch")
assert.Equal(t, tt.want.Minor, got.Minor, "Minor version mismatch")
assert.Equal(t, tt.want.Patch, got.Patch, "Patch version mismatch")
@@ -136,6 +189,34 @@ func TestParseExistingSemver(t *testing.T) {
})
}
}
func TestIsParseableSemverTag(t *testing.T) {
InitLogger(false)
tests := []struct {
name string
tag string
prefixes []string
want bool
}{
{name: "plain x.y.z", tag: "1.2.3", want: true},
{name: "v prefix", tag: "v1.16.5", want: true},
{name: "v prefix with rc", tag: "v2.0.0-rc.3", want: true},
{name: "configured app- prefix", tag: "app-1.2.3", prefixes: []string{"app-"}, want: true},
{name: "rolling v1 tag", tag: "v1", want: false},
{name: "rolling latest tag", tag: "latest", want: false},
{name: "two-component", tag: "1.2", want: false},
{name: "empty", tag: "", want: false},
{name: "non-numeric major", tag: "vX.Y.Z", want: false},
{name: "just text", tag: "release-day", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, IsParseableSemverTag(tt.tag, tt.prefixes))
})
}
}
func TestCheckMatches(t *testing.T) {
// Initialize logger for tests
@@ -196,4 +277,4 @@ func TestCheckMatches(t *testing.T) {
assert.Equal(t, tt.want, got)
})
}
}
}
+1 -8
View File
@@ -1,17 +1,10 @@
version: 1
force:
major: 1
minor: 4
existing: true
strict: false
commit: 960207e4677476ad31a9f389f74eaf9f33d49613
wording:
patch:
- update
- initial
- fix
minor:
- change
- improve
major:
- breaking
- breaking
+4
View File
@@ -8,6 +8,10 @@ blacklist:
- "Merge pull request"
- "feature/"
- "feature:"
tag_prefixes:
# Note: "v" prefix is stripped automatically, no need to include it here
- "app-"
- "infra-"
wording:
patch:
- update
+17 -19
View File
@@ -1,13 +1,12 @@
module github.com/lukaszraczylo/semver-generator
go 1.24.0
toolchain go1.24.6
go 1.25.0
require (
github.com/go-git/go-git/v5 v5.16.4
github.com/go-git/go-git/v5 v5.19.1
github.com/lithammer/fuzzysearch v1.1.8
github.com/lukaszraczylo/graphql-monitoring-proxy v0.41.20
github.com/lukaszraczylo/graphql-monitoring-proxy v0.45.1
github.com/lukaszraczylo/oss-telemetry v0.2.1
github.com/lukaszraczylo/pandati v0.0.29
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
@@ -17,25 +16,25 @@ require (
require (
dario.cat/mergo v1.0.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/ProtonMail/go-crypto v1.4.1 // indirect
github.com/cloudflare/circl v1.6.3 // indirect
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fsnotify/fsnotify v1.10.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.7.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/go-git/go-billy/v5 v5.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.4.0 // indirect
github.com/kevinburke/ssh_config v1.6.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pjbgf/sha1cd v0.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.3.1 // indirect
github.com/pjbgf/sha1cd v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
@@ -52,11 +51,10 @@ require (
github.com/wI2L/jsondiff v0.6.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/crypto v0.51.0 // indirect
golang.org/x/net v0.54.0 // indirect
golang.org/x/sys v0.44.0 // indirect
golang.org/x/text v0.37.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+36 -34
View File
@@ -3,16 +3,16 @@ dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM=
github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE=
@@ -27,22 +27,22 @@ github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
github.com/go-git/go-billy/v5 v5.7.0 h1:83lBUJhGWhYp0ngzCMSgllhUSuoHP1iEWYjsPl9nwqM=
github.com/go-git/go-billy/v5 v5.7.0/go.mod h1:/1IUejTKH8xipsAcdfcSAlUlo2J7lkYV8GTKxAT/L3E=
github.com/go-git/go-billy/v5 v5.9.0 h1:jItGXszUDRtR/AlferWPTMN4j38BQ88XnXKbilmmBPA=
github.com/go-git/go-billy/v5 v5.9.0/go.mod h1:jCnQMLj9eUgGU7+ludSTYoZL/GGmii14RxKFj7ROgHw=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.16.4 h1:7ajIEZHZJULcyJebDLo99bGgS0jRrOxzZG4uCk2Yb2Y=
github.com/go-git/go-git/v5 v5.16.4/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/go-git/go-git/v5 v5.19.1 h1:nX27AnaU43/K5bKktKwgBmR9lawoYVe1Ckg0rgzzN00=
github.com/go-git/go-git/v5 v5.19.1/go.mod h1:Pb1v0c7/g8aGQJwx9Us09W85yGoyvSwuhEGMH7zjDKQ=
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
@@ -52,8 +52,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/kevinburke/ssh_config v1.4.0 h1:6xxtP5bZ2E4NF5tuQulISpTO2z8XbtH8cg1PWkxoFkQ=
github.com/kevinburke/ssh_config v1.4.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY=
github.com/kevinburke/ssh_config v1.6.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -65,8 +65,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
github.com/lukaszraczylo/graphql-monitoring-proxy v0.41.20 h1:554N+HD5cTY074Y0LrL82cYQNCG1qDV3QKULgdLovs0=
github.com/lukaszraczylo/graphql-monitoring-proxy v0.41.20/go.mod h1:1FLcH7q+7cjUgQxyeVeF7ouBamGpcJZgqDF+j+cuFxI=
github.com/lukaszraczylo/graphql-monitoring-proxy v0.45.1 h1:NBRubpm7P+Z0iOgqPFAM6HHVPnUs8Qm1BZqpJBKL81Q=
github.com/lukaszraczylo/graphql-monitoring-proxy v0.45.1/go.mod h1:oL4NfPtHhKcHUUzQpfAqMLUkQDLwkwqzAZFfyhZW3+0=
github.com/lukaszraczylo/oss-telemetry v0.2.1 h1:6ULyfzXplpdmIY/i01OPM1jeod9+L1RAhI0jtbVnJI0=
github.com/lukaszraczylo/oss-telemetry v0.2.1/go.mod h1:+Cn78qZo8rc3T9eZt0v3oICYRdd75wORtSidc8lNjDQ=
github.com/lukaszraczylo/pandati v0.0.29 h1:WUEWm1+hWjE5KJbIL8OctG00x2dk4XKGJSlrjhxZ55k=
github.com/lukaszraczylo/pandati v0.0.29/go.mod h1:+DyTWKFaXd+jIfe7GW5w2S5PyTko/RXxMyOa+Vl713A=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -78,10 +80,10 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pjbgf/sha1cd v0.5.0 h1:a+UkboSi1znleCDUNT3M5YxjOnN1fz2FhN48FlwCxs0=
github.com/pjbgf/sha1cd v0.5.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM=
github.com/pelletier/go-toml/v2 v2.3.1 h1:MYEvvGnQjeNkRF1qUuGolNtNExTDwct51yp7olPtrEc=
github.com/pelletier/go-toml/v2 v2.3.1/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pjbgf/sha1cd v0.6.0 h1:3WJ8Wz8gvDz29quX1OcEmkAlUg9diU4GxJHqs0/XiwU=
github.com/pjbgf/sha1cd v0.6.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -138,10 +140,10 @@ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM=
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -149,8 +151,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w=
golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -167,21 +169,21 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
+9 -1
View File
@@ -15,13 +15,21 @@ limitations under the License.
*/
package main
import "github.com/lukaszraczylo/semver-generator/cmd"
import (
"time"
telemetry "github.com/lukaszraczylo/oss-telemetry"
"github.com/lukaszraczylo/semver-generator/cmd"
)
var (
PKG_VERSION string
)
func main() {
telemetry.SendForModule("semver-generator", "github.com/lukaszraczylo/semver-generator", PKG_VERSION)
defer telemetry.Wait(2 * time.Second)
cmd.PKG_VERSION = PKG_VERSION
cmd.Execute()
}
+1 -1
View File
@@ -30,4 +30,4 @@ func TestMain(t *testing.T) {
// Verify that the version was set correctly
assert.Equal(t, "test-version", cmd.PKG_VERSION, "PKG_VERSION should be set correctly")
}
}