Skip to content

Commit bb588f8

Browse files
Merge pull request #11 from andreimerlescu/hotfix/shim-test
Added support for parsing cwd/pwd go.mod for igo -cmd use the shim
2 parents ace4ec1 + 3edac0d commit bb588f8

26 files changed

Lines changed: 2357 additions & 184 deletions

.github/workflows/test-igo.yml

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- master
7-
- 'hotfix/**'
87
pull_request:
98
branches: [ master, develop, 'release/**' ]
109
workflow_dispatch:
@@ -39,6 +38,38 @@ jobs:
3938
source .github/workflows/scripts/check_version.sh
4039
shell: bash
4140

41+
test-go-package:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: 1.24.2
49+
50+
- name: Install dependencies
51+
run: |
52+
go mod download
53+
go mod tidy
54+
go mod vendor
55+
shell: bash
56+
57+
- uses: actions/cache@v3
58+
with:
59+
path: |
60+
~/.cache/go-build
61+
~/go/pkg/mod
62+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
63+
restore-keys: |
64+
${{ runner.os }}-go-
65+
66+
- name: Test
67+
run: |
68+
set -euo pipefail
69+
go test -v ./...
70+
shell: bash
71+
72+
4273
release-check:
4374
if: startsWith(github.ref, 'refs/heads/release/') || inputs.create_release || inputs.promote_to_master
4475
runs-on: ubuntu-latest
@@ -134,6 +165,7 @@ jobs:
134165
135166
136167
168+
137169
test-linux:
138170
needs: version-check
139171
runs-on: ${{ matrix.os }}
@@ -169,9 +201,11 @@ jobs:
169201
go build -o igo
170202
chmod +x igo
171203
export PATH=$PATH:$(pwd)
172-
chmod +x ./tester.sh
204+
chmod +x ./testing/tester.sh
173205
touch .profile
174-
./tester.sh
206+
rm go.mod
207+
rm go.sum
208+
./testing/tester.sh
175209
shell: bash
176210

