Skip to content

Commit 6e8e94d

Browse files
fix(release): fix completion generation on windows (#1391) (#1392)
The GitHub action that does the release actually runs on Windows (likely makes publishing to Choco easier?). The changes to add completions for Homebrew caused errors during release because I had assumed a *nix like runtime environment for the GHA `release` job (incorrectly). This replaces the shell script with a tiny go script that is platform agnostic. --- Note: like the other changes, I am unable to test this myself (due to a private repo being referenced in `go.mod`). In order to test the new script, you should be able to run `go run scripts/generate.go` (which is what is done in the `.goreleaser.yaml` file). Co-authored-by: Robert Jackson <[email protected]>
1 parent 2e15810 commit 6e8e94d

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

.goreleaser.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ before:
77
- go mod tidy
88
# you may remove this if you don't need go generate
99
- go generate ./...
10-
- ./scripts/completions.sh
10+
- go run scripts/completions.go
1111
builds:
1212
- env:
1313
- CGO_ENABLED=0

scripts/completions.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
)
9+
10+
func main() {
11+
// Remove existing completions directory
12+
os.RemoveAll("completions")
13+
14+
// Create new completions directory
15+
err := os.Mkdir("completions", 0755)
16+
if err != nil {
17+
fmt.Fprintf(os.Stderr, "Error creating completions directory: %v\n", err)
18+
os.Exit(1)
19+
}
20+
21+
// Generate completions for different shells
22+
shells := []string{"bash", "zsh", "fish"}
23+
for _, shell := range shells {
24+
outputFile := filepath.Join("completions", "speakeasy."+shell)
25+
cmd := exec.Command("go", "run", "main.go", "completion", shell)
26+
output, err := cmd.Output()
27+
if err != nil {
28+
fmt.Fprintf(os.Stderr, "Error generating %s completion: %v\n", shell, err)
29+
os.Exit(1)
30+
}
31+
32+
err = os.WriteFile(outputFile, output, 0644)
33+
if err != nil {
34+
fmt.Fprintf(os.Stderr, "Error writing to %s: %v\n", outputFile, err)
35+
os.Exit(1)
36+
}
37+
}
38+
}

scripts/completions.sh

-7
This file was deleted.

0 commit comments

Comments
 (0)