Skip to content

Commit 4f0c9f9

Browse files
committed
MEDIUM: use go-git for base ref resolution, update docs
1 parent 300714f commit 4f0c9f9

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,5 @@ jobs:
1919
with:
2020
fetch-depth: 0
2121

22-
- uses: actions/checkout@v2
23-
with:
24-
ref: master
25-
26-
- name: Set up Go
27-
uses: actions/setup-go@v2
28-
with:
29-
go-version: 1.15
30-
31-
# Runs a set of commands using the runners shell
32-
- name: Run a multi-line script
33-
run: |
34-
export
35-
git show-ref
36-
git clone -b git_envs https://github.com/aiharos/github-actions.git
37-
cd github-actions/check-commit; go run check.go "../../."
22+
- name: check-commit
23+
uses: docker://aiharos/check-commit:latest

check-commit/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ steps:
5050
uses: actions/checkout@v2
5151
with:
5252
fetch-depth: 0
53-
- name: Create base branch reference
54-
uses: actions/checkout@v2
55-
with:
56-
ref: main
5753
- name: check-commit
5854
uses: docker://haproxytech/check-commit:TAG
5955
```
60-
Here we instruct `checkout@v2` action to fetch the repo history, as well as the main branch of the repo. This creates git refs in the checked-out repository so that the check-commit can do a merge-base operation against the main and the feature branch. Modify the main repo name from this example to reflect what is the main repo name in your own repository.
56+
Here we instruct `checkout@v2` action to fetch the repo history.
57+
58+
Check-commit can work on `pull_request` events by inspecting all commit messages between a merge-base commit of the the target branch (usually main, looked up from `$GITHUB_BASE_REF`) and the tip of the feature branch (`$GITHUB_REF`) branch. If the operation is a `push` only the last commit is checked.
59+
60+
For this to work, the `origin/$GITHUB_BASE_REF` ref has to be a part of the history checked out by `actions/checkout@v2`, so `fetch-depth: 0` is can be used as a safe option to fetch the complete repo history. Setting this to a fixed number will limit how many commits are allowed in a Pull Request to that many commits and will speed up the checkout for large repos.
6161

6262
## Example configuration
6363

check-commit/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func hashesFromRefs(repo *git.Repository, repoEnv *gitEnv) ([]*plumbing.Hash, []
261261
refStrings = append(refStrings, repoEnv.Ref)
262262

263263
if !(repoEnv.EnvName == GITHUB && repoEnv.Event == "push") { // for Github push we only have the last commit
264-
refStrings = append(refStrings, repoEnv.Base)
264+
refStrings = append(refStrings, fmt.Sprintf("refs/remotes/origin/%s", repoEnv.Base))
265265
}
266266

267267
hashes := make([]*plumbing.Hash, 0, 2)

0 commit comments

Comments
 (0)