Skip to content

Commit

Permalink
fix action and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh committed May 25, 2024
1 parent 3a4a5f9 commit 7f32fd0
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 583 deletions.
176 changes: 67 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,67 @@
# 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
1. 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
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

# SimVer - Semantic Versioning Simplified 🔄

## 🌟 Overview

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.

## 🎯 Target Audience

SimVer is the go-to solution for developers and teams who:
- Are exhausted by manual versioning complexities.
- Desire a consistent, traceable version history.
- Need seamless integration with CI/CD tools like GitHub Actions.

## ✨ Features

- **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.

## 📘 How It Works

### Versioning Logic Simplified
- **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.

### Tagging Made Easy
- **Main Branch:** Receives clean, full release versions.
- **Side Branches and PRs:** Get detailed pre-release tags to avoid confusion and maintain clarity.

### Real-world Examples
- 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.

## 🚀 Getting Started

### Usage
Easily integrate SimVer into your GitHub Actions with this setup:
___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:
uses: walteh/simver/actions/simver@v1
secrets: inherit
___

## ⚠️ Current Limitations & 🛠 Future Fixes
- **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.

## 🤝 Contributing
Contributions are welcome! Fork, modify, and submit a pull request.

## 📜 License
Distributed under the MIT License. See `LICENSE` for more information.
54 changes: 54 additions & 0 deletions actions/simver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
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,
repository: "walteh/simver",
ref: "{{ github.action_ref }}",
dir: "__simver__",
},
},
{
name: get current go version from go.mod,
id: go-version,
run: "cat go.mod | grep 'go ' | awk '{print $2}' | xargs -I {} echo \"GO_VERSION={}\" >> $GITHUB_ENV"
},
{
name: setup golang,
uses: "actions/setup-go@v4",
with: { go-version: '{{ env.GO_VERSION }}' },
},
{
name: install dependencies,
run: "cd __simver__ && go mod download",
},
{
name: install simver,
env: {
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}",
},
run: "go run ./__simver__/cmd/simver_gha --read-only=false",
},
],
},
},
}
6 changes: 2 additions & 4 deletions cmd/simver_github_actions/main.go → cmd/simver_gha/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package main

import (
"context"
"fmt"
"os"

"github.com/rs/zerolog"
"github.com/walteh/simver"
"github.com/walteh/simver/gitexec"
szl "github.com/walteh/snake/zerolog"
"github.com/walteh/terrors"
)

func main() {
Expand All @@ -29,7 +27,7 @@ func main() {
ee, _, err := simver.LoadExecutionFromPR(ctx, tagreader, prr)
if err != nil {
zerolog.Ctx(ctx).Error().Err(err).Msgf("error loading execution")
fmt.Println(terrors.FormatErrorCaller(err))
// fmt.Println(terrors.FormatErrorCaller(err))
os.Exit(1)
}

Expand All @@ -40,7 +38,7 @@ func main() {
err = tagwriter.CreateTags(ctx, tags...)
if err != nil {
zerolog.Ctx(ctx).Error().Err(err).Msgf("error creating tag: %v", err)
fmt.Println(terrors.FormatErrorCaller(err))
// fmt.Println(terrors.FormatErrorCaller(err))

os.Exit(1)
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion gitexec/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strconv"
"strings"

"github.com/go-faster/errors"
"github.com/walteh/simver"
"gitlab.com/tozd/go/errors"
)

func BuildGitHubActionsProviders() (simver.GitProvider, simver.TagReader, simver.TagWriter, simver.PRProvider, simver.PRResolver, error) {
Expand Down
2 changes: 1 addition & 1 deletion gitexec/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"os"
"os/exec"

"github.com/go-faster/errors"
"github.com/rs/zerolog"
"github.com/walteh/simver"
"gitlab.com/tozd/go/errors"
)

var _ simver.PRProvider = (*ghProvider)(nil)
Expand Down
2 changes: 1 addition & 1 deletion gitexec/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os/exec"
"strings"

"github.com/go-faster/errors"
"github.com/rs/zerolog"
"github.com/walteh/simver"
"gitlab.com/tozd/go/errors"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion gitexec/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"strings"

"github.com/go-faster/errors"
"github.com/spf13/afero"
"github.com/walteh/simver"
"gitlab.com/tozd/go/errors"
)

func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagReader, simver.TagWriter, simver.PRResolver, error) {
Expand Down
2 changes: 1 addition & 1 deletion gitexec/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strings"
"time"

"github.com/go-faster/errors"
"github.com/rs/zerolog"
"github.com/walteh/simver"
"gitlab.com/tozd/go/errors"
)

var (
Expand Down
24 changes: 13 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
module github.com/walteh/simver

go 1.21.4
go 1.22.3

require (
github.com/go-faster/errors v0.7.0
github.com/rs/zerolog v1.31.0
github.com/spf13/afero v1.10.0
github.com/stretchr/testify v1.8.4
github.com/rs/zerolog v1.33.0
github.com/spf13/afero v1.11.0
github.com/stretchr/testify v1.9.0
github.com/walteh/snake v0.25.0
github.com/walteh/terrors v0.2.6
golang.org/x/mod v0.14.0
gitlab.com/tozd/go/errors v0.8.1
golang.org/x/mod v0.17.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/k0kubun/pp/v3 v3.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.13.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/walteh/terrors v0.19.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 7f32fd0

Please sign in to comment.