Skip to content

Commit

Permalink
feat: make action fail if broken links are present
Browse files Browse the repository at this point in the history
  • Loading branch information
nprimo committed Mar 26, 2024
1 parent 587404e commit 3eacafd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test-ga.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Test local version with multiple paths
uses: ./
with:
filepath: ${{env.MULTIPLE_FPATH}}

- name: Prepare GITHUB_OUTPUT
- name: Prepare GITHUB_OUTPUT
id: files_to_check
run: |
echo "fpaths=$(find ./mock_public/ -name *.md | xargs)" >> $GITHUB_OUTPUT
echo "fpaths=$(find ./mock_public/ -name "*.md" -print0)" >> "$GITHUB_OUTPUT"
- name: Test local version with GITHUB_OUTPUT
uses: ./
with:
Expand Down
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type LinkChecker struct {
func checkFilePath(filePath string) ([]LinkChecker, error) {
cont, err := os.ReadFile(filePath)
if err != nil {
// TODO: is there a better way than printing out to handle err?
// Should I stop for any reason?
// TODO: is there a better way than printing out to handle err?
// Should I stop for any reason?
log.Printf("Error reading %s: %v", filePath, err)
return nil, err
}
Expand Down Expand Up @@ -95,11 +95,16 @@ func main() {
res <- fileChecker
}(filePath)
}
brokenLinksCount := 0
for range filePaths {
for _, check := range <-res {
if check.StatusCode != 200 {
log.Printf("(%s): %s -> %d\n", check.FilePath, check.Link, check.StatusCode)
brokenLinksCount++
}
}
}
if brokenLinksCount != 0 {
log.Fatalf("Found %d broken links!", brokenLinksCount)
}
}

0 comments on commit 3eacafd

Please sign in to comment.