Skip to content

Commit 97ed6f5

Browse files
committed
Refactor error handling in main.go and README.md to log errors without terminating the program. Update GitHub Actions workflow to support multi-OS builds and include ONNX Runtime DLL in artifacts.
1 parent ae03025 commit 97ed6f5

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

.github/workflows/release.yml

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ permissions:
99
contents: write
1010

1111
jobs:
12-
build-and-release:
13-
runs-on: ubuntu-latest
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
include:
17+
- os: ubuntu-latest
18+
goos: linux
19+
goarch: amd64
20+
- os: windows-latest
21+
goos: windows
22+
goarch: amd64
1423
steps:
1524
- name: Checkout
1625
uses: actions/checkout@v4
@@ -22,19 +31,61 @@ jobs:
2231
with:
2332
go-version-file: go.mod
2433

25-
- name: Build artifacts
34+
- name: Prepare dist
35+
run: mkdir -p dist
36+
37+
- name: Download ONNX Runtime (windows only)
38+
if: matrix.goos == 'windows'
39+
shell: pwsh
40+
run: |
41+
$ver="1.22.0"
42+
$url="https://github.com/microsoft/onnxruntime/releases/download/v$ver/onnxruntime-win-x64-$ver.zip"
43+
Invoke-WebRequest -Uri $url -OutFile ort.zip
44+
Expand-Archive ort.zip -DestinationPath ort
45+
Copy-Item "ort\onnxruntime-win-x64-$ver\onnxruntime.dll" dist\onnxruntime.dll
46+
47+
- name: Build
48+
shell: bash
49+
env:
50+
GOOS: ${{ matrix.goos }}
51+
GOARCH: ${{ matrix.goarch }}
52+
CGO_ENABLED: 1
53+
WINDOWS: ${{ matrix.goos == 'windows' && '1' || '0' }}
2654
run: |
27-
mkdir -p dist
28-
make build-linux
29-
make build-windows
55+
if [ "$GOOS" = "windows" ]; then
56+
make build-windows
57+
else
58+
make build-linux
59+
fi
60+
61+
- name: Upload artifacts
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: build-${{ matrix.goos }}-${{ matrix.goarch }}
65+
path: |
66+
dist/hf_transformers_go-${{ matrix.goos }}-${{ matrix.goarch }}*
67+
dist/onnxruntime.dll
68+
69+
release:
70+
needs: build
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Download artifacts
74+
uses: actions/download-artifact@v4
75+
with:
76+
path: dist
77+
78+
- name: List artifacts
79+
run: ls -R dist
3080

3181
- name: Create release
3282
uses: softprops/action-gh-release@v2
3383
with:
3484
tag_name: ${{ github.ref_name }}
3585
name: ${{ github.ref_name }}
3686
files: |
37-
dist/hf_transformers_go-linux-amd64
38-
dist/hf_transformers_go-windows-amd64.exe
87+
dist/**/hf_transformers_go-linux-amd64
88+
dist/**/hf_transformers_go-windows-amd64.exe
89+
dist/**/onnxruntime.dll
3990
env:
4091
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ build-linux: deps
1515
GOOS=linux GOARCH=amd64 go build -o dist/hf_transformers_go-linux-amd64 .
1616

1717
build-windows: deps
18+
ifneq ($(GOOS),windows)
1819
ifeq ($(WINDOWS),1)
1920
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -o dist/hf_transformers_go-windows-amd64.exe .
2021
else
2122
@echo "Skipping Windows build; set WINDOWS=1 to attempt (requires Windows toolchain and onnxruntime DLLs)"
2223
endif
24+
else
25+
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -o dist/hf_transformers_go-windows-amd64.exe .
26+
endif
2327

2428
# Build both (Linux + optional Windows)
2529
build: build-linux build-windows

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ func main() {
3232
map[string]any{"dtype": "q4"},
3333
)
3434
if err != nil {
35-
log.Fatal(err)
35+
log.Println(err)
36+
return
3637
}
3738
out, err := generator([]ChatMessage{
3839
{Role: RoleUser, Content: "What is the third planet in our solar system and who inhabits it?"},
3940
}, map[string]any{"max_new_tokens": 32})
4041
if err != nil {
41-
log.Fatal(err)
42+
log.Println(err)
43+
return
4244
}
4345
fmt.Println(out[0]["generated_text"])
4446
}

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func main() {
2929
map[string]any{"dtype": "q4"},
3030
)
3131
if err != nil {
32-
log.Fatal(err)
32+
log.Println(err)
33+
return
3334
}
3435

3536
messages := []ChatMessage{
@@ -46,7 +47,8 @@ func main() {
4647
},
4748
})
4849
if err != nil {
49-
log.Fatal(err)
50+
log.Println(err)
51+
return
5052
}
5153

5254
gen := out[0]["generated_text"].([]map[string]any)

0 commit comments

Comments
 (0)