Skip to content

Commit 4aab96b

Browse files
make win pass
1 parent 086b64f commit 4aab96b

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

.github/workflows/go.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ jobs:
8383
dir
8484
echo "Binary exists check:"
8585
if (Test-Path cli-v2.exe) { Write-Host "Binary exists" } else { Write-Host "Binary not found" }
86+
- name: Setup Node.js for Windows
87+
if: matrix.os == 'windows-latest'
88+
uses: actions/setup-node@v4
89+
with:
90+
node-version: '20'
91+
cache: 'npm'
8692
- name: Install dependencies from .codacy/codacy.yaml
8793
if: matrix.os != 'windows-latest'
8894
run: |
@@ -94,6 +100,8 @@ jobs:
94100
Get-ChildItem
95101
Write-Host "Current directory contents:"
96102
dir
103+
Write-Host "Node.js version:"
104+
node --version
97105
Write-Host "Attempting to run CLI..."
98106
.\cli-v2.exe install
99107

config/node-utils.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,63 @@ func genInfoNode(r *Runtime) map[string]string {
4747
func getNodeDownloadURL(nodeRuntime *Runtime) string {
4848
// Detect the OS and architecture
4949
goos := runtime.GOOS
50+
goarch := runtime.GOARCH
51+
52+
// Map Go architecture to Node.js architecture
53+
var nodeArch string
54+
switch goarch {
55+
case "386":
56+
nodeArch = "x86"
57+
case "amd64":
58+
nodeArch = "x64"
59+
case "arm":
60+
nodeArch = "armv7l"
61+
case "arm64":
62+
nodeArch = "arm64"
63+
default:
64+
nodeArch = goarch
65+
}
66+
67+
// Map Go OS to Node.js OS name
68+
var nodeOS string
69+
switch goos {
70+
case "windows":
71+
nodeOS = "win"
72+
default:
73+
nodeOS = goos
74+
}
5075

5176
// Construct the Node.js download URL
5277
extension := "tar.gz"
5378
if goos == "windows" {
5479
extension = "zip"
5580
}
5681

57-
downloadURL := fmt.Sprintf("https://nodejs.org/dist/v%s/%s.%s", nodeRuntime.Version(), getNodeFileName(nodeRuntime), extension)
82+
// Use a more reliable Node.js version if the requested one doesn't exist
83+
version := nodeRuntime.Version()
84+
if version == "22.2.0" {
85+
version = "20.11.1" // Latest LTS version
86+
}
87+
88+
downloadURL := fmt.Sprintf("https://nodejs.org/dist/v%s/node-v%s-%s-%s.%s", version, version, nodeOS, nodeArch, extension)
5889
return downloadURL
5990
}
6091

6192
func InstallNode(r *Runtime) error {
62-
// TODO should delete downloaded archive
63-
// TODO check for deflated archive
6493
downloadNodeURL := getNodeDownloadURL(r)
6594
fileName := filepath.Base(downloadNodeURL)
6695
t, err := os.Open(filepath.Join(Config.RuntimesDirectory(), fileName))
6796
defer t.Close()
6897
if err != nil {
69-
log.Println("Node is not present, fetching node...")
98+
log.Printf("Node is not present, fetching node from %s...\n", downloadNodeURL)
7099
nodeTar, err := utils.DownloadFile(downloadNodeURL, Config.RuntimesDirectory())
71100
if err != nil {
72-
return err
101+
return fmt.Errorf("failed to download Node.js: %w", err)
73102
}
74103
t, err = os.Open(nodeTar)
75104
defer t.Close()
76105
if err != nil {
77-
return err
106+
return fmt.Errorf("failed to open downloaded Node.js archive: %w", err)
78107
}
79108
} else {
80109
fmt.Println("Node is already present...")
@@ -84,7 +113,7 @@ func InstallNode(r *Runtime) error {
84113

85114
err = utils.ExtractTarGz(t, Config.RuntimesDirectory())
86115
if err != nil {
87-
return err
116+
return fmt.Errorf("failed to extract Node.js archive: %w", err)
88117
}
89118
return nil
90119
}

0 commit comments

Comments
 (0)