Skip to content

Commit 24ea360

Browse files
authored
feature: No patching (#2)
1 parent b950640 commit 24ea360

33 files changed

+514
-561
lines changed

.github/PULL_REQUEST_TEMPLATE.md

-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ with an overview of the logic and implementation details when needed.
1010
## Notes
1111
Other notes that you want to share but do not fit into _Problem_ or _Solution_.
1212

13-
<!--
14-
Bumping
15-
Any commit message that includes #major, #minor, or #patch will trigger the respective version bump.
16-
If two or more are present, the highest-ranking one will take precedence.
17-
If no #major, #minor or #patch tag is contained in the commit messages, it will bump patch.
18-
-->

.github/dependabot.yml

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
version: 2
22
updates:
3-
- package-ecosystem: gomod
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "04:00"
8-
open-pull-requests-limit: 10
3+
- package-ecosystem: "gomod"
4+
open-pull-requests-limit: 10
5+
directory: "/"
6+
schedule:
7+
interval: "daily"
8+
time: "04:00"
9+
commit-message:
10+
prefix: "chore"
11+
labels:
12+
- "dependencies"
13+
- "go"
14+
- "chore"
15+
16+
- package-ecosystem: "github-actions"
17+
open-pull-requests-limit: 10
18+
directory: "/"
19+
schedule:
20+
interval: "daily"
21+
time: "04:00"
22+
commit-message:
23+
prefix: "chore"
24+
labels:
25+
- "dependencies"
26+
- "github_actions"
27+
- "chore"
28+

.github/labeler.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
labels:
2+
'feature':
3+
- '^(?i:feat)'
4+
- '^(?i:feature)'
5+
'fix':
6+
- '^(?i:fix)'
7+
'chore':
8+
- '^(?i:chore)'

.github/release-drafter.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
categories:
4+
- title: '🚀 Features'
5+
label: 'feature'
6+
- title: '🐛 Bug Fixes'
7+
label: 'fix'
8+
- title: '🧰 Maintenance'
9+
label: 'chore'
10+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
11+
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
12+
version-resolver:
13+
major:
14+
labels:
15+
- 'major'
16+
minor:
17+
labels:
18+
- 'minor'
19+
patch:
20+
labels:
21+
- 'patch'
22+
default: patch
23+
autolabeler:
24+
- label: 'feature'
25+
title:
26+
- '/^feat/i'
27+
- '/^feature/i'
28+
- label: 'fix'
29+
title:
30+
- '/^fix/i'
31+
- label: 'chore'
32+
title:
33+
- '/^chore/i'
34+
template: |
35+
## Changes
36+
37+
$CHANGES
38+

.github/workflows/ci.yml

-66
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# this workflow will run on all pull requests opened but in the context of the base of the pull request.
2+
on:
3+
pull_request_target:
4+
types: [opened]
5+
6+
name: "pull_request_target_opened"
7+
jobs:
8+
# labeler will label pull requests based on their title.
9+
# the configuration is at .github/labeler.yml.
10+
label_pull_request:
11+
runs-on: ubuntu-latest
12+
steps:
13+
-
14+
name: Label Pull Request
15+
uses: jimschubert/labeler-action@v2
16+
with:
17+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/push.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# this workflow will run on all pushes.
2+
on:
3+
push:
4+
5+
name: "push"
6+
jobs:
7+
# run golangci-lint to lint the golang source code.
8+
# the configuration is at /.golangci.yml.
9+
linter:
10+
runs-on: ubuntu-latest
11+
steps:
12+
-
13+
uses: actions/[email protected]
14+
-
15+
name: lint
16+
uses: golangci/[email protected]
17+
with:
18+
version: latest
19+
# optional: show only new issues if it's a pull request. The default value is `false`.
20+
# only-new-issues: true
21+
22+
# use nancy to scan for vulnerabilities.
23+
vulnerability_scanner:
24+
name: Vulnerability scanner
25+
runs-on: ubuntu-latest
26+
steps:
27+
-
28+
uses: actions/[email protected]
29+
-
30+
uses: actions/setup-go@v2
31+
# we cannot use nancy-github-action because it is outdated, so it's better to use the latest
32+
# docker image for the validation
33+
-
34+
name: nancy
35+
run: go list -json -m all | docker run -i sonatypecommunity/nancy:latest
36+
37+
# run golang test suite and collect their coverage.
38+
test:
39+
strategy:
40+
matrix:
41+
platform: [ ubuntu-latest, macos-latest, windows-latest ]
42+
runs-on: ${{ matrix.platform }}
43+
steps:
44+
- name: Checkout code
45+
uses: actions/[email protected]
46+
- name: Get go.mod details
47+
48+
id: go-mod-details
49+
- name: Install Go
50+
uses: actions/setup-go@v1
51+
with:
52+
go-version: ${{ steps.go-mod-details.outputs.go_version }}
53+
- name: Test
54+
env:
55+
COVERAGE_PREFIX: coverage-${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-
56+
run: go test -v -count=1
57+
- name: Send coverage (Bucket 1)
58+
uses: shogo82148/[email protected]
59+
with:
60+
path-to-profile: coverage-${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-bucket0.cov
61+
flag-name: ${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-bucket1
62+
parallel: true
63+
- name: Send coverage (Bucket 2)
64+
uses: shogo82148/[email protected]
65+
with:
66+
path-to-profile: coverage-${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-bucket1.cov
67+
flag-name: ${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-bucket2
68+
parallel: true
69+
- name: Send coverage (Exclude Package)
70+
uses: shogo82148/[email protected]
71+
with:
72+
path-to-profile: coverage-${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-exclude-package.cov
73+
flag-name: ${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-exclude-package
74+
parallel: true
75+
- name: Send coverage (Exclude Directory)
76+
uses: shogo82148/[email protected]
77+
with:
78+
path-to-profile: coverage-${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-exclude-directory.cov
79+
flag-name: ${{ matrix.platform }}-${{ steps.go-mod-details.outputs.go_version }}-exclude-directory
80+
parallel: true
81+
82+
# notifies that all test jobs are finished.
83+
finish:
84+
needs: test
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: shogo82148/[email protected]
88+
with:
89+
parallel-finished: true
90+
91+
92+
# draft your next release notes as pull requests are merged into "master"
93+
# the configuration is at /.github/release-drafter.yml.
94+
update_release_draft:
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: release-drafter/release-drafter@v5
98+
if: github.ref == 'refs/heads/master'
99+
with:
100+
config-name: release-drafter.yml
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

-20
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea
22
/.vscode
3+
/*.cov

README.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# go-test-buckets
2+
[![Actions Status](https://github.com/Eun/go-test-buckets/workflows/push/badge.svg)](https://github.com/Eun/go-test-buckets/actions)
3+
[![Coverage Status](https://coveralls.io/repos/github/Eun/go-test-buckets/badge.svg?branch=master)](https://coveralls.io/github/Eun/go-test-buckets?branch=master)
4+
[![PkgGoDev](https://img.shields.io/badge/pkg.go.dev-reference-blue)](https://pkg.go.dev/github.com/Eun/go-test-buckets)
5+
[![go-report](https://goreportcard.com/badge/github.com/Eun/go-test-buckets)](https://goreportcard.com/report/github.com/Eun/go-test-buckets)
6+
---
27
Split your go tests into buckets, or exclude some packages/directories.
38

49
## Buckets
@@ -7,11 +12,16 @@ package main_test
712

813
import (
914
"testing"
15+
"os"
1016

11-
// import to get bucket and exclude feature
12-
_ "github.com/Eun/go-test-buckets"
17+
"github.com/Eun/go-test-buckets"
1318
)
1419

20+
func TestMain(m *testing.M) {
21+
buckets.Buckets(m)
22+
os.Exit(m.Run())
23+
}
24+
1525
// run with BUCKET=0 TOTAL_BUCKETS=2 go test -count=1 -v ./...
1626
// will run TestA and TestB
1727

@@ -29,15 +39,19 @@ func TestC(t *testing.T) {
2939
```
3040

3141
## Excluding Packages/Directories
32-
1. Add to your imports `_ "github.com/Eun/go-test-buckets"`
42+
1. Add to your package
43+
```go
44+
func TestMain(m *testing.M) {
45+
buckets.Buckets(m)
46+
os.Exit(m.Run())
47+
}
48+
```
3349
2. Run `EXCLUDE_PACKAGES=package/path/to/exclude,package/path/to/exclude-2 go test -count=1 -v ./...`
3450
3. Or `EXCLUDE_DIRECTORIES=/full/path/to/exclude go test -count=1 -v ./...`
3551

3652

3753

38-
> Because of `go test` package separation, you have to import `github.com/Eun/go-test-buckets` in each package you want to ignore.
39-
40-
> Note that uses some nasty memory patching to make this possible. So use with care.
54+
> Because of `go test` package separation, you have to call `buckets.Buckets(m)` in every package you want to ignore.
4155
4256
# Why?
4357
Speed up ci pipelines by parallelizing go tests without thinking about [t.Parallel](https://golang.org/pkg/testing/#T.Parallel).

example/test/bucket/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Buckets
2+
To run this example
3+
```shell
4+
# This will only run TestA and TestB (Bucket 0) not TestC (Bucket 1)
5+
cd example/test/exclude/directory
6+
BUCKET=0 TOTAL_BUCKETS=2 go test -count=1 -v ./...
7+
```
8+

0 commit comments

Comments
 (0)