-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Rewrite verify_readmes.sh script in Go #6598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmathieu
merged 7 commits into
open-telemetry:main
from
eliottness:verify_readmes-in-go
Apr 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d1dbbf2
Rewrite verify_readmes.sh script in Go
eliottness 16ac7ea
Suggestions from @pellared and @andriisoldatenko
eliottness a11488c
Merge branch 'main' into verify_readmes-in-go
eliottness b91a441
Force all readme filenames to be exactly README.md (following @pellar…
eliottness be3676a
Merge branch 'main' into verify_readmes-in-go
eliottness af4aab0
Update internal/tools/verifyreadmes/main.go
dmathieu 1543ef9
Merge branch 'main' into verify_readmes-in-go
dmathieu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package verifyreadmes is used to verify that all go modules in the repository | ||
// have a README.md file. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// excludedDirs is a list of directories to exclude from the README check if the full path contains any of these strings. | ||
var excludedDirs = []string{ | ||
"internal", | ||
"test", | ||
"example", | ||
"/.", | ||
} | ||
|
||
// verifyReadme is a [os.WalkFunc] that checks if a README.md exists in the same directory as the go.mod file. | ||
func verifyReadme(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !info.Mode().IsRegular() || info.Name() != "go.mod" { | ||
return nil | ||
|
||
} | ||
|
||
for _, dir := range excludedDirs { | ||
if strings.Contains(path, dir) { | ||
return nil | ||
} | ||
} | ||
|
||
// Check that a README.md exists in the same directory as the go.mod file. | ||
readme := filepath.Join(filepath.Dir(path), "README.md") | ||
pellared marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, err = os.Stat(readme) | ||
if os.IsNotExist(err) { | ||
err = fmt.Errorf("couldn't find README.md for %q", filepath.Dir(path)) | ||
dmathieu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return err | ||
|
||
} | ||
|
||
func main() { | ||
root, err := os.Getwd() | ||
if len(os.Args) == 2 { | ||
root, err = filepath.Abs(os.Args[1]) | ||
} | ||
|
||
if err != nil { | ||
fmt.Println("Error: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("Verifying READMEs in", root) | ||
|
||
var errs []string | ||
filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { | ||
err = verifyReadme(path, info, err) | ||
if err != nil { | ||
errs = append(errs, err.Error()) | ||
} | ||
eliottness marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil // continue walking | ||
}) | ||
|
||
if len(errs) == 0 { | ||
return | ||
} | ||
|
||
fmt.Println("Error: some READMEs couldn't be found.") | ||
fmt.Println(strings.Join(errs, "\n")) | ||
os.Exit(1) | ||
eliottness marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.