Skip to content

Commit

Permalink
Pass GITHUB_TOKEN to tools tests (#4558)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Aug 28, 2024
1 parent 5034539 commit 788f3b9
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
run: bin/task test-unit-short TEST_TIMEOUT=10m
env:
GOFLAGS: ${{ runner.debug == '1' && '-v' || '' }}
GITHUB_TOKEN: invalid # to test that -short is handled correctly

# we don't want them on CI
- name: Clean test and fuzz caches
Expand Down Expand Up @@ -119,6 +120,7 @@ jobs:
run: bin/task test-unit TEST_TIMEOUT=10m
env:
GOFLAGS: ${{ runner.debug == '1' && '-v' || '' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # for tools

# The token is not required but should make uploads more stable.
# If secrets are unavailable (for example, for a pull request from a fork), it fallbacks to the tokenless uploads.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ The results will be saved `tmp/bin`.
Some of our development tools require access to public information on GitHub
at a rate higher than allowed for unauthenticated requests.
Those tools will report a problem in this case.
It could be solved by creating a new classic or fine-graned personal access token
It could be solved by creating a new classic or fine-grained personal access token
[there](https://github.com/settings/tokens).
No scopes are needed for classic tokens, not even `public_repo`.
For fine-graned tokens, only read-only access to public repositories is needed without any additional permissions.
For fine-grained tokens, only read-only access to public repositories is needed without any additional permissions.
After generating a token, set the `GITHUB_TOKEN` environment variable:

```sh
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ tasks:
desc: "Run short unit tests (with caching)"
cmds:
- go test -short -timeout={{.TEST_TIMEOUT}} {{.RACE_FLAG}} -tags={{.BUILD_TAGS}} -shuffle=on -coverpkg=./... -coverprofile=cover.txt ./...
- bin/task{{exeExt}} -d tools tools-test
- bin/task{{exeExt}} -d tools tools-test-short

test-unit:
desc: "Run all unit tests"
Expand Down
19 changes: 13 additions & 6 deletions tools/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
version: 3

vars:
PACKAGES: ./checkcomments/... ./checkdocs/... ./checkswitch/... ./github/...
RACE_FLAG: -race={{and (ne OS "windows") (ne ARCH "arm") (ne ARCH "riscv64")}}

tasks:
tools-test-short:
cmds:
- ../bin/envtool{{exeExt}} shell rmdir ../tmp/githubcache
- ../bin/envtool{{exeExt}} shell mkdir ../tmp/githubcache
- go test -short {{.RACE_FLAG}} -shuffle=on -coverprofile=cover.txt -coverpkg=./... {{.PACKAGES}}

tools-test:
cmds:
- ../bin/envtool{{exeExt}} shell rmdir ../tmp/githubcache
- ../bin/envtool{{exeExt}} shell mkdir ../tmp/githubcache
- go test -short {{.RACE_FLAG}} -shuffle=on -coverprofile=cover.txt -coverpkg=./... ./checkcomments/... ./checkdocs/... ./checkswitch/...
- go test -count=1 {{.RACE_FLAG}} -shuffle=on -coverprofile=cover.txt -coverpkg=./... {{.PACKAGES}}

lint:
desc: "Run linters"
cmds:
- ../bin/golangci-lint{{exeExt}} run --config=../.golangci.yml ./checkcomments/... ./checkdocs/... ./checkswitch/...
- ../bin/golangci-lint{{exeExt}} run --config=../.golangci-new.yml ./checkcomments/... ./checkdocs/... ./checkswitch/...
- ../bin/go-consistent{{exeExt}} -pedantic ./checkcomments/... ./checkdocs/... ./checkswitch/...
- ../bin/golangci-lint{{exeExt}} run --config=../.golangci.yml {{.PACKAGES}}
- ../bin/golangci-lint{{exeExt}} run --config=../.golangci-new.yml {{.PACKAGES}}
- ../bin/go-consistent{{exeExt}} -pedantic {{.PACKAGES}}

- go vet -vettool=../bin/checkswitch{{exeExt}} ./checkcomments/... ./checkdocs/... ./checkswitch/...
- go vet -vettool=../bin/checkcomments{{exeExt}} ./checkcomments/... ./checkdocs/... ./checkswitch/...
- go vet -vettool=../bin/checkswitch{{exeExt}} {{.PACKAGES}}
- go vet -vettool=../bin/checkcomments{{exeExt}} {{.PACKAGES}}
4 changes: 4 additions & 0 deletions tools/checkcomments/checkcomments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
)

func TestCheckCommentIssue(t *testing.T) {
if testing.Short() {
t.Skip("skipping in -short mode")
}

t.Parallel()

path, err := github.CacheFilePath()
Expand Down
2 changes: 1 addition & 1 deletion tools/checkdocs/checkdocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func checkSupportedCommands(file string) error {
}

if failed {
return fmt.Errorf("supported commands table is not formated correctly")
return fmt.Errorf("supported commands table is not formatted correctly")
}

return nil
Expand Down
12 changes: 10 additions & 2 deletions tools/checkdocs/checkdocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
)

func TestReal(t *testing.T) {
if testing.Short() {
t.Skip("skipping in -short mode")
}

blogFiles, err := filepath.Glob(filepath.Join("..", "..", "website", "blog", "*.md"))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -89,8 +93,12 @@ func TestVerifyTruncateString(t *testing.T) {
}

func TestCheckSupportedCommands(t *testing.T) {
buf := new(bytes.Buffer)
l := log.New(buf, "", 0)
if testing.Short() {
t.Skip("skipping in -short mode")
}

var buf bytes.Buffer
l := log.New(&buf, "", 0)

p, err := github.CacheFilePath()
require.NoError(t, err)
Expand Down
92 changes: 0 additions & 92 deletions tools/cleantool/cleantool.go

This file was deleted.

7 changes: 5 additions & 2 deletions tools/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ func CacheFilePath() (string, error) {
}

var (
// urlRE represents correctly formated FerretDB issue.
// Correctly formatted FerretDB issue.
// It returns repository name and the issue number as it's submatches.
urlRE = regexp.MustCompile(`^\Qhttps://github.com/FerretDB/\E([-\w]+)/issues/(\d+)$`)

// ErrIncorrectURL indicates that FerretDB issue URL is formatted incorrectly.
ErrIncorrectURL = errors.New("invalid TODO: incorrect format")

// ErrIncorrectIssueNumber indicates that FerretDB issue number is formatted incorrectly.
ErrIncorrectIssueNumber = errors.New("invalid TODO: incorrect issue number")
)

// parseIssueURL takes the properly formated FerretDB issue URL and returns it's
// parseIssueURL takes the properly formatted FerretDB issue URL and returns it's
// repository name and issue number.
// If the issue number or URL formatting is incorrect, the error is returned.
func parseIssueURL(line string) (repo string, num int, err error) {
Expand Down Expand Up @@ -256,6 +257,8 @@ func (c *Client) checkIssueStatus(ctx context.Context, repo string, num int) (Is
switch s := IssueStatus(issue.GetState()); s {
case IssueOpen, IssueClosed:
return s, nil
case IssueNotFound:
fallthrough
default:
return "", fmt.Errorf("unknown issue state: %q", s)
}
Expand Down
4 changes: 4 additions & 0 deletions tools/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestCacheFilePath(t *testing.T) {
}

func TestClient(t *testing.T) {
if testing.Short() {
t.Skip("skipping in -short mode")
}

t.Parallel()

cacheFilePath := filepath.Join(t.TempDir(), "cache.json")
Expand Down
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/quasilyte/go-consistent v0.6.1
github.com/rogpeppe/go-internal v1.12.0
github.com/stretchr/testify v1.9.0
golang.org/x/oauth2 v0.21.0
golang.org/x/perf v0.0.0-20240707193131-dc66afd55b77
golang.org/x/pkgsite v0.0.0-20240701161620-30d9315975ff
golang.org/x/tools v0.23.0
Expand Down Expand Up @@ -106,6 +105,7 @@ require (
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7 // indirect
Expand Down

0 comments on commit 788f3b9

Please sign in to comment.