simver

package module
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

simver

simple, pr based, semver git tagging logic

definitions

    # how can we make sure that a version is reserved - and if it is not reserved we need to bump it

when is mmrt valid?

  1. it exists
  2. it is higher than the mrlt

the most recent reserved tag (mrrt)

inside this commits tree, the highest 'vX.Y.Z-reserved' tag is the mrrt.

the most recent live tag (mrlt)

inside this commits tree, the highest 'vX.Y.Z' tag is the mrlt.

the my most recent tag (mmrt)

inside this commits tree, the highest 'vX.Y.Z-pr.N+base' tag is the mmrt.

next valid tag (nvt)

find the latest mrrt or mrlt and increment the patch number (or minor if the base branch is main)

the my most recent build number (mmrbn)

inside this commits tree, the highest '*-pr.N+(this)' is the mmrbn.

note each of the nvt, mrrt, mrlt, and mmrt are saved as valid semvers, so "X.Y.Z" the mmrbn is an integer, so "N"


two bugs:

  • need to make sure merges do not have build numbers
  • need to make sure that build nums are picked up

probs to test

  1. make sure that a new pr to main does a minor bump
  2. make sure that a new pr not to main does a patch bump
  3. make sure that a new commit to a pr who has been tagged with a version and was last used for it does a patch bump
  4. make sure if reserved is set, but others are not that it does not loop infinitely

process

when to run the workflow

  1. for every commit on main
  2. for every pr event
1. for each pr event:
  1. figure out if head commit is a pr merge, commit, or nothing
  • check if the current head has a semver tag
    • if it does, then it is a nothing
  • check if the commit message contains "(#N)" where N is a number and the pr exists and the head commit is the current commit
  • if it is, then it is a pr merge
  • if it is not, then it is a normal commit
1. if nothing:
  1. do nothing
2. if pr merge:
  1. find the mrrt, mrlt, and mmrt
  2. check if the mmrt is valid
  3. if it is, move forward with the mmrt
  4. if it is not, use the nvt
  • create two new tags on the base commit
    • vX.Y.Z-reserved
    • vX.Y.Z-pr.N+base
  1. create a new tag on the head commit
3. if a normal commit:
  1. find the mrrt and mrlt, calculate the nvt
  2. create a new tag (based on nvt) on the head commit
2. for each commit on main:
  1. figure out if head is a pr merge or not
  • check if the commit message contains "(#N)" where N is a number and the pr exists and the head commit is the current commit
  • if it is, then it is a pr merge
  • if it is not, then it is a normal commit
1. if pr merge:
  1. find the mrrt, mrlt, and mmrt
  2. check if the mmrt is valid
  3. if it is, move forward with the mmrt
  4. if it is not, use the nvt
  • create two new tags on the base commit (for brevity) - get the base commit from the pr
    • vX.Y.Z-reserved
    • vX.Y.Z-pr.N+base
  1. create a new tag on the head commit with no build number or prerelease
2. if a normal commit:
  1. find the mrrt and mrlt, calculate the nvt
  2. create a new tag (based on nvt) on the head commit with no build number or prerelease

when you merge a pr:

  • find the mmrt or the pr branch, and we need to start using that for this branch
  • the base branch should inherit the mmrt from the pr branch
  • so we need to create:
    1. a new "base" tag for the base branch with the mmrt of the pr branch
    2. create a new build tag using the mmrt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Err = errors.New("simver.Err")
)

Functions

func BumpPatch added in v0.1.34

func BumpPatch[S ~string](arg S) S

func ExecutionAsString added in v0.13.0

func ExecutionAsString(ctx context.Context, e Execution) (string, error)

func ForcePatch added in v0.1.34

func ForcePatch(ctx context.Context, ee Execution, mmrt MMRT) bool

func LastSymbolicTag added in v0.18.0

func LastSymbolicTag(ctx context.Context, ex Execution, mmrt MMRT, bn MMRBN) string

func LoadExecutionFromPR added in v0.18.0

func LoadExecutionFromPR(ctx context.Context, tprov TagReader, prr PRResolver) (Execution, *PRDetails, error)

func Max added in v0.1.43

func Max[A ~string, B ~string](a A, b B) string

func Skip added in v0.5.0

func Skip(ctx context.Context, ee Execution, mmrt MMRT) bool

Types

type ActivePRProjectState added in v0.18.0

type ActivePRProjectState struct {
	CurrentPR             *PRDetails
	CurrentRootBranchTags Tags
	CurrentRootCommitTags Tags
	CurrentHeadCommitTags Tags
	CurrentBaseCommitTags Tags
	CurrentBaseBranchTags Tags
	CurrentHeadBranchTags Tags
}

func (*ActivePRProjectState) BaseBranchTags added in v0.18.0

func (e *ActivePRProjectState) BaseBranchTags() Tags

func (*ActivePRProjectState) HeadBranchTags added in v0.18.0

func (e *ActivePRProjectState) HeadBranchTags() Tags

func (*ActivePRProjectState) HeadCommitTags added in v0.18.0

func (e *ActivePRProjectState) HeadCommitTags() Tags

func (*ActivePRProjectState) IsDirty added in v0.18.0

func (e *ActivePRProjectState) IsDirty() bool

func (*ActivePRProjectState) IsLocal added in v0.18.0

func (e *ActivePRProjectState) IsLocal() bool

func (*ActivePRProjectState) IsMerge added in v0.18.0

func (e *ActivePRProjectState) IsMerge() bool

func (*ActivePRProjectState) IsTargetingRoot added in v0.18.0

func (e *ActivePRProjectState) IsTargetingRoot() bool

func (*ActivePRProjectState) PR added in v0.18.0

func (e *ActivePRProjectState) PR() int

func (*ActivePRProjectState) ProvideRefs added in v0.18.0

func (e *ActivePRProjectState) ProvideRefs() RefProvider

func (*ActivePRProjectState) RootBranch added in v0.18.0

func (e *ActivePRProjectState) RootBranch() string

func (*ActivePRProjectState) RootBranchTags added in v0.18.0

func (e *ActivePRProjectState) RootBranchTags() Tags

type BasicRefProvider added in v0.1.40

type BasicRefProvider struct {
	HeadRef  string
	BaseRef  string
	RootRef  string
	MergeRef string
}

func (*BasicRefProvider) Base added in v0.1.40

func (e *BasicRefProvider) Base() string

func (*BasicRefProvider) Head added in v0.1.40

func (e *BasicRefProvider) Head() string

func (*BasicRefProvider) Merge added in v0.1.40

func (e *BasicRefProvider) Merge() string

func (*BasicRefProvider) Root added in v0.1.40

func (e *BasicRefProvider) Root() string

type Calculation

type Calculation struct {
	MyMostRecentTag   MMRT
	MostRecentLiveTag MRLT
	MyMostRecentBuild MMRBN
	LastSymbolicTag   LST
	PR                int
	NextValidTag      NVT
	IsMerge           bool
	ForcePatch        bool
	Skip              bool
	IsDirty           bool
}

func Calculate added in v0.1.34

func Calculate(ctx context.Context, ex Execution) *Calculation

func (*Calculation) CalculateNewTagsRaw

func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutput

type CalculationOutput added in v0.1.31

type CalculationOutput struct {
	BaseTags  []string
	HeadTags  []string
	RootTags  []string
	MergeTags []string
}

func (*CalculationOutput) ApplyRefs added in v0.1.31

func (out *CalculationOutput) ApplyRefs(opts RefProvider) Tags

func (*CalculationOutput) CurrentBuildTag added in v0.20.0

func (me *CalculationOutput) CurrentBuildTag(opts RefProvider) (string, string)

type Execution

type Execution interface {
	PR() int
	IsTargetingRoot() bool
	IsMerge() bool
	HeadCommitTags() Tags
	HeadBranchTags() Tags
	BaseBranchTags() Tags
	RootBranchTags() Tags
	ProvideRefs() RefProvider
	IsDirty() bool
	IsLocal() bool
}

func NewLocalProjectState added in v0.18.0

func NewLocalProjectState(ctx context.Context, gp GitProvider, tr TagReader) (Execution, error)

type GitProvider

type GitProvider interface {
	GetHeadRef(ctx context.Context) (string, error)
	CommitFromRef(ctx context.Context, ref string) (string, error)
	Branch(ctx context.Context) (string, error)
	RepoName(ctx context.Context) (string, string, error)
	Dirty(ctx context.Context) (bool, error)
}

type LST added in v0.18.0

type LST string // assumed last full decorated tag

type LocalProjectState added in v0.18.0

type LocalProjectState struct {
	Commit string
	Branch string
	Tags   Tags
	Dirty  bool
}

func (*LocalProjectState) BaseBranchTags added in v0.18.0

func (me *LocalProjectState) BaseBranchTags() Tags

BaseBranchTags implements Execution.

func (*LocalProjectState) HeadBranchTags added in v0.18.0

func (me *LocalProjectState) HeadBranchTags() Tags

HeadBranchTags implements Execution.

func (*LocalProjectState) HeadCommitTags added in v0.18.0

func (*LocalProjectState) HeadCommitTags() Tags

HeadCommitTags implements Execution.

func (*LocalProjectState) IsDirty added in v0.18.0

func (me *LocalProjectState) IsDirty() bool

func (*LocalProjectState) IsLocal added in v0.18.0

func (me *LocalProjectState) IsLocal() bool

func (*LocalProjectState) IsMerge added in v0.18.0

func (*LocalProjectState) IsMerge() bool

IsMerge implements Execution.

func (*LocalProjectState) IsTargetingRoot added in v0.18.0

func (me *LocalProjectState) IsTargetingRoot() bool

IsTargetingRoot implements Execution.

func (*LocalProjectState) PR added in v0.18.0

func (*LocalProjectState) PR() int

PR implements Execution.

func (*LocalProjectState) ProvideRefs added in v0.18.0

