From b4c1aa28918fa815da74d6c64ac84d4c08b3757a Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 12 Sep 2023 17:46:03 -0500 Subject: [PATCH 01/20] add scripts/ --- .codecov.yml | 2 ++ .github/workflows/linter.yml | 26 ++++---------------- .github/workflows/tests.yml | 22 +++-------------- .gitignore | 1 + scripts/fmt | 19 +++++++++++++++ scripts/generate | 47 ++++++++++++++++++++++++++++++++++++ scripts/lint | 41 +++++++++++++++++++++++++++++++ scripts/test | 25 +++++++++++++++++++ 8 files changed, 144 insertions(+), 39 deletions(-) create mode 100755 scripts/fmt create mode 100755 scripts/generate create mode 100755 scripts/lint create mode 100755 scripts/test diff --git a/.codecov.yml b/.codecov.yml index 0f63adb3a6c..2ef223a6e96 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -3,3 +3,5 @@ ignore: - "github/github-accessors.go" # ignore experimental scrape package - "scrape" + # ignore update-urls + - "update-urls" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 4f3cdf8e4df..f466111d588 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -3,30 +3,14 @@ name: linter permissions: contents: read - pull-requests: read jobs: lint: - strategy: - matrix: - platform: [ubuntu-latest] - - # golangci-lint will only process a single module, so we need to call it - # separately for each module in the repo. We dont lint example/newreposecretwithlibsodium - # since that needs libsodium to run. - working-directory: - - "" - - example - - scrape - - update-urls - runs-on: ${{ matrix.platform }} - + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: golangci-lint ${{ matrix.working-directory }} - uses: golangci/golangci-lint-action@v3 + - uses: actions/setup-go@v4 with: - version: latest - working-directory: ${{ matrix.working-directory}} - args: --verbose + go-version: 1.x + cache-dependency-path: "**/go.sum" + - run: scripts/lint diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 87d97f99c09..ba6b74db563 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,7 +41,7 @@ jobs: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v4 - # Get values for cache paths to be used in later steps + # Get values for cache paths to be used in later steps - id: cache-paths run: | echo "go-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT @@ -57,29 +57,15 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- - - name: Ensure go generate produces a zero diff - shell: bash - run: go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) - - name: Run go test - run: go test -v -race -coverprofile coverage.txt -covermode atomic ./... + env: + COVERPROFILE: coverage.txt + run: scripts/test - name: Ensure integration tests build # don't actually run tests since they hit live GitHub API run: go test -v -tags=integration -run=^$ ./test/integration - - name: Run scrape tests - run: | - cd scrape - go test ./... - - name: Upload coverage to Codecov if: ${{ matrix.update-coverage }} uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d #v3.1.4 - - - name: Ensure go generate produces a zero diff for update-urls - shell: bash - run: cd update-urls && go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) - - - name: Run go test for update-urls - run: cd update-urls && go test -v -race ./... diff --git a/.gitignore b/.gitignore index 704f4ef5b54..3a24427a962 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.sh *.test coverage.out +/bin # intellij files .idea/ vendor/ diff --git a/scripts/fmt b/scripts/fmt new file mode 100755 index 00000000000..1989697776c --- /dev/null +++ b/scripts/fmt @@ -0,0 +1,19 @@ +#!/bin/sh +#/ scripts/fmt runs go fmt on all go files in the project. + +set -e + +CDPATH="" cd -- "$(dirname -- "$0")/.." + +MOD_DIRS="$( + git ls-files '*go.mod' | + xargs dirname | + sort +)" + +for dir in $MOD_DIRS; do + ( + cd "$dir" + go fmt ./... + ) +done diff --git a/scripts/generate b/scripts/generate new file mode 100755 index 00000000000..7a5d9e0261f --- /dev/null +++ b/scripts/generate @@ -0,0 +1,47 @@ +#!/bin/sh +#/ scripts/generate runs go generate on all modules in this repo. +#/ `scripts/generate --check` checks that the generated files are up to date. + +set -e + +CDPATH="" cd -- "$(dirname -- "$0")/.." + +if [ "$1" = "--check" ]; then + GENTEMP="$(mktemp -d)" + git worktree add -q --detach "$GENTEMP" + trap 'git worktree remove -f "$GENTEMP"; rm -rf "$GENTEMP"' EXIT + for f in $(git ls-files -com --exclude-standard); do + target="$GENTEMP/$f" + mkdir -p "$(dirname -- "$target")" + cp "$f" "$target" + done + if [ -f "$(pwd)"/bin ]; then + ln -s "$(pwd)"/bin "$GENTEMP"/bin + fi + ( + cd "$GENTEMP" + git add . + git -c user.name='bot' -c user.email='bot@localhost' commit -m "generate" -q --allow-empty + scripts/generate + [ -z "$(git status --porcelain)" ] || { + echo "scripts/generate resulted in changes." 1>&2 + git diff + exit 1 + } + ) + exit 0 +fi + +MOD_DIRS="$( + git ls-files '*go.mod' | + xargs dirname | + sort +)" + +for dir in $MOD_DIRS; do + ( + cd "$dir" + go generate ./... + go mod tidy -compat '1.17' + ) +done diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 00000000000..f821e5318d0 --- /dev/null +++ b/scripts/lint @@ -0,0 +1,41 @@ +#!/bin/sh +#/ scripts/lint runs linters and validates generated files. + +set -e + +GOLANGCI_LINT_VERSION="1.54.2" + +CDPATH="" cd -- "$(dirname -- "$0")/.." +BIN="$(pwd -P)"/bin + +install_golangci_lint() { + mkdir -p "$BIN" + if [ -f "$BIN"/golangci-lint ]; then + if "$BIN"/golangci-lint --version | grep -q "$GOLANGCI_LINT_VERSION"; then + return + fi + fi + GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" +} + +install_golangci_lint + +MOD_DIRS="$( + git ls-files '*go.mod' | + xargs dirname | + grep -v newreposecretwithlibsodium | + sort +)" + +for dir in $MOD_DIRS; do + echo linting "$dir" + ( + cd "$dir" + # github actions output when running in an action + if [ -n "$GITHUB_ACTIONS" ]; then + "$BIN"/golangci-lint run --path-prefix "$dir" --out-format github-actions + continue + fi + "$BIN"/golangci-lint run --path-prefix "$dir" + ) +done diff --git a/scripts/test b/scripts/test new file mode 100755 index 00000000000..175d99c4177 --- /dev/null +++ b/scripts/test @@ -0,0 +1,25 @@ +#!/bin/sh +#/ scripts/test runs tests on each go module in . When COVERPROFILE is set, it +#/ collects coverage information in the file named by COVERPROFILE. + +set -e + +CDPATH="" cd -- "$(dirname -- "$0")/.." + +MOD_DIRS="$( + git ls-files '*go.mod' | + xargs dirname | + grep -v newreposecretwithlibsodium | + sort +)" + +for dir in $MOD_DIRS; do + ( + cd "$dir" + if [ -n "$COVERPROFILE" ]; then + go test -race -covermode atomic -coverprofile "$COVERPROFILE" ./... + continue + fi + go test -race -covermode atomic ./... + ) +done From 618007c0c137763cf68f48975e5a52ac719cc28d Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 12 Sep 2023 17:51:29 -0500 Subject: [PATCH 02/20] lint generation --- .github/workflows/tests.yml | 2 +- scripts/lint | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ba6b74db563..36cbc53068b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,7 +41,7 @@ jobs: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v4 - # Get values for cache paths to be used in later steps + # Get values for cache paths to be used in later steps - id: cache-paths run: | echo "go-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT diff --git a/scripts/lint b/scripts/lint index f821e5318d0..555ec78d68e 100755 --- a/scripts/lint +++ b/scripts/lint @@ -39,3 +39,5 @@ for dir in $MOD_DIRS; do "$BIN"/golangci-lint run --path-prefix "$dir" ) done + +scripts/generate --check From 60bc2235105ede1ecd7275d755b43d69ee0b092e Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 14 Sep 2023 13:31:15 -0500 Subject: [PATCH 03/20] update scripts --- .github/workflows/tests.yml | 13 +++++++++---- example/basicauth/main.go | 3 +-- example/tagprotection/main.go | 3 +-- example/tokenauth/main.go | 4 ++-- scripts/fmt | 6 +----- scripts/generate | 13 +++++++------ scripts/lint | 21 +++++++++++---------- scripts/test | 29 +++++++++++++++-------------- 8 files changed, 47 insertions(+), 45 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36cbc53068b..063ff03666c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,6 +19,9 @@ permissions: jobs: test: + defaults: + run: + shell: bash strategy: matrix: go-version: [1.x, 1.20.x] @@ -46,7 +49,6 @@ jobs: run: | echo "go-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT echo "go-mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT - shell: bash - name: Cache go modules uses: actions/cache@v3 @@ -58,9 +60,12 @@ jobs: restore-keys: ${{ runner.os }}-go- - name: Run go test - env: - COVERPROFILE: coverage.txt - run: scripts/test + run: | + if [ -n "${{ matrix.update-coverage }}" ]; then + scripts/test -race -covermode atomic -coverprofile coverage.txt ./... + exit + fi + scripts/test -race -covermode atomic ./... - name: Ensure integration tests build # don't actually run tests since they hit live GitHub API diff --git a/example/basicauth/main.go b/example/basicauth/main.go index e677aa94a42..95ec4360c21 100644 --- a/example/basicauth/main.go +++ b/example/basicauth/main.go @@ -20,7 +20,6 @@ import ( "fmt" "os" "strings" - "syscall" "github.com/google/go-github/v55/github" "golang.org/x/term" @@ -32,7 +31,7 @@ func main() { username, _ := r.ReadString('\n') fmt.Print("GitHub Password: ") - bytePassword, _ := term.ReadPassword(syscall.Stdin) + bytePassword, _ := term.ReadPassword(int(os.Stdin.Fd())) password := string(bytePassword) tp := github.BasicAuthTransport{ diff --git a/example/tagprotection/main.go b/example/tagprotection/main.go index 3b9b723dd0f..4127d2b44de 100644 --- a/example/tagprotection/main.go +++ b/example/tagprotection/main.go @@ -17,7 +17,6 @@ import ( "log" "os" "strings" - "syscall" "github.com/google/go-github/v55/github" "golang.org/x/term" @@ -39,7 +38,7 @@ func main() { pattern = strings.TrimSpace(pattern) fmt.Print("GitHub Token: ") - byteToken, _ := term.ReadPassword(syscall.Stdin) + byteToken, _ := term.ReadPassword(int(os.Stdin.Fd())) println() token := string(byteToken) diff --git a/example/tokenauth/main.go b/example/tokenauth/main.go index 91ad5e5067a..ccd36543584 100644 --- a/example/tokenauth/main.go +++ b/example/tokenauth/main.go @@ -13,7 +13,7 @@ import ( "context" "fmt" "log" - "syscall" + "os" "github.com/google/go-github/v55/github" "golang.org/x/term" @@ -21,7 +21,7 @@ import ( func main() { fmt.Print("GitHub Token: ") - byteToken, _ := term.ReadPassword(syscall.Stdin) + byteToken, _ := term.ReadPassword(int(os.Stdin.Fd())) println() token := string(byteToken) diff --git a/scripts/fmt b/scripts/fmt index 1989697776c..e3891861370 100755 --- a/scripts/fmt +++ b/scripts/fmt @@ -5,11 +5,7 @@ set -e CDPATH="" cd -- "$(dirname -- "$0")/.." -MOD_DIRS="$( - git ls-files '*go.mod' | - xargs dirname | - sort -)" +MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" for dir in $MOD_DIRS; do ( diff --git a/scripts/generate b/scripts/generate index 7a5d9e0261f..aa7d46aea82 100755 --- a/scripts/generate +++ b/scripts/generate @@ -24,7 +24,12 @@ if [ "$1" = "--check" ]; then git -c user.name='bot' -c user.email='bot@localhost' commit -m "generate" -q --allow-empty scripts/generate [ -z "$(git status --porcelain)" ] || { - echo "scripts/generate resulted in changes." 1>&2 + msg="Generated files are out of date. Please run scripts/generate and commit the results" + if [ -n "$GITHUB_ACTIONS" ]; then + echo "::error ::$msg" + else + echo "$msg" 1>&2 + fi git diff exit 1 } @@ -32,11 +37,7 @@ if [ "$1" = "--check" ]; then exit 0 fi -MOD_DIRS="$( - git ls-files '*go.mod' | - xargs dirname | - sort -)" +MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" for dir in $MOD_DIRS; do ( diff --git a/scripts/lint b/scripts/lint index 555ec78d68e..42d49a15a67 100755 --- a/scripts/lint +++ b/scripts/lint @@ -6,7 +6,8 @@ set -e GOLANGCI_LINT_VERSION="1.54.2" CDPATH="" cd -- "$(dirname -- "$0")/.." -BIN="$(pwd -P)"/bin +REPO_DIR="$(pwd -P)" +BIN="$REPO_DIR"/bin install_golangci_lint() { mkdir -p "$BIN" @@ -20,24 +21,24 @@ install_golangci_lint() { install_golangci_lint -MOD_DIRS="$( - git ls-files '*go.mod' | - xargs dirname | - grep -v newreposecretwithlibsodium | - sort -)" +MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" for dir in $MOD_DIRS; do + [ "$dir" = "example/newreposecretwithlibsodium" ] && continue echo linting "$dir" ( cd "$dir" # github actions output when running in an action if [ -n "$GITHUB_ACTIONS" ]; then "$BIN"/golangci-lint run --path-prefix "$dir" --out-format github-actions - continue + else + "$BIN"/golangci-lint run --path-prefix "$dir" fi - "$BIN"/golangci-lint run --path-prefix "$dir" - ) + ) || FAILED=1 done scripts/generate --check + +if [ -n "$FAILED" ]; then + exit 1 +fi diff --git a/scripts/test b/scripts/test index 175d99c4177..0c2878dd8f9 100755 --- a/scripts/test +++ b/scripts/test @@ -1,25 +1,26 @@ #!/bin/sh -#/ scripts/test runs tests on each go module in . When COVERPROFILE is set, it -#/ collects coverage information in the file named by COVERPROFILE. +#/ scripts/test runs tests on each go module in go-github. Arguments are passed to each go test invocation. +#/ "-race -covermode atomic ./..." is used when no arguments are given. set -e CDPATH="" cd -- "$(dirname -- "$0")/.." -MOD_DIRS="$( - git ls-files '*go.mod' | - xargs dirname | - grep -v newreposecretwithlibsodium | - sort -)" +if [ "$#" = "0" ]; then + set -- -race -covermode atomic ./... +fi + +MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" for dir in $MOD_DIRS; do + [ "$dir" = "example/newreposecretwithlibsodium" ] && continue + echo "testing $dir" ( cd "$dir" - if [ -n "$COVERPROFILE" ]; then - go test -race -covermode atomic -coverprofile "$COVERPROFILE" ./... - continue - fi - go test -race -covermode atomic ./... - ) + go test "$@" + ) || FAILED=1 done + +if [ -n "$FAILED" ]; then + exit 1 +fi From 2861295d6c6127a4d91a8d82d46af871efc62700 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 09:37:25 -0500 Subject: [PATCH 04/20] update scripts/lint --- scripts/lint | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/lint b/scripts/lint index 42d49a15a67..ca24b57c647 100755 --- a/scripts/lint +++ b/scripts/lint @@ -9,17 +9,14 @@ CDPATH="" cd -- "$(dirname -- "$0")/.." REPO_DIR="$(pwd -P)" BIN="$REPO_DIR"/bin -install_golangci_lint() { - mkdir -p "$BIN" - if [ -f "$BIN"/golangci-lint ]; then - if "$BIN"/golangci-lint --version | grep -q "$GOLANGCI_LINT_VERSION"; then - return - fi - fi - GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" -} +mkdir -p "$BIN" -install_golangci_lint +# install golangci-lint if it doesn't exist or is the wrong version +if [ ! -f "$BIN"/golangci-lint ]; then + if ! "$BIN"/golangci-lint --version | grep -q "$GOLANGCI_LINT_VERSION"; then + GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" + fi +fi MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" @@ -37,7 +34,7 @@ for dir in $MOD_DIRS; do ) || FAILED=1 done -scripts/generate --check +scripts/generate --check || FAILED=1 if [ -n "$FAILED" ]; then exit 1 From 7b50a4608b412691f525ce4c00e81a1259d125c2 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 09:42:56 -0500 Subject: [PATCH 05/20] Increase lint timeout --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 3e286f045f4..e814f27d76f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,5 @@ run: + timeout: 3m build-tags: - integration linters: From b2b507e79f77fb410fa349b23d354589dcb3b77f Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 09:50:40 -0500 Subject: [PATCH 06/20] fix err output when golangci-lint is missing --- scripts/lint | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/lint b/scripts/lint index ca24b57c647..e6dab3f113a 100755 --- a/scripts/lint +++ b/scripts/lint @@ -11,11 +11,9 @@ BIN="$REPO_DIR"/bin mkdir -p "$BIN" -# install golangci-lint if it doesn't exist or is the wrong version -if [ ! -f "$BIN"/golangci-lint ]; then - if ! "$BIN"/golangci-lint --version | grep -q "$GOLANGCI_LINT_VERSION"; then - GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" - fi +# install golangci-lint bin/golangci-lint doesn't exist with the correct version +if ! "$BIN"/golangci-lint --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then + GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" fi MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" From 0fe0ba8dc4b0025c11f31e476b67b98bd1b9fd38 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 09:54:38 -0500 Subject: [PATCH 07/20] introduce test and lint errors --- example/actionpermissions/main.go | 5 +---- example/go.mod | 2 +- github/actions_artifacts.go | 3 --- github/actions_artifacts_test.go | 4 ++++ update-urls/main_test.go | 4 ++++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/example/actionpermissions/main.go b/example/actionpermissions/main.go index 4ff7008ca9d..1bb2829ba7e 100644 --- a/example/actionpermissions/main.go +++ b/example/actionpermissions/main.go @@ -45,10 +45,7 @@ func main() { fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String()) actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Bool(true), AllowedActions: github.String("selected")} - _, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository) - if err != nil { - log.Fatal(err) - } + _, _, _ = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository) fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String()) diff --git a/example/go.mod b/example/go.mod index eaf9f5b6926..484dc34f6cf 100644 --- a/example/go.mod +++ b/example/go.mod @@ -1,6 +1,6 @@ module github.com/google/go-github/v55/example -go 1.17 + go 1.17 require ( github.com/bradleyfalzon/ghinstallation/v2 v2.0.4 diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 441a53910e3..2fb0aede723 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -56,9 +56,6 @@ type ArtifactList struct { func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListOptions) (*ArtifactList, *Response, error) { u := fmt.Sprintf("repos/%v/%v/actions/artifacts", owner, repo) u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index de07c14f847..6a688130398 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -16,6 +16,10 @@ import ( "github.com/google/go-cmp/cmp" ) +func TestFail(t *testing.T) { + t.Errorf("This test fails") +} + func TestActionsService_ListArtifacts(t *testing.T) { client, mux, _, teardown := setup() defer teardown() diff --git a/update-urls/main_test.go b/update-urls/main_test.go index d4696e1e967..777916f499f 100644 --- a/update-urls/main_test.go +++ b/update-urls/main_test.go @@ -18,6 +18,10 @@ import ( "github.com/pmezard/go-difflib/difflib" ) +func TestFail(t *testing.T) { + t.Errorf("This test fails") +} + type pipelineSetup struct { // Fields filled in by the unit test: baseURL string From 8a447bcdce7aa05ba75ceed7be82aa5edddeb43d Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 10:02:23 -0500 Subject: [PATCH 08/20] Revert "introduce test and lint errors" This reverts commit 0fe0ba8dc4b0025c11f31e476b67b98bd1b9fd38. --- example/actionpermissions/main.go | 5 ++++- example/go.mod | 2 +- github/actions_artifacts.go | 3 +++ github/actions_artifacts_test.go | 4 ---- update-urls/main_test.go | 4 ---- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/example/actionpermissions/main.go b/example/actionpermissions/main.go index 1bb2829ba7e..4ff7008ca9d 100644 --- a/example/actionpermissions/main.go +++ b/example/actionpermissions/main.go @@ -45,7 +45,10 @@ func main() { fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String()) actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Bool(true), AllowedActions: github.String("selected")} - _, _, _ = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository) + _, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository) + if err != nil { + log.Fatal(err) + } fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String()) diff --git a/example/go.mod b/example/go.mod index 484dc34f6cf..eaf9f5b6926 100644 --- a/example/go.mod +++ b/example/go.mod @@ -1,6 +1,6 @@ module github.com/google/go-github/v55/example - go 1.17 +go 1.17 require ( github.com/bradleyfalzon/ghinstallation/v2 v2.0.4 diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 2fb0aede723..441a53910e3 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -56,6 +56,9 @@ type ArtifactList struct { func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListOptions) (*ArtifactList, *Response, error) { u := fmt.Sprintf("repos/%v/%v/actions/artifacts", owner, repo) u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index 6a688130398..de07c14f847 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -16,10 +16,6 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestFail(t *testing.T) { - t.Errorf("This test fails") -} - func TestActionsService_ListArtifacts(t *testing.T) { client, mux, _, teardown := setup() defer teardown() diff --git a/update-urls/main_test.go b/update-urls/main_test.go index 777916f499f..d4696e1e967 100644 --- a/update-urls/main_test.go +++ b/update-urls/main_test.go @@ -18,10 +18,6 @@ import ( "github.com/pmezard/go-difflib/difflib" ) -func TestFail(t *testing.T) { - t.Errorf("This test fails") -} - type pipelineSetup struct { // Fields filled in by the unit test: baseURL string From 757b60ec001b28ea8bdfbc6b5d70467fffc0a3d8 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 10:57:41 -0500 Subject: [PATCH 09/20] update formatting for patch section of CONTRIBUTING.md --- CONTRIBUTING.md | 104 ++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb3660461fc..eab5f146e4f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,58 +31,58 @@ are more sensitive, emailed to . ## Submitting a patch ## - 1. It's generally best to start by opening a new issue describing the bug or - feature you're intending to fix. Even if you think it's relatively minor, - it's helpful to know what people are working on. Mention in the initial - issue that you are planning to work on that bug or feature so that it can - be assigned to you. - - 1. Follow the normal process of [forking][] the project, and setup a new - branch to work in. It's important that each group of changes be done in - separate branches in order to ensure that a pull request only includes the - commits related to that bug or feature. - - 1. Go makes it very simple to ensure properly formatted code, so always run - `go fmt` on your code before committing it. You should also run - [go vet][] over your code. this will help you find common style issues - within your code and will keep styling consistent within the project. - - 1. Any significant changes should almost always be accompanied by tests. The - project already has good test coverage, so look at some of the existing - tests if you're unsure how to go about it. [gocov][] and [gocov-html][] - are invaluable tools for seeing which parts of your code aren't being - exercised by your tests. - - 1. Please run: - * `go generate github.com/google/go-github/...` - * `go test github.com/google/go-github/...` - * `go vet github.com/google/go-github/...` - - The `go generate ./...` command will update or generate certain files, and the - resulting changes should be included in your pull request. - - The `go test ./...` command will run tests inside your code. This will help you - spot places where code might be faulty before committing. - - And finally, the `go vet ./...` command will check linting and styling over your - code, keeping the project consistent formatting-wise. - - In any case, it is always a good idea to read [official Go documentation][] when working - on this project, as the definition of tools and commands of the Go programming - language is described in further detail there. - - 1. Do your best to have [well-formed commit messages][] for each change. - This provides consistency throughout the project, and ensures that commit - messages are able to be formatted properly by various git tools. - - 1. Finally, push the commits to your fork and submit a [pull request][]. - Before pushing commits, it is highly advised to check for generated files - that were either created or modified for the sake of your commit. Running - `go generate -x ./...` should return a log of modified generated files that should - be included alongside the manually written code in the commit. - **NOTE:** Please do not use force-push on PRs in this repo, as it makes - it more difficult for reviewers to see what has changed since the last - code review. +1. It's generally best to start by opening a new issue describing the bug or + feature you're intending to fix. Even if you think it's relatively minor, + it's helpful to know what people are working on. Mention in the initial issue + that you are planning to work on that bug or feature so that it can be + assigned to you. + +2. Follow the normal process of [forking][] the project, and setup a new branch + to work in. It's important that each group of changes be done in separate + branches in order to ensure that a pull request only includes the commits + related to that bug or feature. + +3. Go makes it very simple to ensure properly formatted code, so always run + `go fmt` on your code before committing it. You should also run + [go vet][] over your code. this will help you find common style issues within + your code and will keep styling consistent within the project. + +4. Any significant changes should almost always be accompanied by tests. The + project already has good test coverage, so look at some of the existing tests + if you're unsure how to go about it. [gocov][] and [gocov-html][] + are invaluable tools for seeing which parts of your code aren't being + exercised by your tests. + +5. Please run: + * `go generate github.com/google/go-github/...` + * `go test github.com/google/go-github/...` + * `go vet github.com/google/go-github/...` + + The `go generate ./...` command will update or generate certain files, and + the resulting changes should be included in your pull request. + + The `go test ./...` command will run tests inside your code. This will help + you spot places where code might be faulty before committing. + + And finally, the `go vet ./...` command will check linting and styling over + your code, keeping the project consistent formatting-wise. + + In any case, it is always a good idea to read [official Go documentation][] + when working on this project, as the definition of tools and commands of the + Go programming language is described in further detail there. + +6. Do your best to have [well-formed commit messages][] for each change. This + provides consistency throughout the project, and ensures that commit messages + are able to be formatted properly by various git tools. + +7. Finally, push the commits to your fork and submit a [pull request][]. Before + pushing commits, it is highly advised to check for generated files that were + either created or modified for the sake of your commit. Running + `go generate -x ./...` should return a log of modified generated files that + should be included alongside the manually written code in the commit. + **NOTE:** Please do not use force-push on PRs in this repo, as it makes it + more difficult for reviewers to see what has changed since the last code + review. [official Go documentation]: https://pkg.go.dev/std [forking]: https://help.github.com/articles/fork-a-repo From 3b42e0cda2a858942c201038d6575643f19d2768 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 11:07:18 -0500 Subject: [PATCH 10/20] update CONTRIBUTING.md with new scripts --- CONTRIBUTING.md | 71 +++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eab5f146e4f..62fcb4e2831 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,57 +42,48 @@ are more sensitive, emailed to . branches in order to ensure that a pull request only includes the commits related to that bug or feature. -3. Go makes it very simple to ensure properly formatted code, so always run - `go fmt` on your code before committing it. You should also run - [go vet][] over your code. this will help you find common style issues within - your code and will keep styling consistent within the project. - -4. Any significant changes should almost always be accompanied by tests. The +3. Any significant changes should almost always be accompanied by tests. The project already has good test coverage, so look at some of the existing tests - if you're unsure how to go about it. [gocov][] and [gocov-html][] - are invaluable tools for seeing which parts of your code aren't being - exercised by your tests. - -5. Please run: - * `go generate github.com/google/go-github/...` - * `go test github.com/google/go-github/...` - * `go vet github.com/google/go-github/...` - - The `go generate ./...` command will update or generate certain files, and - the resulting changes should be included in your pull request. - - The `go test ./...` command will run tests inside your code. This will help - you spot places where code might be faulty before committing. - - And finally, the `go vet ./...` command will check linting and styling over - your code, keeping the project consistent formatting-wise. - - In any case, it is always a good idea to read [official Go documentation][] - when working on this project, as the definition of tools and commands of the - Go programming language is described in further detail there. - -6. Do your best to have [well-formed commit messages][] for each change. This + if you're unsure how to go about it. Coverage is [monitored by codecov.io][], + which flags pull requests that decrease test coverage. This doesn't + necessarily mean that PRs with decreased coverage won't be merged. Sometimes + a decrease in coverage makes sense, but if your PR is flagged, you should + either add tests to cover those lines or add a PR comment explaining the + untested lines. + +4. Run `scripts/fmt`, `scripts/test` and `scripts/lint` to format your code and + check that it passes all tests and linters. `scripts/lint` may also tell you + that generated files need to be updated. If so, run `scripts/generate` to + update them. + +5. Do your best to have [well-formed commit messages][] for each change. This provides consistency throughout the project, and ensures that commit messages are able to be formatted properly by various git tools. -7. Finally, push the commits to your fork and submit a [pull request][]. Before - pushing commits, it is highly advised to check for generated files that were - either created or modified for the sake of your commit. Running - `go generate -x ./...` should return a log of modified generated files that - should be included alongside the manually written code in the commit. +6. Finally, push the commits to your fork and submit a [pull request][]. **NOTE:** Please do not use force-push on PRs in this repo, as it makes it more difficult for reviewers to see what has changed since the last code review. -[official Go documentation]: https://pkg.go.dev/std [forking]: https://help.github.com/articles/fork-a-repo -[go vet]: https://pkg.go.dev/cmd/vet -[gocov]: https://github.com/axw/gocov -[gocov-html]: https://github.com/matm/gocov-html [well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html -[squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits [pull request]: https://help.github.com/articles/creating-a-pull-request +[monitored by codecov.io]: https://codecov.io/gh/google/go-github + +## Scripts ## + +The `scripts` directory has shell scripts that help with common development +tasks. + +**scripts/fmt** formats all go code in the repository. + +**scripts/generate** runs code generators and `go mod tidy` on all modules. With +`--check` it checks that the generated files are current. + +**scripts/lint** runs linters on the project and checks generated files are +current. +**scripts/test** runs tests on all modules. ## Other notes on code organization ## @@ -144,5 +135,5 @@ this][modified-comment]. [rebase-comment]: https://github.com/google/go-github/pull/277#issuecomment-183035491 [modified-comment]: https://github.com/google/go-github/pull/280#issuecomment-184859046 -**When creating a release, don't forget to update the `Version` constant in `github.go`.** This is used to +**When creating a release, don't forget to update the `Version` constant in `github.go`.** This is used to send the version in the `User-Agent` header to identify clients to the GitHub API. From c437981c5d9a131f57a27e7583a3e53fc52e8bfd Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 11:26:43 -0500 Subject: [PATCH 11/20] Revert "Increase lint timeout" This reverts commit 7b50a4608b412691f525ce4c00e81a1259d125c2. --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index e814f27d76f..3e286f045f4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,4 @@ run: - timeout: 3m build-tags: - integration linters: From 35d0f24dc5f798c2182c6610aad7e627ffb65ef2 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 12:15:35 -0500 Subject: [PATCH 12/20] simplify scripts/lint --- scripts/lint | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/lint b/scripts/lint index e6dab3f113a..36054d1fdeb 100755 --- a/scripts/lint +++ b/scripts/lint @@ -23,12 +23,12 @@ for dir in $MOD_DIRS; do echo linting "$dir" ( cd "$dir" + cmd="$BIN/golangci-lint run --path-prefix '$dir'" + # github actions output when running in an action - if [ -n "$GITHUB_ACTIONS" ]; then - "$BIN"/golangci-lint run --path-prefix "$dir" --out-format github-actions - else - "$BIN"/golangci-lint run --path-prefix "$dir" - fi + [ -n "$GITHUB_ACTIONS" ] && cmd="$cmd --out-format github-actions" + + $cmd ) || FAILED=1 done From cfdcf72c0603ec87875cb6a3ed286b93f4d5007b Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 12:47:12 -0500 Subject: [PATCH 13/20] Revert "simplify scripts/lint" This reverts commit 35d0f24dc5f798c2182c6610aad7e627ffb65ef2. --- scripts/lint | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/lint b/scripts/lint index 36054d1fdeb..e6dab3f113a 100755 --- a/scripts/lint +++ b/scripts/lint @@ -23,12 +23,12 @@ for dir in $MOD_DIRS; do echo linting "$dir" ( cd "$dir" - cmd="$BIN/golangci-lint run --path-prefix '$dir'" - # github actions output when running in an action - [ -n "$GITHUB_ACTIONS" ] && cmd="$cmd --out-format github-actions" - - $cmd + if [ -n "$GITHUB_ACTIONS" ]; then + "$BIN"/golangci-lint run --path-prefix "$dir" --out-format github-actions + else + "$BIN"/golangci-lint run --path-prefix "$dir" + fi ) || FAILED=1 done From 4b2f8444bc6e57a4ae568da1b6ccbc713890d9a4 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 15 Sep 2023 12:50:57 -0500 Subject: [PATCH 14/20] remove redundant var --- scripts/lint | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/lint b/scripts/lint index e6dab3f113a..0fd102ea595 100755 --- a/scripts/lint +++ b/scripts/lint @@ -6,8 +6,7 @@ set -e GOLANGCI_LINT_VERSION="1.54.2" CDPATH="" cd -- "$(dirname -- "$0")/.." -REPO_DIR="$(pwd -P)" -BIN="$REPO_DIR"/bin +BIN="$(pwd -P)"/bin mkdir -p "$BIN" From c1836889cc8220f48e93c78468779d40c8869d66 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Mon, 18 Sep 2023 08:46:16 -0500 Subject: [PATCH 15/20] Set lint timeout to 10m --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 3e286f045f4..d1ec5b11c92 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,7 @@ run: build-tags: - integration + timeout: 10m linters: enable: - dogsled From 9c70c5500397178a71b929da56de6c7bc85698aa Mon Sep 17 00:00:00 2001 From: Will Roden Date: Mon, 18 Sep 2023 09:46:47 -0500 Subject: [PATCH 16/20] rename scripts to .sh --- .github/workflows/linter.yml | 2 +- .github/workflows/tests.yml | 4 ++-- .gitignore | 1 + CONTRIBUTING.md | 14 +++++++------- scripts/{fmt => fmt.sh} | 2 +- scripts/{generate => generate.sh} | 8 ++++---- scripts/{lint => lint.sh} | 4 ++-- scripts/{test => test.sh} | 2 +- 8 files changed, 19 insertions(+), 18 deletions(-) rename scripts/{fmt => fmt.sh} (75%) rename scripts/{generate => generate.sh} (82%) rename scripts/{lint => lint.sh} (89%) rename scripts/{test => test.sh} (80%) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index f466111d588..7ff479c87cc 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -13,4 +13,4 @@ jobs: with: go-version: 1.x cache-dependency-path: "**/go.sum" - - run: scripts/lint + - run: scripts/lint.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 063ff03666c..ee0dd9be677 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,10 +62,10 @@ jobs: - name: Run go test run: | if [ -n "${{ matrix.update-coverage }}" ]; then - scripts/test -race -covermode atomic -coverprofile coverage.txt ./... + scripts/test.sh -race -covermode atomic -coverprofile coverage.txt ./... exit fi - scripts/test -race -covermode atomic ./... + scripts/test.sh -race -covermode atomic ./... - name: Ensure integration tests build # don't actually run tests since they hit live GitHub API diff --git a/.gitignore b/.gitignore index 3a24427a962..b94f808fc42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.sh +!/scripts/*.sh *.test coverage.out /bin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62fcb4e2831..636ac290c46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,9 +51,9 @@ are more sensitive, emailed to . either add tests to cover those lines or add a PR comment explaining the untested lines. -4. Run `scripts/fmt`, `scripts/test` and `scripts/lint` to format your code and - check that it passes all tests and linters. `scripts/lint` may also tell you - that generated files need to be updated. If so, run `scripts/generate` to +4. Run `scripts/fmt.sh`, `scripts/test.sh` and `scripts/lint.sh` to format your code and + check that it passes all tests and linters. `scripts/lint.sh` may also tell you + that generated files need to be updated. If so, run `scripts/generate.sh` to update them. 5. Do your best to have [well-formed commit messages][] for each change. This @@ -75,15 +75,15 @@ are more sensitive, emailed to . The `scripts` directory has shell scripts that help with common development tasks. -**scripts/fmt** formats all go code in the repository. +**scripts/fmt.sh** formats all go code in the repository. -**scripts/generate** runs code generators and `go mod tidy` on all modules. With +**scripts/generate.sh** runs code generators and `go mod tidy` on all modules. With `--check` it checks that the generated files are current. -**scripts/lint** runs linters on the project and checks generated files are +**scripts/lint.sh** runs linters on the project and checks generated files are current. -**scripts/test** runs tests on all modules. +**scripts/test.sh** runs tests on all modules. ## Other notes on code organization ## diff --git a/scripts/fmt b/scripts/fmt.sh similarity index 75% rename from scripts/fmt rename to scripts/fmt.sh index e3891861370..ff58f982c80 100755 --- a/scripts/fmt +++ b/scripts/fmt.sh @@ -1,5 +1,5 @@ #!/bin/sh -#/ scripts/fmt runs go fmt on all go files in the project. +#/ scripts/fmt.sh runs go fmt on all go files in the project. set -e diff --git a/scripts/generate b/scripts/generate.sh similarity index 82% rename from scripts/generate rename to scripts/generate.sh index aa7d46aea82..5973e3cfca6 100755 --- a/scripts/generate +++ b/scripts/generate.sh @@ -1,6 +1,6 @@ #!/bin/sh -#/ scripts/generate runs go generate on all modules in this repo. -#/ `scripts/generate --check` checks that the generated files are up to date. +#/ scripts/generate.sh runs go generate on all modules in this repo. +#/ `scripts/generate.sh --check` checks that the generated files are up to date. set -e @@ -22,9 +22,9 @@ if [ "$1" = "--check" ]; then cd "$GENTEMP" git add . git -c user.name='bot' -c user.email='bot@localhost' commit -m "generate" -q --allow-empty - scripts/generate + scripts/generate.sh [ -z "$(git status --porcelain)" ] || { - msg="Generated files are out of date. Please run scripts/generate and commit the results" + msg="Generated files are out of date. Please run scripts/generate.sh and commit the results" if [ -n "$GITHUB_ACTIONS" ]; then echo "::error ::$msg" else diff --git a/scripts/lint b/scripts/lint.sh similarity index 89% rename from scripts/lint rename to scripts/lint.sh index 0fd102ea595..bf9073ba0e2 100755 --- a/scripts/lint +++ b/scripts/lint.sh @@ -1,5 +1,5 @@ #!/bin/sh -#/ scripts/lint runs linters and validates generated files. +#/ scripts/lint.sh runs linters and validates generated files. set -e @@ -31,7 +31,7 @@ for dir in $MOD_DIRS; do ) || FAILED=1 done -scripts/generate --check || FAILED=1 +scripts/generate.sh --check || FAILED=1 if [ -n "$FAILED" ]; then exit 1 diff --git a/scripts/test b/scripts/test.sh similarity index 80% rename from scripts/test rename to scripts/test.sh index 0c2878dd8f9..635212df7fa 100755 --- a/scripts/test +++ b/scripts/test.sh @@ -1,5 +1,5 @@ #!/bin/sh -#/ scripts/test runs tests on each go module in go-github. Arguments are passed to each go test invocation. +#/ scripts/test.sh runs tests on each go module in go-github. Arguments are passed to each go test invocation. #/ "-race -covermode atomic ./..." is used when no arguments are given. set -e From 88e38b162c4a83770e4538c6e5a8df2eca8d91fe Mon Sep 17 00:00:00 2001 From: Will Roden Date: Mon, 18 Sep 2023 11:04:03 -0500 Subject: [PATCH 17/20] TIL setup is not a verb --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 636ac290c46..f5c3b52111a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ are more sensitive, emailed to . that you are planning to work on that bug or feature so that it can be assigned to you. -2. Follow the normal process of [forking][] the project, and setup a new branch +2. Follow the normal process of [forking][] the project, and set up a new branch to work in. It's important that each group of changes be done in separate branches in order to ensure that a pull request only includes the commits related to that bug or feature. From e10408beffc20a48a20503a3d0bf982c7e9ed6b8 Mon Sep 17 00:00:00 2001 From: WillAbides <233500+WillAbides@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:04:30 -0500 Subject: [PATCH 18/20] Update CONTRIBUTING.md Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- CONTRIBUTING.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f5c3b52111a..e98e4f323ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,7 +63,10 @@ are more sensitive, emailed to . 6. Finally, push the commits to your fork and submit a [pull request][]. **NOTE:** Please do not use force-push on PRs in this repo, as it makes it more difficult for reviewers to see what has changed since the last code - review. + review. We always perform "squash and merge" actions on PRs in this repo, so it doesn't + matter how many commits your PR has, as they will end up being a single commit after merging. + This is done to make a much cleaner `git log` history and helps to find regressions in the code + using existing tools such as "git bisect". [forking]: https://help.github.com/articles/fork-a-repo [well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html From 503fad742b1b7135e90e301d830a32b4f170256b Mon Sep 17 00:00:00 2001 From: WillAbides <233500+WillAbides@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:11:45 -0500 Subject: [PATCH 19/20] Update CONTRIBUTING.md Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e98e4f323ac..409d235c0e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,7 +66,7 @@ are more sensitive, emailed to . review. We always perform "squash and merge" actions on PRs in this repo, so it doesn't matter how many commits your PR has, as they will end up being a single commit after merging. This is done to make a much cleaner `git log` history and helps to find regressions in the code - using existing tools such as "git bisect". + using existing tools such as `git bisect`. [forking]: https://help.github.com/articles/fork-a-repo [well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html From 13c9ed3d867e704187bd8788a956f41a1e26ee42 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 21 Sep 2023 07:25:46 -0500 Subject: [PATCH 20/20] mv scripts script --- .github/workflows/linter.yml | 2 +- .github/workflows/tests.yml | 4 ++-- .gitignore | 2 +- CONTRIBUTING.md | 16 ++++++++-------- {scripts => script}/fmt.sh | 2 +- {scripts => script}/generate.sh | 8 ++++---- {scripts => script}/lint.sh | 4 ++-- {scripts => script}/test.sh | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) rename {scripts => script}/fmt.sh (75%) rename {scripts => script}/generate.sh (77%) rename {scripts => script}/lint.sh (89%) rename {scripts => script}/test.sh (80%) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 7ff479c87cc..98a1f5de8be 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -13,4 +13,4 @@ jobs: with: go-version: 1.x cache-dependency-path: "**/go.sum" - - run: scripts/lint.sh + - run: script/lint.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ee0dd9be677..b3abd8b6f92 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,10 +62,10 @@ jobs: - name: Run go test run: | if [ -n "${{ matrix.update-coverage }}" ]; then - scripts/test.sh -race -covermode atomic -coverprofile coverage.txt ./... + script/test.sh -race -covermode atomic -coverprofile coverage.txt ./... exit fi - scripts/test.sh -race -covermode atomic ./... + script/test.sh -race -covermode atomic ./... - name: Ensure integration tests build # don't actually run tests since they hit live GitHub API diff --git a/.gitignore b/.gitignore index b94f808fc42..0c803b53aa6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.sh -!/scripts/*.sh +!/script/*.sh *.test coverage.out /bin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 409d235c0e2..451924ce4c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,9 +51,9 @@ are more sensitive, emailed to . either add tests to cover those lines or add a PR comment explaining the untested lines. -4. Run `scripts/fmt.sh`, `scripts/test.sh` and `scripts/lint.sh` to format your code and - check that it passes all tests and linters. `scripts/lint.sh` may also tell you - that generated files need to be updated. If so, run `scripts/generate.sh` to +4. Run `script/fmt.sh`, `script/test.sh` and `script/lint.sh` to format your code and + check that it passes all tests and linters. `script/lint.sh` may also tell you + that generated files need to be updated. If so, run `script/generate.sh` to update them. 5. Do your best to have [well-formed commit messages][] for each change. This @@ -75,18 +75,18 @@ are more sensitive, emailed to . ## Scripts ## -The `scripts` directory has shell scripts that help with common development +The `script` directory has shell scripts that help with common development tasks. -**scripts/fmt.sh** formats all go code in the repository. +**script/fmt.sh** formats all go code in the repository. -**scripts/generate.sh** runs code generators and `go mod tidy` on all modules. With +**script/generate.sh** runs code generators and `go mod tidy` on all modules. With `--check` it checks that the generated files are current. -**scripts/lint.sh** runs linters on the project and checks generated files are +**script/lint.sh** runs linters on the project and checks generated files are current. -**scripts/test.sh** runs tests on all modules. +**script/test.sh** runs tests on all modules. ## Other notes on code organization ## diff --git a/scripts/fmt.sh b/script/fmt.sh similarity index 75% rename from scripts/fmt.sh rename to script/fmt.sh index ff58f982c80..20ff6e69254 100755 --- a/scripts/fmt.sh +++ b/script/fmt.sh @@ -1,5 +1,5 @@ #!/bin/sh -#/ scripts/fmt.sh runs go fmt on all go files in the project. +#/ script/fmt.sh runs go fmt on all go files in the project. set -e diff --git a/scripts/generate.sh b/script/generate.sh similarity index 77% rename from scripts/generate.sh rename to script/generate.sh index 5973e3cfca6..17707b2385c 100755 --- a/scripts/generate.sh +++ b/script/generate.sh @@ -1,6 +1,6 @@ #!/bin/sh -#/ scripts/generate.sh runs go generate on all modules in this repo. -#/ `scripts/generate.sh --check` checks that the generated files are up to date. +#/ script/generate.sh runs go generate on all modules in this repo. +#/ `script/generate.sh --check` checks that the generated files are up to date. set -e @@ -22,9 +22,9 @@ if [ "$1" = "--check" ]; then cd "$GENTEMP" git add . git -c user.name='bot' -c user.email='bot@localhost' commit -m "generate" -q --allow-empty - scripts/generate.sh + script/generate.sh [ -z "$(git status --porcelain)" ] || { - msg="Generated files are out of date. Please run scripts/generate.sh and commit the results" + msg="Generated files are out of date. Please run script/generate.sh and commit the results" if [ -n "$GITHUB_ACTIONS" ]; then echo "::error ::$msg" else diff --git a/scripts/lint.sh b/script/lint.sh similarity index 89% rename from scripts/lint.sh rename to script/lint.sh index bf9073ba0e2..af5ae991006 100755 --- a/scripts/lint.sh +++ b/script/lint.sh @@ -1,5 +1,5 @@ #!/bin/sh -#/ scripts/lint.sh runs linters and validates generated files. +#/ script/lint.sh runs linters and validates generated files. set -e @@ -31,7 +31,7 @@ for dir in $MOD_DIRS; do ) || FAILED=1 done -scripts/generate.sh --check || FAILED=1 +script/generate.sh --check || FAILED=1 if [ -n "$FAILED" ]; then exit 1 diff --git a/scripts/test.sh b/script/test.sh similarity index 80% rename from scripts/test.sh rename to script/test.sh index 635212df7fa..23e6a0c8f84 100755 --- a/scripts/test.sh +++ b/script/test.sh @@ -1,5 +1,5 @@ #!/bin/sh -#/ scripts/test.sh runs tests on each go module in go-github. Arguments are passed to each go test invocation. +#/ script/test.sh runs tests on each go module in go-github. Arguments are passed to each go test invocation. #/ "-race -covermode atomic ./..." is used when no arguments are given. set -e