Skip to content

Commit 50a7979

Browse files
authored
2025 01 25 Project cleanup (#418)
Changes: * Added gofumpt, staticcheck, go vet and govulncheck into pipeline * Formatted all files * go mod tidy on all gomods * Fumpted the go * Cleaned up the existing pipeline so that it runs
1 parent f09913d commit 50a7979

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+682
-711
lines changed

.github/workflows/test.yml .github/workflows/code-qa.yml

+75-16
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,95 @@
1-
name: Build and Test
1+
name: Code QA
22

33
on:
4+
pull_request:
5+
branches:
6+
- master
47
push:
58
branches:
69
- master
7-
- staging
8-
- trying
9-
schedule:
10-
- cron: '0 2 * * *' # To test `wasmer-nightly` with `libwasmer_archive_name`.
1110

1211
jobs:
12+
staticcheck:
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: "1.23"
21+
22+
- name: Staticcheck
23+
run: |
24+
go install honnef.co/go/tools/cmd/[email protected]
25+
staticcheck ./...
26+
gofumpt:
27+
runs-on: ubuntu-24.04
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Set up Go
32+
uses: actions/setup-go@v4
33+
with:
34+
go-version: "1.23"
35+
36+
- name: Gofumpt
37+
run: |
38+
go install mvdan.cc/[email protected]
39+
output=$(gofumpt -l .)
40+
if [ ! -z "$output" ]; then echo "$output" && exit 1; fi
41+
shell: bash
42+
43+
govulncheck:
44+
runs-on: ubuntu-24.04
45+
steps:
46+
- uses: actions/checkout@v3
47+
48+
- name: Set up Go
49+
uses: actions/setup-go@v4
50+
with:
51+
go-version: "1.23"
52+
53+
- name: Vulnerabilities
54+
run: |
55+
go install golang.org/x/vuln/cmd/govulncheck@latest
56+
govulncheck ./...
57+
58+
govet:
59+
runs-on: ubuntu-24.04
60+
steps:
61+
- uses: actions/checkout@v3
62+
63+
- name: Set up Go
64+
uses: actions/setup-go@v4
65+
with:
66+
go-version: "1.23"
67+
68+
- name: Vet
69+
run: |
70+
go vet ./...
71+
1372
test:
1473
name: Build and Test
15-
1674
strategy:
1775
matrix:
18-
go: [1.14, 1.15]
76+
go: [1.21, 1.22]
1977
target:
20-
- id: 'linux-amd64'
21-
os: 'ubuntu-18.04'
78+
- id: "linux-amd64"
79+
os: "ubuntu-24.04"
2280

2381
#- id: 'linux-aarch64'
2482
# os: ['self-hosted', 'linux', 'ARM64']
2583

26-
- id: 'darwin-amd64'
27-
os: 'macos-latest'
84+
- id: "darwin-amd64"
85+
os: "macos-latest"
2886

29-
- id: 'linux-amd64'
30-
os: 'ubuntu-18.04'
31-
libwasmer_archive_name: 'wasmer-linux-amd64.tar.gz'
87+
- id: "linux-amd64"
88+
os: "ubuntu-24.04"
89+
libwasmer_archive_name: "wasmer-linux-amd64.tar.gz"
3290
fail-fast: true
3391

3492
runs-on: ${{ matrix.target.os }}
35-
3693
steps:
3794
- name: Check out code
3895
uses: actions/checkout@v2
@@ -66,7 +123,8 @@ jobs:
66123
continue-on-error: true
67124
shell: bash
68125
run: |
69-
libwasmer_url=$(curl -s https://api.github.com/repos/wasmerio/wasmer-nightly/releases/latest | jq --raw-output '.assets[] | select(.name == "${{ matrix.target.libwasmer_archive_name }}") | .browser_download_url')
126+
libwasmer_url=$(curl -s https://api.github.com/repos/wasmerio/wasmer/releases/latest | \
127+
jq --raw-output '.assets[] | select(.name == "${{ matrix.target.libwasmer_archive_name }}") | .browser_download_url')
70128
mkdir -p libwasmer
71129
curl -L $libwasmer_url > release.tar.gz
72130
tar xzvf release.tar.gz -C libwasmer
@@ -78,6 +136,7 @@ jobs:
78136
shell: bash
79137
run: |
80138
just examples
139+
81140
# Skipped for now because of Github banning the API request from actions.
82141
# You can find more info in this PR: https://github.com/wasmerio/wasmer-go/pull/118#issuecomment-588487544
83142
# - name: Test bazel build

examples/appendices/simple.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package main
22

33
import (
44
"fmt"
5-
wasmer "github.com/wasmerio/wasmer-go/wasmer"
65
"io/ioutil"
6+
7+
wasmer "github.com/wasmerio/wasmer-go/wasmer"
78
)
89

910
func main() {

examples/example_early_exit_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func ExampleFunction_Call() {
5959

6060
fmt.Println("Compiling module...")
6161
module, err := wasmer.NewModule(store, wasmBytes)
62-
6362
if err != nil {
6463
fmt.Println("Failed to compile module:", err)
6564
}
@@ -80,7 +79,6 @@ func ExampleFunction_Call() {
8079
fmt.Println("Instantiating module...")
8180
// Let's instantiate the Wasm module.
8281
instance, err := wasmer.NewInstance(module, importObject)
83-
8482
if err != nil {
8583
panic(fmt.Sprintln("Failed to instantiate the module:", err))
8684
}
@@ -90,7 +88,6 @@ func ExampleFunction_Call() {
9088
// Get the `run` function which we'll use as our entrypoint.
9189
fmt.Println("Calling `run` function...")
9290
run, err := instance.Exports.GetFunction("run")
93-
9491
if err != nil {
9592
panic(fmt.Sprintln("Failed to retrieve the `run` function:", err))
9693
}

examples/example_errors_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package wasmer
1717

1818
import (
1919
"fmt"
20+
2021
"github.com/wasmerio/wasmer-go/wasmer"
2122
)
2223

@@ -45,7 +46,6 @@ func ExampleError() {
4546

4647
fmt.Println("Compiling module...")
4748
module, err := wasmer.NewModule(store, wasmBytes)
48-
4949
if err != nil {
5050
fmt.Println("Failed to compile module:", err)
5151
}
@@ -56,7 +56,6 @@ func ExampleError() {
5656
fmt.Println("Instantiating module...")
5757
// Let's instantiate the Wasm module.
5858
instance, err := wasmer.NewInstance(module, importObject)
59-
6059
if err != nil {
6160
panic(fmt.Sprintln("Failed to instantiate the module:", err))
6261
}
@@ -69,7 +68,6 @@ func ExampleError() {
6968
//
7069
// Let's get it.
7170
divByZero, err := instance.Exports.GetFunction("div_by_zero")
72-
7371
if err != nil {
7472
panic(fmt.Sprintln("Failed to get the `div_by_zero` function:", err))
7573
}

examples/example_exports_function_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package wasmer
1919

2020
import (
2121
"fmt"
22+
2223
"github.com/wasmerio/wasmer-go/wasmer"
2324
)
2425

@@ -44,7 +45,6 @@ func ExampleFunction() {
4445

4546
fmt.Println("Compiling module...")
4647
module, err := wasmer.NewModule(store, wasmBytes)
47-
4848
if err != nil {
4949
fmt.Println("Failed to compile module:", err)
5050
}
@@ -55,7 +55,6 @@ func ExampleFunction() {
5555
fmt.Println("Instantiating module...")
5656
// Let's instantiate the Wasm module.
5757
instance, err := wasmer.NewInstance(module, importObject)
58-
5958
if err != nil {
6059
panic(fmt.Sprintln("Failed to instantiate the module:", err))
6160
}
@@ -65,15 +64,13 @@ func ExampleFunction() {
6564
// The Wasm module exports a function called `sum`. Let's get
6665
// it.
6766
sum, err := instance.Exports.GetRawFunction("sum")
68-
6967
if err != nil {
7068
panic(fmt.Sprintln("Failed to retrieve the `sum` function:", err))
7169
}
7270

7371
fmt.Println("Calling `sum` function...")
7472
// Let's call the `sum` exported function.
7573
result, err := sum.Call(1, 2)
76-
7774
if err != nil {
7875
panic(fmt.Sprintln("Failed to call the `sum` function:", err))
7976
}
@@ -90,7 +87,6 @@ func ExampleFunction() {
9087
// statically typed Rust values of type `i32` and `i32`. The
9188
// result, in this case particular case, in a unit of type `i32`.
9289
result, err = sumNative(3, 4)
93-
9490
if err != nil {
9591
panic(fmt.Sprintln("Failed to call the `sum` function natively:", err))
9692
}

examples/example_exports_global_test.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// This example illustrates how to use exported globals. They come
55
// in 2 flavors:
66
//
7-
// 1. Immutable globals (const),
8-
// 2. Mutable globals.
7+
// 1. Immutable globals (const),
8+
// 2. Mutable globals.
99
//
1010
// You can run the example directly by executing in Wasmer root:
1111
//
@@ -18,6 +18,7 @@ package wasmer
1818

1919
import (
2020
"fmt"
21+
2122
"github.com/wasmerio/wasmer-go/wasmer"
2223
)
2324

@@ -44,7 +45,6 @@ func ExampleGlobal_Set() {
4445

4546
fmt.Println("Compiling module...")
4647
module, err := wasmer.NewModule(store, wasmBytes)
47-
4848
if err != nil {
4949
fmt.Println("Failed to compile module:", err)
5050
}
@@ -55,7 +55,6 @@ func ExampleGlobal_Set() {
5555
fmt.Println("Instantiating module...")
5656
// Let's instantiate the Wasm module.
5757
instance, err := wasmer.NewInstance(module, importObject)
58-
5958
if err != nil {
6059
panic(fmt.Sprintln("Failed to instantiate the module:", err))
6160
}
@@ -64,13 +63,11 @@ func ExampleGlobal_Set() {
6463
//
6564
// The Wasm module exports some globals. Let's get them.
6665
one, err := instance.Exports.GetGlobal("one")
67-
6866
if err != nil {
6967
panic(fmt.Sprintln("Failed to retrieve the `one` global:", err))
7068
}
7169

7270
some, err := instance.Exports.GetGlobal("some")
73-
7471
if err != nil {
7572
panic(fmt.Sprintln("Failed to retrieve the `some` global:", err))
7673
}
@@ -91,19 +88,16 @@ func ExampleGlobal_Set() {
9188
// We will use an exported function for the `one` global
9289
// and the Global API for `some`.
9390
getOne, err := instance.Exports.GetFunction("get_one")
94-
9591
if err != nil {
9692
panic(fmt.Sprintln("Failed to retrieve the `get_one` function:", err))
9793
}
9894

9995
oneValue, err := getOne()
100-
10196
if err != nil {
10297
panic(fmt.Sprintln("Failed to call the `get_one` function:", err))
10398
}
10499

105100
someValue, err := some.Get()
106-
107101
if err != nil {
108102
panic(fmt.Sprintln("Failed to get the `some` global value:", err))
109103
}
@@ -121,7 +115,6 @@ func ExampleGlobal_Set() {
121115
}
122116

123117
oneValue, err = getOne()
124-
125118
if err != nil {
126119
panic(fmt.Sprintln("Failed to call the `get_one` function:", err))
127120
}
@@ -134,33 +127,28 @@ func ExampleGlobal_Set() {
134127
//
135128
// We will use both for the `some` global.
136129
setSome, err := instance.Exports.GetFunction("set_some")
137-
138130
if err != nil {
139131
panic(fmt.Sprintln("Failed to retrieve the `set_some` function:", err))
140132
}
141133

142134
_, err = setSome(float32(21.0))
143-
144135
if err != nil {
145136
panic(fmt.Sprintln("Failed to call the `set_some` function:", err))
146137
}
147138

148139
someValue, err = some.Get()
149-
150140
if err != nil {
151141
panic(fmt.Sprintln("Failed to get the `some` global value:", err))
152142
}
153143

154144
fmt.Printf("`some` value after `set_some`: %.1f\n", someValue)
155145

156146
err = some.Set(float32(42.0), wasmer.F32)
157-
158147
if err != nil {
159148
panic(fmt.Sprintln("Failed to set the `some` global value:", err))
160149
}
161150

162151
someValue, err = some.Get()
163-
164152
if err != nil {
165153
panic(fmt.Sprintln("Failed to get the `some` global value:", err))
166154
}

examples/example_imports_exports_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func ExampleExtern() {
4242

4343
fmt.Println("Compiling module...")
4444
module, err := wasmer.NewModule(store, wasmBytes)
45-
4645
if err != nil {
4746
panic(fmt.Sprintln("Failed to compile module:", err))
4847
}
@@ -114,7 +113,6 @@ func ExampleExtern() {
114113
// Let's get them.
115114
fmt.Println("Getting the exported function...")
116115
function, err := instance.Exports.GetFunction("guest_function")
117-
118116
if err != nil {
119117
panic(fmt.Sprintln("Failed to get the exported function:", err))
120118
}
@@ -123,7 +121,6 @@ func ExampleExtern() {
123121

124122
fmt.Println("Getting the exported global...")
125123
global, err := instance.Exports.GetGlobal("guest_global")
126-
127124
if err != nil {
128125
panic(fmt.Sprintln("Failed to get the exported global:", err))
129126
}
@@ -132,7 +129,6 @@ func ExampleExtern() {
132129

133130
fmt.Println("Getting the exported memory...")
134131
memory, err := instance.Exports.GetMemory("guest_memory")
135-
136132
if err != nil {
137133
panic(fmt.Sprintln("Failed to get the exported memory:", err))
138134
}
@@ -141,7 +137,6 @@ func ExampleExtern() {
141137

142138
fmt.Println("Getting the exported table...")
143139
table, err := instance.Exports.GetTable("guest_table")
144-
145140
if err != nil {
146141
panic(fmt.Sprintln("Failed to get the exported table:", err))
147142
}

0 commit comments

Comments
 (0)