Skip to content

Commit 88db214

Browse files
committed
Add new command
1 parent b04d8b5 commit 88db214

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

.github/workflows/checks.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,21 @@ jobs:
4747
name: playground-logs-${{ matrix.flags }}
4848
path: /tmp/playground-logs
4949
retention-days: 5
50+
51+
artifacts:
52+
name: Artifacts
53+
strategy:
54+
matrix:
55+
os: [ubuntu-latest, macos-13]
56+
runs-on: ${{ matrix.os }}
57+
steps:
58+
- name: Check out code
59+
uses: actions/checkout@v2
60+
61+
- name: Set up Go
62+
uses: actions/setup-go@v2
63+
with:
64+
go-version: 1.24
65+
66+
- name: Download and test artifacts
67+
run: go run main.go artifacts-all

internal/catalog.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package internal
22

3-
var components = []Service{}
3+
var Components = []Service{}
44

55
func register(component Service) {
6-
components = append(components, component)
6+
Components = append(Components, component)
77
}
88

99
func init() {
@@ -20,7 +20,7 @@ func init() {
2020
}
2121

2222
func FindComponent(name string) Service {
23-
for _, component := range components {
23+
for _, component := range Components {
2424
if component.Name() == name {
2525
return component
2626
}

main.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log"
88
"os"
9+
"os/exec"
910
"os/signal"
1011
"sort"
1112
"strings"
@@ -78,6 +79,40 @@ var artifactsCmd = &cobra.Command{
7879
},
7980
}
8081

82+
var artifactsAllCmd = &cobra.Command{
83+
Use: "artifacts-all",
84+
Short: "Download all the artifacts available in the catalog (Used for testing purposes)",
85+
RunE: func(cmd *cobra.Command, args []string) error {
86+
fmt.Println("Downloading all artifacts...")
87+
88+
output := outputFlag
89+
if output == "" {
90+
homeDir, err := internal.GetHomeDir()
91+
if err != nil {
92+
return fmt.Errorf("failed to get home directory: %w", err)
93+
}
94+
output = homeDir
95+
}
96+
for _, component := range internal.Components {
97+
releaseService, ok := component.(internal.ReleaseService)
98+
if !ok {
99+
continue
100+
}
101+
location, err := internal.DownloadRelease(output, releaseService.ReleaseArtifact())
102+
if err != nil {
103+
return fmt.Errorf("failed to download release: %w", err)
104+
}
105+
106+
// make sure the artifact is valid to be executed on this platform
107+
log.Printf("Downloaded %s to %s\n", releaseService.ReleaseArtifact().Name, location)
108+
if err := isExecutableValid(location); err != nil {
109+
return fmt.Errorf("failed to check if artifact is valid: %w", err)
110+
}
111+
}
112+
return nil
113+
},
114+
}
115+
81116
var recipes = []internal.Recipe{
82117
&internal.L1Recipe{},
83118
&internal.OpRecipe{},
@@ -110,9 +145,11 @@ func main() {
110145

111146
// reuse the same output flag for the artifacts command
112147
artifactsCmd.Flags().StringVar(&outputFlag, "output", "", "Output folder for the artifacts")
148+
artifactsAllCmd.Flags().StringVar(&outputFlag, "output", "", "Output folder for the artifacts")
113149

114150
rootCmd.AddCommand(cookCmd)
115151
rootCmd.AddCommand(artifactsCmd)
152+
rootCmd.AddCommand(artifactsAllCmd)
116153

117154
if err := rootCmd.Execute(); err != nil {
118155
fmt.Println(err)
@@ -231,3 +268,26 @@ func runIt(recipe internal.Recipe) error {
231268
}
232269
return nil
233270
}
271+
272+
func isExecutableValid(path string) error {
273+
// First check if file exists
274+
_, err := os.Stat(path)
275+
if err != nil {
276+
return fmt.Errorf("file does not exist or is inaccessible: %w", err)
277+
}
278+
279+
// Try to execute with a harmless flag or in a way that won't run the main program
280+
cmd := exec.Command(path, "--version")
281+
// Redirect output to /dev/null
282+
cmd.Stdout = nil
283+
cmd.Stderr = nil
284+
285+
if err := cmd.Start(); err != nil {
286+
return fmt.Errorf("cannot start executable: %w", err)
287+
}
288+
289+
// Immediately kill the process since we just want to test if it starts
290+
cmd.Process.Kill()
291+
292+
return nil
293+
}

0 commit comments

Comments
 (0)