Skip to content

Commit c0dd0a0

Browse files
authored
ci: Windows build pipelines (#221)
* ci: Windows build pipelines * use forward slash * fix Makefile * fix Makefile * remove otel expect * fix Makefile * fix Makefile * fix infra.go
1 parent 67a803a commit c0dd0a0

File tree

10 files changed

+78
-56
lines changed

10 files changed

+78
-56
lines changed

Diff for: .github/workflows/basic.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
build:
17-
runs-on: ubuntu-latest
17+
runs-on: ${{ matrix.os }}
1818
strategy:
1919
# If you want to matrix build , you can append the following list.
2020
matrix:
@@ -23,6 +23,7 @@ jobs:
2323
- 1.23
2424
os:
2525
- ubuntu-latest
26+
- windows-latest
2627
steps:
2728
- uses: actions/checkout@v4
2829

Diff for: Makefile

+35-20
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,40 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Get the current operating system and CPU architecture of the system
15+
#-------------------------------------------------------------------------------
16+
# General build options
1617
CURRENT_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
1718
CURRENT_ARCH := $(shell uname -m)
1819

20+
MOD_NAME := github.com/alibaba/opentelemetry-go-auto-instrumentation
21+
VERSION := $(MAIN_VERSION)_$(COMMIT_ID)
22+
XVERSION := -X=$(MOD_NAME)/tool/config.ToolVersion=$(VERSION)
23+
STRIP_DEBUG := -s -w
24+
LDFLAGS := $(XVERSION) $(STRIP_DEBUG)
25+
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -ldflags="$(LDFLAGS)" -o $(3) ./tool/cmd
26+
27+
OUTPUT_BASE = otel
28+
OUTPUT_DARWIN_AMD64 = $(OUTPUT_BASE)-darwin-amd64
29+
OUTPUT_LINUX_AMD64 = $(OUTPUT_BASE)-linux-amd64
30+
OUTPUT_WINDOWS_AMD64 = $(OUTPUT_BASE)-windows-amd64.exe
31+
OUTPUT_DARWIN_ARM64 = $(OUTPUT_BASE)-darwin-arm64
32+
OUTPUT_LINUX_ARM64 = $(OUTPUT_BASE)-linux-arm64
33+
34+
#-------------------------------------------------------------------------------
35+
# Multiple OS and ARCH support
1936
ifeq ($(CURRENT_ARCH), x86_64)
2037
CURRENT_ARCH := amd64
2138
endif
2239

40+
# Check if current os contains "MINGW" or "MSYS" to determine if it is Windows
41+
ifeq ($(findstring mingw,$(CURRENT_OS)),mingw)
42+
CURRENT_OS := windows
43+
endif
44+
45+
ifeq ($(findstring msys,$(CURRENT_OS)),msys)
46+
CURRENT_OS := windows
47+
endif
48+
2349
# Get the current Git commit ID
2450
CHECK_GIT_DIRECTORY := $(if $(wildcard .git),true,false)
2551
ifeq ($(CHECK_GIT_DIRECTORY),true)
@@ -36,27 +62,16 @@ else
3662
COMMIT_ID := default
3763
endif
3864

39-
# General build options
40-
MOD_NAME := github.com/alibaba/opentelemetry-go-auto-instrumentation
41-
TOOL_REL_NAME := otel
42-
43-
VERSION := $(MAIN_VERSION)_$(COMMIT_ID)
44-
XVERSION := -X=$(MOD_NAME)/tool/config.ToolVersion=$(VERSION)
45-
STRIP_DEBUG := -s -w
46-
LDFLAGS := $(XVERSION) $(STRIP_DEBUG)
47-
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -ldflags="$(LDFLAGS)" -o $(3) ./tool/cmd
48-
49-
OUTPUT_BASE = $(TOOL_REL_NAME)
50-
OUTPUT_DARWIN_AMD64 = $(OUTPUT_BASE)-darwin-amd64
51-
OUTPUT_LINUX_AMD64 = $(OUTPUT_BASE)-linux-amd64
52-
OUTPUT_WINDOWS_AMD64 = $(OUTPUT_BASE)-windows-amd64.exe
53-
OUTPUT_DARWIN_ARM64 = $(OUTPUT_BASE)-darwin-arm64
54-
OUTPUT_LINUX_ARM64 = $(OUTPUT_BASE)-linux-arm64
55-
65+
#-------------------------------------------------------------------------------
66+
# Build targets
5667
.PHONY: build
5768
build:
5869
go mod tidy
59-
$(call BUILD_CMD,$(CURRENT_OS),$(CURRENT_ARCH),$(OUTPUT_BASE))
70+
$(eval OUTPUT_BIN=$(OUTPUT_BASE))
71+
ifeq ($(CURRENT_OS),windows)
72+
$(eval OUTPUT_BIN=$(OUTPUT_BASE).exe)
73+
endif
74+
$(call BUILD_CMD,$(CURRENT_OS),$(CURRENT_ARCH),$(OUTPUT_BIN))
6075

6176
.PHONY: all test clean
6277

@@ -87,7 +102,7 @@ clean:
87102
go clean
88103

89104
test:
90-
go test -timeout 50m -v github.com/alibaba/opentelemetry-go-auto-instrumentation/test
105+
go test -timeout 50m -v $(MOD_NAME)/test
91106

92107
install: build
93108
@echo "Running install process..."

Diff for: test/build_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func TestBuildProject5(t *testing.T) {
7171
RunGoBuild(t, "go", "build", "m1")
7272
// both test_fmt.json and default.json rules should be available
7373
// because we always append new -rule to the default.json by default
74-
ExpecPreprocessContains(t, shared.DebugLogFile, "fmt")
75-
ExpecPreprocessContains(t, shared.DebugLogFile, "database/sql")
74+
ExpectPreprocessContains(t, shared.DebugLogFile, "fmt")
75+
ExpectPreprocessContains(t, shared.DebugLogFile, "database/sql")
7676
}
7777

7878
func TestBuildProject6(t *testing.T) {
@@ -82,6 +82,6 @@ func TestBuildProject6(t *testing.T) {
8282
RunSet(t, "-disabledefault=true", "-rule=../../pkg/data/test_fmt.json", "-verbose")
8383
RunGoBuild(t, "go", "build", "m1")
8484
// only test_fmt.json should be available because -disabledefault is set
85-
ExpecPreprocessContains(t, shared.DebugLogFile, "fmt")
86-
ExpecPreprocessNotContains(t, shared.DebugLogFile, "database/sql")
85+
ExpectPreprocessContains(t, shared.DebugLogFile, "fmt")
86+
ExpectPreprocessNotContains(t, shared.DebugLogFile, "database/sql")
8787
}

Diff for: test/flags_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func TestFlags(t *testing.T) {
2525
UseApp(AppName)
2626

2727
RunGoBuildFallible(t, "go", "build", "-thisisnotvalid")
28-
ExpecPreprocessContains(t, shared.DebugLogFile, "failed to")
28+
ExpectPreprocessContains(t, shared.DebugLogFile, "failed to")
2929

3030
RunVersion(t)
3131
ExpectStdoutContains(t, "version")
3232

3333
RunGoBuildFallible(t, "go", "build", "notevenaflag")
34-
ExpecPreprocessContains(t, shared.DebugLogFile, "failed to")
34+
ExpectPreprocessContains(t, shared.DebugLogFile, "failed to")
3535

3636
RunSet(t, "-verbose")
3737
RunGoBuild(t, "go", "build", `-ldflags=-X main.Placeholder=replaced`)

Diff for: test/httpclient_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,4 @@ func TestRunHttpclient(t *testing.T) {
3535
ExpectContains(t, stderr, "debug.Stack()") // during recover()
3636
ExpectContains(t, stderr, "4008208820")
3737
ExpectContains(t, stderr, "Prince of Qin Smashing the Battle line")
38-
39-
//ExpecPreprocessContains(t, "debug.log", "go.opentelemetry.io/[email protected]")
40-
//ExpectInstrumentContains(t, "debug.log", "go.opentelemetry.io/[email protected]")
4138
}

Diff for: test/infra.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ import (
1919
"os"
2020
"os/exec"
2121
"path/filepath"
22+
"runtime"
2223
"sort"
2324
"strings"
2425
"testing"
2526

2627
"github.com/alibaba/opentelemetry-go-auto-instrumentation/test/verifier"
2728
"github.com/alibaba/opentelemetry-go-auto-instrumentation/test/version"
28-
2929
"github.com/alibaba/opentelemetry-go-auto-instrumentation/tool/shared"
3030
"github.com/alibaba/opentelemetry-go-auto-instrumentation/tool/util"
3131
)
3232

33-
const (
34-
ExecName = "otel"
35-
)
33+
func getExecName() string {
34+
execName := "otel"
35+
if runtime.GOOS == "windows" {
36+
return execName + ".exe"
37+
}
38+
return execName
39+
}
3640

3741
func runCmd(args []string) *exec.Cmd {
3842
path := args[0]
@@ -78,8 +82,8 @@ func readStderrLog(t *testing.T) string {
7882

7983
func RunVersion(t *testing.T) {
8084
util.Assert(pwd != "", "pwd is empty")
81-
path := filepath.Join(filepath.Dir(pwd), ExecName)
82-
cmd := runCmd(append([]string{path, "version"}))
85+
path := filepath.Join(filepath.Dir(pwd), getExecName())
86+
cmd := runCmd([]string{path, "version"})
8387
err := cmd.Run()
8488
if err != nil {
8589
t.Fatal(err)
@@ -88,7 +92,7 @@ func RunVersion(t *testing.T) {
8892

8993
func RunSet(t *testing.T, args ...string) {
9094
util.Assert(pwd != "", "pwd is empty")
91-
path := filepath.Join(filepath.Dir(pwd), ExecName)
95+
path := filepath.Join(filepath.Dir(pwd), getExecName())
9296
cmd := runCmd(append([]string{path, "set"}, args...))
9397
err := cmd.Run()
9498
if err != nil {
@@ -99,7 +103,7 @@ func RunSet(t *testing.T, args ...string) {
99103
func RunGoBuild(t *testing.T, args ...string) {
100104
util.Assert(pwd != "", "pwd is empty")
101105
RunSet(t, "-debuglog")
102-
path := filepath.Join(filepath.Dir(pwd), ExecName)
106+
path := filepath.Join(filepath.Dir(pwd), getExecName())
103107
cmd := runCmd(append([]string{path}, args...))
104108
err := cmd.Run()
105109
if err != nil {
@@ -120,7 +124,7 @@ func RunGoBuild(t *testing.T, args ...string) {
120124
func RunGoBuildFallible(t *testing.T, args ...string) {
121125
util.Assert(pwd != "", "pwd is empty")
122126
RunSet(t, "-debuglog")
123-
path := filepath.Join(filepath.Dir(pwd), ExecName)
127+
path := filepath.Join(filepath.Dir(pwd), getExecName())
124128
cmd := runCmd(append([]string{path}, args...))
125129
err := cmd.Run()
126130
if err == nil {
@@ -204,13 +208,13 @@ func ExpectInstrumentNotContains(t *testing.T, log string, rule string) {
204208
ExpectNotContains(t, content, rule)
205209
}
206210

207-
func ExpecPreprocessContains(t *testing.T, log string, rule string) {
211+
func ExpectPreprocessContains(t *testing.T, log string, rule string) {
208212
path := filepath.Join(shared.TempBuildDir, shared.PPreprocess, log)
209213
content := readLog(t, path)
210214
ExpectContains(t, content, rule)
211215
}
212216

213-
func ExpecPreprocessNotContains(t *testing.T, log string, rule string) {
217+
func ExpectPreprocessNotContains(t *testing.T, log string, rule string) {
214218
path := filepath.Join(shared.TempBuildDir, shared.PPreprocess, log)
215219
content := readLog(t, path)
216220
ExpectNotContains(t, content, rule)

Diff for: tool/preprocess/fetch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (dp *DepProcessor) fetchEmbed(path string) (string, error) {
9090
if err != nil {
9191
return err
9292
}
93-
target := shared.GePreprocessLogPath(filepath.Join(OtelRuleCache, p))
93+
target := shared.GetPreprocessLogPath(filepath.Join(OtelRuleCache, p))
9494
err = os.MkdirAll(filepath.Dir(target), 0777)
9595
if err != nil {
9696
return fmt.Errorf("failed to create directory: %w", err)
@@ -111,7 +111,7 @@ func (dp *DepProcessor) fetchEmbed(path string) (string, error) {
111111
}
112112
// Now all rule files are copied to the local file system, we can return
113113
// the path to corresponding local file system
114-
dir := shared.GePreprocessLogPath(filepath.Join(OtelRuleCache, path))
114+
dir := shared.GetPreprocessLogPath(filepath.Join(OtelRuleCache, path))
115115
return dir, nil
116116
}
117117

Diff for: tool/preprocess/setup.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func initRuleDir() (err error) {
4343
return nil
4444
}
4545

46-
func (dp *DepProcessor) copyRules(target string) (err error) {
46+
func (dp *DepProcessor) copyRules(pkgName string) (err error) {
4747
if len(dp.bundles) == 0 {
4848
return nil
4949
}
@@ -85,7 +85,7 @@ func (dp *DepProcessor) copyRules(target string) (err error) {
8585
continue
8686
}
8787

88-
ruleDir := filepath.Join(target, dir)
88+
ruleDir := filepath.Join(pkgName, dir)
8989
err = os.MkdirAll(ruleDir, 0777)
9090
if err != nil {
9191
return fmt.Errorf("failed to create dir %v: %w",
@@ -241,7 +241,7 @@ func (dp *DepProcessor) copyRule(path, target string,
241241
return nil
242242
}
243243

244-
func (dp *DepProcessor) initRules(pkgName, target string) (err error) {
244+
func (dp *DepProcessor) initRules(pkgName string) (err error) {
245245
c := fmt.Sprintf("package %s\n", pkgName)
246246
imports := make(map[string]string)
247247

@@ -272,7 +272,10 @@ func (dp *DepProcessor) initRules(pkgName, target string) (err error) {
272272
aliasPkg = imports[bundle.ImportPath]
273273
}
274274
if rule.OnEnter != "" {
275-
rd := filepath.Join(OtelRules, dp.rule2Dir[rule])
275+
// @@Dont use filepath.Join here, because this is import
276+
// path presented in Go source code, which should always
277+
// use forward slash
278+
rd := fmt.Sprintf("%s/%s", OtelRules, dp.rule2Dir[rule])
276279
path, err := dp.getImportPathOf(rd)
277280
if err != nil {
278281
return fmt.Errorf("failed to get import path: %w",
@@ -289,7 +292,7 @@ func (dp *DepProcessor) initRules(pkgName, target string) (err error) {
289292
)
290293
}
291294
if rule.OnExit != "" {
292-
rd := filepath.Join(OtelRules, dp.rule2Dir[rule])
295+
rd := fmt.Sprintf("%s/%s", OtelRules, dp.rule2Dir[rule])
293296
path, err := dp.getImportPathOf(rd)
294297
if err != nil {
295298
return fmt.Errorf("failed to get import path: %w",
@@ -339,7 +342,8 @@ func (dp *DepProcessor) initRules(pkgName, target string) (err error) {
339342
}
340343
c += "}\n"
341344

342-
_, err = util.WriteFile(target, c)
345+
initTarget := filepath.Join(OtelRules, OtelSetupInst)
346+
_, err = util.WriteFile(initTarget, c)
343347
if err != nil {
344348
return err
345349
}
@@ -358,8 +362,9 @@ func (dp *DepProcessor) addRuleImport() error {
358362
return nil
359363
}
360364

361-
func (dp *DepProcessor) setupOtelSDK(pkgName, target string) error {
362-
_, err := resource.CopyOtelSetupTo(pkgName, target)
365+
func (dp *DepProcessor) setupOtelSDK(pkgName string) error {
366+
setupTarget := filepath.Join(OtelRules, OtelSetupSDK)
367+
_, err := resource.CopyOtelSetupTo(pkgName, setupTarget)
363368
if err != nil {
364369
return fmt.Errorf("failed to copy otel setup sdk: %w", err)
365370
}
@@ -376,11 +381,11 @@ func (dp *DepProcessor) setupRules() (err error) {
376381
if err != nil {
377382
return fmt.Errorf("failed to setup rules: %w", err)
378383
}
379-
err = dp.initRules(OtelRules, filepath.Join(OtelRules, OtelSetupInst))
384+
err = dp.initRules(OtelRules)
380385
if err != nil {
381386
return fmt.Errorf("failed to setup initiator: %w", err)
382387
}
383-
err = dp.setupOtelSDK(OtelRules, filepath.Join(OtelRules, OtelSetupSDK))
388+
err = dp.setupOtelSDK(OtelRules)
384389
if err != nil {
385390
return fmt.Errorf("failed to setup otel sdk: %w", err)
386391
}

Diff for: tool/resource/bundle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func FindRuleFiles(rule InstRule) ([]string, error) {
141141

142142
func StoreRuleBundles(bundles []*RuleBundle) error {
143143
shared.GuaranteeInPreprocess()
144-
ruleFile := shared.GePreprocessLogPath(RuleBundleJsonFile)
144+
ruleFile := shared.GetPreprocessLogPath(RuleBundleJsonFile)
145145
bs, err := json.Marshal(bundles)
146146
if err != nil {
147147
return fmt.Errorf("failed to marshal bundles: %w", err)
@@ -156,7 +156,7 @@ func StoreRuleBundles(bundles []*RuleBundle) error {
156156
func LoadRuleBundles() ([]*RuleBundle, error) {
157157
shared.GuaranteeInInstrument()
158158

159-
ruleFile := shared.GePreprocessLogPath(RuleBundleJsonFile)
159+
ruleFile := shared.GetPreprocessLogPath(RuleBundleJsonFile)
160160
data, err := util.ReadFile(ruleFile)
161161
if err != nil {
162162
return nil, fmt.Errorf("failed to read used rules: %w", err)

Diff for: tool/shared/shared.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func GetInstrumentLogPath(name string) string {
118118
return filepath.Join(TempBuildDir, PInstrument, name)
119119
}
120120

121-
func GePreprocessLogPath(name string) string {
121+
func GetPreprocessLogPath(name string) string {
122122
return filepath.Join(TempBuildDir, PPreprocess, name)
123123
}
124124

0 commit comments

Comments
 (0)