func (me *LocalProjectState) ProvideRefs() RefProvider

ProvideRefs implements Execution.

func (*LocalProjectState) RootBranchTags added in v0.18.0

func (*LocalProjectState) RootBranchTags() Tags

RootBranchTags implements Execution.

type MAXLR added in v0.1.43

type MAXLR string // max live or reserved tag

func MaxLiveOrReservedTag added in v0.1.43

func MaxLiveOrReservedTag(mrlt MRLT, mrrt MRRT) MAXLR

type MAXMR added in v0.1.43

type MAXMR string // max my reserved tag

func MaxMyOrReservedTag added in v0.1.43

func MaxMyOrReservedTag(mrrt MRRT, mmrt MMRT) MAXMR

type MMRBN

type MMRBN int // my most recent build number

func MyMostRecentBuildNumber

func MyMostRecentBuildNumber(e Execution) MMRBN

type MMRT

type MMRT string // my most recent tag

func MyMostRecentTag

func MyMostRecentTag(e Execution) MMRT

type MRLT

type MRLT string // most recent live tag

func MostRecentLiveTag

func MostRecentLiveTag(e Execution) MRLT

type MRRT

type MRRT string // most recent reserved tag

func MostRecentReservedTag

func MostRecentReservedTag(e Execution) MRRT

type MRT added in v0.1.31

type MRT string // my reserved tag

type NVT

type NVT string // next valid tag

func GetNextValidTag

func GetNextValidTag(ctx context.Context, minor bool, maxt MAXLR) NVT

type PRDetails

type PRDetails struct {
	Number               int
	HeadBranch           string
	BaseBranch           string
	RootBranch           string // always main
	Merged               bool
	MergeCommit          string
	HeadCommit           string
	PotentialMergeCommit string

	BaseCommit string
	RootCommit string
}

func NewPushSimulatedPRDetails added in v0.1.45

func NewPushSimulatedPRDetails(parentCommit, headCommit, branch string) *PRDetails

func (*PRDetails) Base added in v0.18.0

func (me *PRDetails) Base() string

Base implements RefProvider.

func (*PRDetails) Head added in v0.18.0

func (me *PRDetails) Head() string

Head implements RefProvider.

func (*PRDetails) IsSimulatedPush added in v0.1.45

func (dets *PRDetails) IsSimulatedPush() bool

func (*PRDetails) Merge added in v0.18.0

func (me *PRDetails) Merge() string

Merge implements RefProvider.

func (*PRDetails) Root added in v0.18.0

func (me *PRDetails) Root() string

Root implements RefProvider.

type PRProvider

type PRProvider interface {
	PRDetailsByPRNumber(ctx context.Context, prNumber int) (*PRDetails, bool, error)
	PRDetailsByCommit(ctx context.Context, commit string) (*PRDetails, bool, error)
	PRDetailsByBranch(ctx context.Context, branch string) (*PRDetails, bool, error)
}

type PRResolver added in v0.1.12

type PRResolver interface {
	CurrentPR(ctx context.Context) (*PRDetails, error)
}

type RefProvider added in v0.1.40

type RefProvider interface {
	Head() string
	Base() string
	Root() string
	Merge() string
}

type SingleRefProvider added in v0.18.0

type SingleRefProvider struct {
	Ref string
}

func (*SingleRefProvider) Base added in v0.18.0

func (e *SingleRefProvider) Base() string

func (*SingleRefProvider) Head added in v0.18.0

func (e *SingleRefProvider) Head() string

func (*SingleRefProvider) Merge added in v0.18.0

func (e *SingleRefProvider) Merge() string

func (*SingleRefProvider) Root added in v0.18.0

func (e *SingleRefProvider) Root() string

type Tag added in v0.1.34

type Tag struct {
	Name string
	Ref  string
}

type TagReader added in v0.17.0

type TagReader interface {
	TagsFromCommit(ctx context.Context, commitHash string) (Tags, error)
	TagsFromBranch(ctx context.Context, branch string) (Tags, error)
}

type TagWriter added in v0.8.0

type TagWriter interface {
	CreateTags(ctx context.Context, tag ...Tag) error
	FetchTags(ctx context.Context) (Tags, error)
}

type Tags

type Tags []Tag

func (Tags) ExtractCommitRefs added in v0.1.40

func (t Tags) ExtractCommitRefs() Tags

func (Tags) GetReserved

func (t Tags) GetReserved() (Tag, bool)

func (Tags) MappedByName added in v0.1.40

func (t Tags) MappedByName() map[string]string

func (Tags) MarshalZerologArray added in v0.1.44

func (t Tags) MarshalZerologArray(a *zerolog.Array)

MarshalZerologArray implements zerolog.LogArrayMarshaler.

func (Tags) Names added in v0.1.40

func (t Tags) Names() []string

func (Tags) SemversMatching added in v0.1.31

func (t Tags) SemversMatching(matcher func(string) bool) []string

func (Tags) Sort added in v0.1.44

func (t Tags) Sort() Tags

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL