Skip to content

Commit

Permalink
document and simplify (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh authored May 25, 2024
1 parent a3a0b94 commit 9e1c74b
Show file tree
Hide file tree
Showing 23 changed files with 614 additions and 782 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
trim_multiple_empty_lines = true


[*.yaml]
indent_style = space
63 changes: 15 additions & 48 deletions .github/workflows/simver.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,15 @@
{
name: simver,
concurrency: { group: simver, cancel-in-progress: false },
permissions: { id-token: write, contents: write, pull-requests: read },
on:
{
workflow_dispatch: null,
workflow_call: {},
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.22.0",
},
{
name: run simver,
id: simver,
env:
{
SIMVER_READ_ONLY: false,
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}",
},
run: simver_github_actions,
},
],
},
},
}
name: simver
permissions: { id-token: write, contents: write, pull-requests: read }
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
simver:
runs-on: ubuntu-latest
steps:
- uses: walteh/simver/cmd/gha-simver@a9f89e2fb17b03b3150c2aed050a68bc85280f02
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 13 additions & 0 deletions .github/workflows/wait-on-simver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: wait-on-simver
permissions: { id-token: write, contents: write, pull-requests: read }
on:
workflow_dispatch:
push:
branches: ["*"]
jobs:
wait-on-simver:
runs-on: ubuntu-latest
steps:
- uses: walteh/simver/cmd/gha-wait-on-simver@a9f89e2fb17b03b3150c2aed050a68bc85280f02
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .vscode/simver.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
"[dockerfile]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"yaml.schemas": {
"https://json.schemastore.org/github-action.json": "file:///Users/dub6ix/Developer/walteh/github/simver/actions/simver.yaml"
},
}
}
140 changes: 55 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,79 @@
# simver
simple, pr based, semver git tagging logic
# SimVer - Semantic Versioning Simplified 🔄

## 🌟 Overview

# definitions
Forget about the headache of manual versioning. SimVer is here to automate and simplify semantic versioning in your Git workflow. By managing version tags directly linked to your commit activities, SimVer ensures a linear, predictable version history with zero manual overhead. Perfect for teams and developers looking for a set-it-and-forget-it solution, SimVer streamlines your development process, allowing you to focus on what truly matters - building great software.

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

SimVer is the go-to solution for developers and teams who:

## when is mmrt valid?
1. it exists
2. it is higher than the mrlt
- Are exhausted by manual versioning complexities.
- Desire a consistent, traceable version history.
- Need seamless integration with CI/CD tools like GitHub Actions.

## ✨ Features

## the most recent reserved tag (mrrt)
- **Automated Version Tags:** Automatically generates semantic version tags for all commits and pull requests.
- **Clear Versioning Rules:** Simplifies decision-making with straightforward rules for main and side branches.
- **Linear History Dependence:** Ensures all version increments are predictable and orderly.

inside this commits tree, the highest 'vX.Y.Z-reserved' tag is the mrrt.
## 📘 How It Works

### Versioning Logic Simplified

## the most recent live tag (mrlt)
- **Direct Pushes to Main:** Trigger minor version updates automatically.
- **Pull Requests:**
- To Main: Trigger minor updates.
- To Side Branches: Apply patch updates.
- Multiple Concurrent PRs: Ensure unique, sequential versioning without conflicts.
- **Merging:** Versions merge seamlessly, with the target branch adopting the version from the merged branch or PR.

inside this commits tree, the highest 'vX.Y.Z' tag is the mrlt.
### Tagging Made Easy

## the my most recent tag (mmrt)
- **Main Branch:** Receives clean, full release versions.
- **Side Branches and PRs:** Get detailed pre-release tags to avoid confusion and maintain clarity.

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

## next valid tag (nvt)
- Direct push to `main` changes `v1.0.0` to `v1.1.0`.
- A PR to `main` updates from `v1.0.0` to `v1.1.0`.
- A PR to a side branch updates from `v1.1.0` to `v1.1.1`.
- Handling multiple PRs ensures sequential updates without overlap.

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

## the my most recent build number (mmrbn)
### Usage

inside this commits tree, the highest '*-pr.N+(this)' is the mmrbn.
Easily integrate SimVer into your GitHub Actions with this setup:

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"
```yaml
name: simver
permissions: { id-token: write, contents: write, pull-requests: read }
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
simver:
runs-on: ubuntu-latest
steps:
- uses: walteh/simver/cmd/gha-simver@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
------------
## ⚠️ Current Limitations & 🛠 Future Fixes
two bugs:
- need to make sure merges do not have build numbers
- need to make sure that build nums are picked up
- **Junk Tags Cleanup:** Upcoming feature to clear temporary tags automatically.
- **Force Push Handling:** We're improving how version recalculations handle force pushes to maintain accurate histories.
# 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
## 🤝 Contributing
Contributions are welcome! Fork, modify, and submit a pull request.
# 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
5. 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
5. 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
## 📜 License
Distributed under the MIT License. See `LICENSE` for more information.
20 changes: 7 additions & 13 deletions calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ type Calculation struct {
MyMostRecentTag MMRT
MostRecentLiveTag MRLT
MyMostRecentBuild MMRBN
LastSymbolicTag LST
PR int
NextValidTag NVT
IsMerge bool
IsMerged bool
ForcePatch bool
Skip bool
IsDirty bool
}

type CalculationOutput struct {
Expand Down Expand Up @@ -65,9 +63,7 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp
}

if me.Skip {
zerolog.Ctx(ctx).Debug().
Any("calculation", me).
Msg("Skipping calculation")
zerolog.Ctx(ctx).Debug().Any("calculation", me).Msg("Skipping calculation")
return out
}

Expand Down Expand Up @@ -95,9 +91,7 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp
if mmrt != "" && semver.Compare(mmrt, mrlt) == 0 && me.MyMostRecentBuild != 0 {
validMmrt = false
nvt = BumpPatch(mmrt)
}

if !me.IsMerge {
} else if !me.IsMerged {
if me.MyMostRecentBuild == 0 {
validMmrt = false
} else if me.ForcePatch {
Expand All @@ -109,14 +103,14 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp
// if mmrt is invalid, then we need to reserve a new mmrt (which is the same as nvt)
if !validMmrt {
mmrt = nvt
// pr will be 0 if this is not a and is a push to the root branch
if me.PR != 0 && !me.IsMerge {
// pr will be 0 if this is not merged and is a push to the root branch
if me.PR != 0 && !me.IsMerged {
out.RootTags = append(out.RootTags, mmrt+"-reserved")
out.BaseTags = append(out.BaseTags, mmrt+fmt.Sprintf("-pr%d+base", me.PR))
}
}

if me.IsMerge {
if me.IsMerged {
// if !matching {
out.MergeTags = append(out.MergeTags, mmrt)
// }
Expand All @@ -135,7 +129,7 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp
Str("mrlt", mrlt).
Str("nvt", nvt).
Str("pr", fmt.Sprintf("%d", me.PR)).
Bool("isMerge", me.IsMerge).
Bool("isMerge", me.IsMerged).
Bool("forcePatch", me.ForcePatch).
Msg("CalculateNewTagsRaw")

Expand Down
Loading

0 comments on commit 9e1c74b

Please sign in to comment.