Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(github): mark pre-releases correctly #110

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions internal/versioning/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,16 @@ func parseSemverWithDefault(tag *git.Tag) (semver.Version, error) {

return parsedVersion, nil
}

func (s semVer) IsPrerelease(version string) bool {
semVersion, err := parseSemverWithDefault(&git.Tag{Hash: "", Name: version})
if err != nil {
return false
}

if len(semVersion.Pre) > 0 {
return true
}

return false
}
34 changes: 34 additions & 0 deletions internal/versioning/semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,37 @@ func TestVersionBumpFromCommits(t *testing.T) {
})
}
}

func TestSemVer_IsPrerelease(t *testing.T) {
tests := []struct {
name string
version string
want bool
}{
{
name: "empty string",
version: "",
want: false,
},
{
name: "stable version",
version: "v1.0.0",
want: false,
},
{
name: "pre-release version",
version: "v1.0.0-rc.1+foo",
want: true,
},
{
name: "invalid version",
version: "ajfkdafjdsfj",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, SemVer.IsPrerelease(tt.version), "IsSemverPrerelease(%v)", tt.version)
})
}
}
1 change: 1 addition & 0 deletions internal/versioning/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type Strategy interface {
NextVersion(git.Releases, VersionBump, NextVersionType) (string, error)
IsPrerelease(version string) bool
}

type VersionBump conventionalcommits.VersionBump
Expand Down
4 changes: 2 additions & 2 deletions releaserpleaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func (rp *ReleaserPleaser) createPendingRelease(ctx context.Context, pr *release
return err
}

// TODO: pre-release & latest
// TODO: Check if version should be marked latest

logger.DebugContext(ctx, "Creating release on forge")
err = rp.forge.CreateRelease(ctx, *pr.ReleaseCommit, version, changelogText, false, true)
err = rp.forge.CreateRelease(ctx, *pr.ReleaseCommit, version, changelogText, rp.versioning.IsPrerelease(version), true)
if err != nil {
return fmt.Errorf("failed to create release on forge: %w", err)
}
Expand Down
Loading