Skip to content

Commit

Permalink
update merge checker to limit exactly 1 commit to be merged
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed May 19, 2024
1 parent 0a25bf2 commit 25a36d5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.35"
const REVISION = "d3b65d5d532f17ee01275785d7872692f3a7b76a+1"
const NUMBER = 221
const REVISION = "0a25bf226a233cd13ddadb1bbd98f9066a46f39e+1"
const NUMBER = 222

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.35"
const REVISION = "d3b65d5d532f17ee01275785d7872692f3a7b76a+1"
const NUMBER = 221
const REVISION = "0a25bf226a233cd13ddadb1bbd98f9066a46f39e+1"
const NUMBER = 222

func getRevision() string {
revSuffix := ""
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.35"
const REVISION = "d3b65d5d532f17ee01275785d7872692f3a7b76a+1"
const NUMBER = 221
const REVISION = "0a25bf226a233cd13ddadb1bbd98f9066a46f39e+1"
const NUMBER = 222

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
37 changes: 29 additions & 8 deletions script/github-actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,44 @@ func handle(args []string) error {

// check if merge to master
// will not result in merge commit

// NOTE: even when your commit is already
// based on master, choosing 'Merge'
// will always generate a 'Merge Commit'.
//
// So we add an enforcement:
//
// only one commit at a time, and the version must
// match master+1.
// With this limitation, we can always use rebase
// to merge new commits without breaking the version file
func checkMerge(args []string) error {
gitDir, err := git.ShowTopLevel("")
if err != nil {
return err
}

err = git.FetchRef(gitDir, "origin", "master")
const targetBranch = "master"

err = git.FetchRef(gitDir, "origin", targetBranch)
if err != nil {
return err
}

masterCommitHash, err := revision.GetCommitHash(gitDir, "origin/"+targetBranch)
if err != nil {
return err
}

masterCommitHash, err := revision.GetCommitHash(gitDir, "origin/master")
branch, err := git.GetCurrentBranch(gitDir)
if err != nil {
return err
}

var found bool
n := 20
for i := 0; i < n; i++ {
i := 0
for ; i < n; i++ {
ref := "HEAD"
if i > 0 {
ref = fmt.Sprintf("HEAD~%d", i)
Expand All @@ -65,11 +84,13 @@ func checkMerge(args []string) error {
}
}
if !found {
branch, err := git.GetCurrentBranch(gitDir)
if err != nil {
return err
}
return fmt.Errorf("%s cannot be merged into master without creating intermediate commit", branch)
return fmt.Errorf("%s cannot be merged into %s without creating intermediate commit", branch, targetBranch)
}
if i == 0 {
return fmt.Errorf("%s is the same with %s", branch, targetBranch)
}
if i != 1 {
return fmt.Errorf("expect 1 commit to be merged, actual: %d", i)
}
return nil
}

0 comments on commit 25a36d5

Please sign in to comment.