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

base version after testing #1

Merged
merged 38 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5eb1b35
rollin
walteh Nov 14, 2023
9a6ed7a
adjust branch tags
walteh Nov 14, 2023
1fe58b9
rollin
walteh Nov 14, 2023
5df8632
get ready for simple merge
walteh Nov 14, 2023
7eaa3f9
role
walteh Nov 14, 2023
aaf7e74
logic
walteh Nov 14, 2023
aa0413a
hold up
walteh Nov 14, 2023
f866d7d
check it
walteh Nov 14, 2023
e22c5c4
bump it up
walteh Nov 14, 2023
115d0bc
save
walteh Nov 14, 2023
87e59f7
3
walteh Nov 14, 2023
09c697c
basic root logic
walteh Nov 14, 2023
9f8bc51
some more refactoring
walteh Nov 14, 2023
a989d42
refactor for simpler testing
walteh Nov 14, 2023
c5845b1
refactor for better regex
walteh Nov 14, 2023
782515f
merge logic working
walteh Nov 15, 2023
01105a4
make sure main is set
walteh Nov 15, 2023
aec592a
merge commit fix
walteh Nov 15, 2023
b0c2e46
renaming for clarity
walteh Nov 15, 2023
faf4baf
force patch
walteh Nov 15, 2023
2c22550
fix build number bug
walteh Nov 15, 2023
d274cdf
try assuming deletion
walteh Nov 15, 2023
f69c03d
fix base problem
walteh Nov 15, 2023
b346e2b
fix accidental minor bump
walteh Nov 15, 2023
fc9096d
add context to calculation for logging
walteh Nov 16, 2023
c1218ab
refactor for logical fixes
walteh Nov 16, 2023
f6554b5
test 123
walteh Nov 16, 2023
b26d2e3
fixed now
walteh Nov 16, 2023
e3205de
might work now
walteh Nov 16, 2023
87a5439
better logging
walteh Nov 16, 2023
95ab205
even better logging
walteh Nov 16, 2023
5daa437
bug fix on the commit to main
walteh Nov 16, 2023
63ca526
idk if this is it
walteh Nov 16, 2023
909ef3a
bulk create tags
walteh Nov 16, 2023
0a024b3
fix the mmrt max bug
walteh Nov 16, 2023
678b6f2
bre build download
walteh Nov 18, 2023
bd1bb74
adjust workflow
walteh Nov 18, 2023
e5cfc34
set v0.2.0 as default
walteh Nov 18, 2023
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
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/[email protected]",
},
{
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