177211
test-macos:
@@ -216,7 +250,9 @@ jobs:
216250
go build -o igo
217251
chmod +x igo
218252
export PATH=$PATH:$(pwd)
219-
chmod +x ./tester.sh
253+
chmod +x ./testing/tester.sh
254+
rm go.mod
255+
rm go.sum
220256
touch ~/.profile
221-
./tester.sh --verbose true --debug true
257+
./testing/tester.sh --verbose true --debug true
222258
shell: bash

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.idea
22
summaries
33
*.log
4-
!test_results/test-sh-*.log
4+
!testing/results/*.log
55
igo
66
bin/*
77

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN chown -R tester:tester /home/tester
1616

1717
COPY --from=builder /bin/igo /bin/igo
1818
ENV PATH=/bin
19-
COPY tester.sh /home/tester/tester.sh
19+
COPY testing/*.sh /home/tester/
2020
RUN chmod +x /bin/igo /home/tester/tester.sh
2121
USER tester
2222
WORKDIR /home/tester

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.0.1
1+
v1.0.2

application.go

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"embed"
66
"fmt"
77
"io/fs"
8+
"net/http"
89
"os"
910
"os/exec"
1011
"path/filepath"
12+
"regexp"
13+
"runtime"
1114
"strings"
1215

1316
"github.com/andreimerlescu/figtree/v2"
@@ -24,23 +27,90 @@ type Application struct {
2427
ctx context.Context
2528
figs figtree.Plant
2629
userHomeDir string
30+
Workspace func() string
2731
}
2832

33+
var UserHomeDir = os.UserHomeDir
34+
2935
func NewApp() *Application {
30-
userHomeDir, err := os.UserHomeDir()
36+
userHomeDir, err := UserHomeDir()
3137
capture(err)
32-
return &Application{
38+
app := &Application{
3339
ctx: context.Background(),
3440
userHomeDir: userHomeDir,
3541
}
42+
app.Workspace = func() string {
43+
if *app.figs.Bool(kSystem) {
44+
return filepath.Join("/", "usr", "go")
45+
}
46+
return filepath.Join(app.userHomeDir, "go")
47+
}
48+
app.figs = figtree.With(figtree.Options{
49+
ConfigFile: filepath.Join(app.userHomeDir, ".igo.config.yml"),
50+
Germinate: true,
51+
Harvest: 0,
52+
})
53+
app.figs.NewBool(kVersion, false, "Display current version")
54+
app.figs.NewBool(kSystem, false, "Install for system-wide usage (ignore USER HOME directory)")
55+
app.figs.NewBool(kDebug, false, "Enable debug mode")
56+
app.figs.NewBool(kVerbose, false, "Enable verbose mode")
57+
app.figs.NewString(kGoDir, filepath.Join(app.userHomeDir, "go"), "Path where you want multiple go versions installed")
58+
app.figs.NewString(kCommand, "", "Command to run: install uninstall use list")
59+
app.figs.NewString(kGoVersion, "1.24.3", "Go Version")
60+
app.figs.WithValidator(kGoVersion, func(value interface{}) error {
61+
v := figtree.NewFlesh(value).ToString()
62+
if err := app.validateVersion(v); err != nil {
63+
return err
64+
}
65+
return nil
66+
})
67+
app.figs.NewString(kGoos, runtime.GOOS, "Go OS")
68+
app.figs.NewString(kGoArch, runtime.GOARCH, "Go Architecture")
69+
app.figs.NewBool(kExtras, true, "Install extra packages")
70+
app.figs.NewMap(kExtraPackages, packages, "Extra packages to install")
71+
_, err = os.Lstat(figtree.ConfigFilePath)
72+
if os.IsNotExist(err) || os.IsPermission(err) {
73+
capture(app.figs.Parse())
74+
} else {
75+
capture(app.figs.Load())
76+
}
77+
return app
3678
}
3779

38-
// Workspace provides the path to where igo is installed
39-
func (app *Application) Workspace() string {
40-
if *app.figs.Bool(kSystem) {
41-
return filepath.Join("/", "usr", "go")
80+
// Add this function to application.go to validate Go version formats
81+
func (app *Application) validateVersion(version string) error {
82+
// Basic format check with regex
83+
if !regexp.MustCompile(`^\d+\.\d+\.\d+$`).MatchString(version) {
84+
return fmt.Errorf("invalid go version format: %s (expected format: X.Y.Z)", version)
85+
}
86+
87+
// Parse version parts to check they're valid numbers
88+
var major, minor, patch int
89+
_, err := fmt.Sscanf(version, "%d.%d.%d", &major, &minor, &patch)
90+
if err != nil {
91+
return fmt.Errorf("error parsing version components: %w", err)
92+
}
93+
94+
// Optional: Add constraints on minimum supported versions
95+
if major < 1 || (major == 1 && minor < 16) {
96+
return fmt.Errorf("go version %s is not supported (minimum: 1.16.0)", version)
97+
}
98+
99+
// Verify the version exists on Go's download server before proceeding
100+
// Using a HEAD request to check if the URL exists
101+
resp, err := httpHead(fmt.Sprintf("https://go.dev/dl/go%s.%s-%s.tar.gz",
102+
version, *app.figs.String(kGoos), *app.figs.String(kGoArch)))
103+
if err != nil {
104+
return fmt.Errorf("error checking if version exists: %w", err)
105+
}
106+
defer resp.Body.Close()
107+
108+
if resp.StatusCode != http.StatusOK {
109+
return fmt.Errorf("go version %s not found on download server (status: %d)",
110+
version, resp.StatusCode)
42111
}
43-
return filepath.Join(app.userHomeDir, "go")
112+
113+
return nil
44114
}
45115

46116
// CreateShims creates the shims for go and gofmt

0 commit comments

Comments
 (0)