Skip to content

Commit

Permalink
feat: update GA to receive multiple fpath separated by space as input
Browse files Browse the repository at this point in the history
- update test-ga to have local tests for new feature
  • Loading branch information
nprimo committed Mar 25, 2024
1 parent b04ad77 commit 811e3c1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/test-ga.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
name: Test GA

env:
MULTIPLE_FPATH: mock_public/prj_01/README.md mock_public/prj_02/README.md

on:
workflow_call:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test local version
- name: Test local version with multiple paths
uses: ./
with:
filepath: mock_public/prj_01/README.md
- name: Test public latest
uses: nprimo/[email protected]
filepath: ${{env.MULTIPLE_FPATH}}

- name: Prepare GITHUB_OUTPUT
id: files_to_check
run: |
echo "fpaths=$(find ./mock_public/ -name *.md | xargs)" >> $GITHUB_OUTPUT
- name: Test local version with GITHUB_OUTPUT
uses: ./
with:
filepath: mock_public/prj_01/README.md
filepath: ${{ steps.files_to_check.outputs.fpaths }}
43 changes: 26 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,37 @@ func checkLink(link string) int {
}

func main() {
filePath, ok := os.LookupEnv("INPUT_FILEPATH")
input, ok := os.LookupEnv("INPUT_FILEPATH")
if !ok {
return
}
filePaths := strings.Split(input, " ")
done := make(chan bool)
for _, filePath := range filePaths {
go func() {
cont, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Error reading %s: %v", filePath, err)
}

cont, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Error reading %s: %v", filePath, err)
}

links := getLinks(cont)
ch := make(chan map[string]int)
for _, link := range links {
go func(text string) { ch <- map[string]int{link: checkLink(link)} }(link)
}
links := getLinks(cont)
ch := make(chan map[string]int)
for _, link := range links {
go func(text string) { ch <- map[string]int{link: checkLink(link)} }(link)
}

for range links {
for link, status := range <-ch {
if status != 200 {
fmt.Printf(
"(%s): %q -> status %d\n", filePath, link, status)
for range links {
for link, status := range <-ch {
if status != 200 {
fmt.Printf(
"(%s): %q -> status %d\n", filePath, link, status)
}
}
}
}
done <- true
}()
}
for range filePaths {
<-done
}
}

0 comments on commit 811e3c1

Please sign in to comment.