-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
# This workflow run pre-commit and amend version and commit info | ||
# Before merging into master | ||
|
||
name: Check Merge | ||
|
||
on: | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
check-merge: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 20 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Run Git Hooks | ||
run: | | ||
set -x | ||
echo 'before' | ||
cat cmd/xgo/version.go | ||
go run ./script/git-hooks pre-commit --amend --no-commit | ||
git status | ||
echo 'after' | ||
cat cmd/xgo/version.go | ||
- name: Check If Git Hooks Generate No New Files | ||
run: | | ||
if ! git diff --quiet;then | ||
echo "diff found after run 'go run ./script/git-hooks pre-commit --no-commit', ensure run git hooks before you commit" >&2 | ||
exit 1 | ||
fi | ||
- name: Check If Can Merge Into Master Without Intermediate Commit | ||
run: go run ./script/github-actions check-merge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Go Windows | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
tests: | ||
strategy: | ||
matrix: | ||
os: [ windows-latest ] | ||
go: [ '1.20' ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '${{ matrix.go }}' | ||
|
||
- name: Test | ||
run: go run ./script/run-test --reset-instrument --debug -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/xhd2015/xgo/script/build-release/revision" | ||
"github.com/xhd2015/xgo/support/git" | ||
) | ||
|
||
func main() { | ||
err := handle(os.Args[1:]) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "%v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func handle(args []string) error { | ||
if len(args) == 0 { | ||
return fmt.Errorf("requires cmd") | ||
} | ||
cmd := args[0] | ||
args = args[1:] | ||
|
||
if cmd == "check-merge" { | ||
return checkMerge(args) | ||
} else { | ||
return fmt.Errorf("unrecognized command: %s", cmd) | ||
} | ||
} | ||
|
||
// check if merge to master | ||
// will not result in merge commit | ||
func checkMerge(args []string) error { | ||
gitDir, err := git.ShowTopLevel("") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = git.FetchRef(gitDir, "origin", "master") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
masterCommitHash, err := revision.GetCommitHash(gitDir, "origin/master") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var found bool | ||
n := 20 | ||
for i := 0; i < n; i++ { | ||
ref := "HEAD" | ||
if i > 0 { | ||
ref = fmt.Sprintf("HEAD~%d", i) | ||
} | ||
commitHash, err := revision.GetCommitHash(gitDir, ref) | ||
if err != nil { | ||
return err | ||
} | ||
if commitHash == masterCommitHash { | ||
found = true | ||
break | ||
} | ||
} | ||
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 nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters