Skip to content

Commit

Permalink
base version after testing (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh authored Nov 18, 2023
2 parents 6bfd073 + e5cfc34 commit c0c4b7e
Show file tree
Hide file tree
Showing 17 changed files with 1,333 additions and 640 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/simver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
name: simver,
concurrency: { group: simver, cancel-in-progress: false },
permissions: { id-token: write, contents: write, pull-requests: read },
on:
{
workflow_dispatch: null,
workflow_call: null,
push: { branches: [main] },
pull_request: { types: [opened, synchronize, reopened, closed] },
},
defaults: { run: { shell: bash } },
jobs:
{
simver:
{
runs-on: ubuntu-latest,

steps:
[
{
name: checkout code,
uses: "actions/checkout@v4",
with: { fetch-depth: 0 },
},
{
name: setup golang,
uses: "actions/setup-go@v4",
with: { go-version: 1.21.4 },
},
{
name: install simver,
run: "go install github.com/walteh/simver/cmd/simver_github_actions@v0.2.0",
},
{
name: run simver,
id: simver,
env:
{
SIMVER_READ_ONLY: false,
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}",
},
run: simver_github_actions,
},
],
},
},
}
23 changes: 12 additions & 11 deletions .vscode/simver.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
VSCODE
////////////////////////////////////////////// */
"workbench.tree.indent": 16,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"search.useIgnoreFiles": true,
"debug.console.wordWrap": false,
Expand All @@ -25,17 +26,17 @@
/* //////////////////////////////////////////////
YAML
////////////////////////////////////////////// */
"yaml.format.enable": true,
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml",
"editor.bracketPairColorization.enabled": true,
"editor.formatOnSave": true,
},
"yaml.style.flowSequence": "allow",
"yaml.style.flowMapping": "allow",
"yaml.format.proseWrap": "preserve",
"yaml.format.singleQuote": false,
"yaml.extension.recommendations": true,
// "yaml.format.enable": true,
// "[yaml]": {
// "editor.defaultFormatter": "esbenp.prettier-vscode",
// "editor.bracketPairColorization.enabled": true,
// "editor.formatOnSave": true,
// },
// "yaml.style.flowSequence": "allow",
// "yaml.style.flowMapping": "allow",
// "yaml.format.proseWrap": "preserve",
// "yaml.format.singleQuote": false,
// "yaml.extension.recommendations": true,
/* //////////////////////////////////////////////
DOCKER
////////////////////////////////////////////// */
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ simple, pr based, semver git tagging logic

# definitions

## when is mmrt valid?
# 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

Expand Down Expand Up @@ -33,7 +36,18 @@ 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
1. make sure if reserved is set, but others are not that it does not loop infinitely


# process

Expand Down Expand Up @@ -86,3 +100,10 @@ the mmrbn is an integer, so "N"
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

87 changes: 73 additions & 14 deletions calculate.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@
package simver

import (
"context"
"fmt"

"github.com/rs/zerolog"
"github.com/walteh/terrors"
"golang.org/x/mod/semver"
)

type Calculation struct {
MyMostRecentTag MMRT
MostRecentLiveTag MRLT
MyMostRecentBuild MMRBN
MostRecentReservedTag MRRT
PR int
NextValidTag NVT
MyMostRecentTag MMRT
MostRecentLiveTag MRLT
MyMostRecentBuild MMRBN
PR int
NextValidTag NVT
IsMerge bool
ForcePatch bool
}

var (
ErrValidatingCalculation = terrors.New("ErrValidatingCalculation")
)

func (me *Calculation) CalculateNewTagsRaw() ([]string, []string) {
baseTags := make([]string, 0)
headTags := make([]string, 0)
type CalculationOutput struct {
BaseTags []string
HeadTags []string
RootTags []string
MergeTags []string
}

func (out *CalculationOutput) ApplyRefs(opts RefProvider) Tags {
tags := make(Tags, 0)
for _, tag := range out.BaseTags {
tags = append(tags, Tag{Name: tag, Ref: opts.Base()})
}

for _, tag := range out.HeadTags {
tags = append(tags, Tag{Name: tag, Ref: opts.Head()})
}
for _, tag := range out.RootTags {
tags = append(tags, Tag{Name: tag, Ref: opts.Root()})
}
for _, tag := range out.MergeTags {
tags = append(tags, Tag{Name: tag, Ref: opts.Merge()})
}
return tags
}

func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutput {
out := &CalculationOutput{
BaseTags: []string{},
HeadTags: []string{},
RootTags: []string{},
MergeTags: []string{},
}

nvt := string(me.NextValidTag)

Expand All @@ -42,15 +74,42 @@ func (me *Calculation) CalculateNewTagsRaw() ([]string, []string) {
validMmrt = true
}

// force patch is ignored if this is a merge
if me.ForcePatch && !me.IsMerge {
nvt = BumpPatch(mmrt)
validMmrt = false
}

// if mmrt is invalid, then we need to reserve a new mmrt (which is the same as nvt)
if !validMmrt {
mmrt = nvt
baseTags = append(baseTags, nvt+"-reserved")
baseTags = append(baseTags, nvt+fmt.Sprintf("-pr%d+base", me.PR))
// pr will be 0 if this is not a and is a push to the root branch
if me.PR != 0 {
out.RootTags = append(out.RootTags, nvt+"-reserved")
out.BaseTags = append(out.BaseTags, nvt+fmt.Sprintf("-pr%d+base", me.PR))
}
}

if me.IsMerge {
out.MergeTags = append(out.MergeTags, mmrt)
} else {
if me.PR == 0 {
out.HeadTags = append(out.HeadTags, mmrt)
} else {
out.HeadTags = append(out.HeadTags, mmrt+fmt.Sprintf("-pr%d+%d", me.PR, int(me.MyMostRecentBuild)+1))
}
}

// then finally we tag mmrt
headTags = append(headTags, mmrt+fmt.Sprintf("-pr%d+%d", me.PR, int(me.MyMostRecentBuild)+1))
zerolog.Ctx(ctx).Debug().
Any("calculation", me).
Any("output", out).
Str("mmrt", mmrt).
Str("mrlt", mrlt).
Str("nvt", nvt).
Str("pr", fmt.Sprintf("%d", me.PR)).
Bool("isMerge", me.IsMerge).
Bool("forcePatch", me.ForcePatch).
Msg("CalculateNewTagsRaw")

return baseTags, headTags
return out
}
Loading

0 comments on commit c0c4b7e

Please sign in to comment.