File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed
.github/workflows/samples-tools Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ For example:
3030
3131 // Skip these packages, these could be handled by a different config.
3232 // Defaults to not exclude anything.
33- " exclude-packages" : [" path/to/slow-to-test" , " special-config-package" ]
33+ " exclude-packages" : [" path/to/slow-to-test" , " special-config-package" ],
3434}
3535```
3636
@@ -60,6 +60,7 @@ git --no-pager diff --name-only HEAD origin/main | tee /tmp/diffs.txt
6060```
6161
6262Now we can check which packages have been affected.
63+ We pass the config file and the diffs file as positional arguments.
6364
6465``` sh
6566/tmp/tools affected .github/config/nodejs.jsonc /tmp/diffs.txt
@@ -68,3 +69,12 @@ Now we can check which packages have been affected.
6869## Running on all packages
6970
7071> This must run at the repository root directory.
72+
73+ We pass the config file and a bash script to run as positional arguments.
74+ The script must receive a single positional argument in ` $1 ` as the package name.
75+ For example, the script should be called like ` bash path/to/my-script.sh path/to/package ` .
76+
77+ ``` sh
78+ # To run all the Node.js tests.
79+ /tmp/tools run-all ./github/config/nodejs.jsonc ./github/scripts/nodejs-test.sh
80+ ```
Original file line number Diff line number Diff line change @@ -21,33 +21,27 @@ import (
2121 "os"
2222 "os/exec"
2323 "strings"
24+ "sync/atomic"
2425)
2526
2627// runAll runs all the commands in parallel.
27- func runAll (packages []string , script string , maxGoroutines int ) int {
28- failures := make ([] string , len ( packages ))
28+ func runAll (packages []string , script string , maxGoroutines int ) int64 {
29+ var failures int64
2930 guard := make (chan struct {}, maxGoroutines )
30- for i , pkg := range packages {
31+ for _ , pkg := range packages {
3132 guard <- struct {}{} // block if channel is filled
3233 go func () {
3334 output , err := exec .Command ("bash" , script , pkg ).CombinedOutput ()
3435 if err != nil {
3536 printError (os .Stderr , pkg , err , string (output ))
36- failures [ i ] = pkg
37+ atomic . AddInt64 ( & failures , 1 )
3738 } else {
3839 fmt .Printf ("✅ %v\n " , pkg )
3940 }
4041 <- guard
4142 }()
4243 }
43-
44- failed := 0
45- for _ , failure := range failures {
46- if failure != "" {
47- failed ++
48- }
49- }
50- return failed
44+ return failures
5145}
5246
5347func printError (f * os.File , pkg string , err error , output string ) {
You can’t perform that action at this time.
0 commit comments