Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Add repo-infra scripts to verify go source code #167

Merged
merged 3 commits into from Jan 11, 2018

Conversation

font
Copy link
Contributor

@font font commented Jan 6, 2018

Adding scripts from repo-infra to help verify go source code. It would be best to vendor in the scripts to execute them directly, but we are blocked on golang/dep#1306.

The first commit adds the scripts and the second commit fixes the errors.

This can be followed up with a prow job.

/sig multicluster

@k8s-ci-robot k8s-ci-robot added sig/multicluster Categorizes an issue or PR as relevant to SIG Multicluster. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 6, 2018
Copy link
Contributor

@perotinus perotinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this!

@@ -0,0 +1,111 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this script runs all the other scripts. Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It runs all the scripts in hack/go-tools/, which right now is just the two being added in this PR. The exact arguments will be ./hack/verify-go-src.sh -v --rootdir $(pwd), which I can add as a new prow job. So we can have the existing prow job to verify all the generated code, and a new prow job to verify all the go source code. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that seems reasonable to me.

# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: set -euo pipefail is more consistent with the rest of the other scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,20 @@
#!/bin/bash
# Copyright 2017 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018

set -o nounset
set -o pipefail

find_files() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this use $(go list ./... | grep -v /vendor/) like the vet script below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because go vet takes a list of packages which is provided by go list, whereas gofmt takes paths to Go source files.

@font
Copy link
Contributor Author

font commented Jan 9, 2018

@perotinus Updated based on comments and added a section to the development doc on how to run these. PTAL.

Copy link
Contributor

@perotinus perotinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me; just a few more nits before I LGTM.


To verify and fix your Go source files:

1. Run `./hack/verify-go-src.sh -v --rootdir $(pwd)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain where you need to run this from to get pwd to work properly? I assume you have to be in the repo root.



SILENT=true
REPO_ROOT=$(dirname "${BASH_SOURCE}")/../..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BASH_SOURCE[0]

}

if ${SILENT} ; then
echo "Running in the silent mode, run with -v if you want to see script logs."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... in silent mode ...

@perotinus
Copy link
Contributor

@font Can you address the comments I made so we can get this in? It would be nice to have it running on PR submissions.

@font
Copy link
Contributor Author

font commented Jan 11, 2018

@perotinus Oh sorry, the comments were addressed in my last push on Monday. I should have notified you.

@perotinus
Copy link
Contributor

@font Oh, sorry! I should have looked more closely at the patches...

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 11, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: font, perotinus

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 6fce5ea into kubernetes-retired:master Jan 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. sig/multicluster Categorizes an issue or PR as relevant to SIG Multicluster. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants