@@ -40,29 +40,32 @@ jobs:
4040 git submodule update --init --recursive
4141
4242 # Ensure all dependencies are properly downloaded and verified
43- go mod download
44- go mod verify
45- go mod tidy
43+ GOWORK=off go mod download
44+ GOWORK=off go mod verify
45+ GOWORK=off go mod tidy
4646
4747 # Explicitly get the missing dependency that causes issues in xgo
48- go get github.com/munnerz/goautoneg
49- go get github.com/prometheus/common/expfmt@v0.65.0
48+ GOWORK=off go get github.com/munnerz/goautoneg
49+ GOWORK=off go get github.com/prometheus/common/expfmt@v0.65.0
5050
5151 # Update go.sum and mod files after adding dependencies
52- go mod tidy
52+ GOWORK=off go mod tidy
5353
5454 # List module status for debugging
5555 echo "Go module status:"
56- go list -m all | grep -E "(prometheus|munnerz)" || true
56+ GOWORK=off go list -m all | grep -E "(prometheus|munnerz)" || true
5757
58- # Use xgo to build for multiple platforms
58+ # Store the exact Go version and build flags for plugin builds
5959 GO_RELEASE_V=$(go version | { read _ _ v _; echo ${v#go}; })
60+ echo "GO_VERSION=$GO_RELEASE_V" >> $GITHUB_ENV
61+ echo "BUILD_LDFLAGS=-s -w" >> $GITHUB_ENV
62+ echo "XGO_IMAGE=techknowlogick/xgo:latest" >> $GITHUB_ENV
6063
6164 # Build main binaries using xgo with the same targets as Makefile
6265 # Use local directory and enable modules
6366 xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out glauth -dest bin \
6467 -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64,windows/amd64,windows/386" \
65- -env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct" .
68+ -env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct,GOWORK=off " .
6669
6770 # Fix ownership and permissions for files created by xgo (which runs as root in docker)
6871 sudo chown -R $USER:$USER bin/ 2>/dev/null || true
@@ -84,42 +87,54 @@ jobs:
8487 make prepare-plugins-build
8588
8689 # Ensure all dependencies are up to date after plugin preparation
87- go mod download
88- go mod verify
89- go mod tidy
90+ GOWORK=off go mod download
91+ GOWORK=off go mod verify
92+ GOWORK=off go mod tidy
9093
91- # Disable workspace mode for consistent plugin builds
92- export GOWORK=off
94+ # Create a hash of the current module state for verification
95+ echo "Creating module state hash..."
96+ GOWORK=off go list -m all | sort | sha256sum > module-state.hash
97+ cat module-state.hash
9398
94- GO_RELEASE_V=$(go version | { read _ _ v _; echo ${v#go}; })
99+ # Use the same build environment as main binaries
100+ echo "Using stored build environment:"
101+ echo "GO_VERSION=$GO_VERSION"
102+ echo "BUILD_LDFLAGS=$BUILD_LDFLAGS"
103+ echo "XGO_IMAGE=$XGO_IMAGE"
95104
96105 # Build SQLite plugin
97106 if [ -d "pkg/plugins/glauth-sqlite" ]; then
98107 echo "Building SQLite plugin..."
99108 cd pkg/plugins/glauth-sqlite
100109
101- # Use the main module's go.mod and go.sum for consistent builds
102- cp ../../../ go.mod ./ go.mod.backup 2>/dev/null || true
103- cp ../../../ go.sum ./ go.sum.backup 2>/dev/null || true
110+ # Backup original module files if they exist
111+ mv go.mod go.mod.original 2>/dev/null || true
112+ mv go.sum go.sum.original 2>/dev/null || true
104113
105- # Update module name but keep all dependencies from main module
106- sed 's/^module.*/module github.com\/glauth\/glauth-sqlite/' ../../../ go.mod > go.mod
114+ # Create go.mod with exact same dependencies as main module
115+ cp ../ ../../go.mod go.mod
107116 cp ../../../go.sum go.sum
117+ sed -i 's/^module.*/module github.com\/glauth\/glauth-sqlite/' go.mod
118+ echo "require github.com/mattn/go-sqlite3 v1.14.15" >> go.mod
108119
109- # Add plugin-specific dependencies
110- go mod edit -require=github.com/mattn/go-sqlite3@v1.14.15
120+ # Build with updated module files
111121 GOWORK=off go mod tidy
112122
113- GOWORK=off xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out sqlite -dest ../../../bin \
123+ # Verify module state matches main module (excluding plugin-specific deps)
124+ echo "Verifying module state consistency..."
125+ GOWORK=off go list -m all | grep -v "github.com/mattn/go-sqlite3" | sort | sha256sum > plugin-state.hash
126+ if ! diff ../../../module-state.hash plugin-state.hash; then
127+ echo "WARNING: Plugin module state differs from main module"
128+ fi
129+
130+ GOWORK=off xgo -image $XGO_IMAGE -v -ldflags="$BUILD_LDFLAGS" -go $GO_VERSION -out sqlite -dest ../../../bin \
114131 -buildmode=plugin -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64" \
115132 -env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct,GOWORK=off" .
116133
117- # Restore original go.mod if it existed
118- if [ -f "./go.mod.backup" ]; then
119- mv ./go.mod.backup ./go.mod
120- mv ./go.sum.backup ./go.sum
121- fi
122-
134+ # Restore original module files
135+ rm -f go.mod go.sum plugin-state.hash
136+ mv go.mod.original go.mod 2>/dev/null || true
137+ mv go.sum.original go.sum 2>/dev/null || true
123138 cd ../../..
124139 fi
125140
@@ -128,28 +143,34 @@ jobs:
128143 echo "Building MySQL plugin..."
129144 cd pkg/plugins/glauth-mysql
130145
131- # Use the main module's go.mod and go.sum for consistent builds
132- cp ../../../ go.mod ./ go.mod.backup 2>/dev/null || true
133- cp ../../../ go.sum ./ go.sum.backup 2>/dev/null || true
146+ # Backup original module files if they exist
147+ mv go.mod go.mod.original 2>/dev/null || true
148+ mv go.sum go.sum.original 2>/dev/null || true
134149
135- # Update module name but keep all dependencies from main module
136- sed 's/^module.*/module github.com\/glauth\/glauth-mysql/' ../../../ go.mod > go.mod
150+ # Create go.mod with exact same dependencies as main module
151+ cp ../ ../../go.mod go.mod
137152 cp ../../../go.sum go.sum
153+ sed -i 's/^module.*/module github.com\/glauth\/glauth-mysql/' go.mod
154+ echo "require github.com/go-sql-driver/mysql v1.6.0" >> go.mod
138155
139- # Add plugin-specific dependencies
140- go mod edit -require=github.com/go-sql-driver/mysql@v1.6.0
156+ # Build with updated module files
141157 GOWORK=off go mod tidy
142158
143- GOWORK=off xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out mysql -dest ../../../bin \
159+ # Verify module state matches main module (excluding plugin-specific deps)
160+ echo "Verifying module state consistency..."
161+ GOWORK=off go list -m all | grep -v "github.com/go-sql-driver/mysql" | sort | sha256sum > plugin-state.hash
162+ if ! diff ../../../module-state.hash plugin-state.hash; then
163+ echo "WARNING: Plugin module state differs from main module"
164+ fi
165+
166+ GOWORK=off xgo -image $XGO_IMAGE -v -ldflags="$BUILD_LDFLAGS" -go $GO_VERSION -out mysql -dest ../../../bin \
144167 -buildmode=plugin -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64" \
145168 -env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct,GOWORK=off" .
146169
147- # Restore original go.mod if it existed
148- if [ -f "./go.mod.backup" ]; then
149- mv ./go.mod.backup ./go.mod
150- mv ./go.sum.backup ./go.sum
151- fi
152-
170+ # Restore original module files
171+ rm -f go.mod go.sum plugin-state.hash
172+ mv go.mod.original go.mod 2>/dev/null || true
173+ mv go.sum.original go.sum 2>/dev/null || true
153174 cd ../../..
154175 fi
155176
@@ -158,28 +179,34 @@ jobs:
158179 echo "Building PostgreSQL plugin..."
159180 cd pkg/plugins/glauth-postgres
160181
161- # Use the main module's go.mod and go.sum for consistent builds
162- cp ../../../ go.mod ./ go.mod.backup 2>/dev/null || true
163- cp ../../../ go.sum ./ go.sum.backup 2>/dev/null || true
182+ # Backup original module files if they exist
183+ mv go.mod go.mod.original 2>/dev/null || true
184+ mv go.sum go.sum.original 2>/dev/null || true
164185
165- # Update module name but keep all dependencies from main module
166- sed 's/^module.*/module github.com\/glauth\/glauth-postgres/' ../../../ go.mod > go.mod
186+ # Create go.mod with exact same dependencies as main module
187+ cp ../ ../../go.mod go.mod
167188 cp ../../../go.sum go.sum
189+ sed -i 's/^module.*/module github.com\/glauth\/glauth-postgres/' go.mod
190+ echo "require github.com/lib/pq v1.10.7" >> go.mod
168191
169- # Add plugin-specific dependencies
170- go mod edit -require=github.com/lib/pq@v1.10.7
192+ # Build with updated module files
171193 GOWORK=off go mod tidy
172194
173- GOWORK=off xgo -image techknowlogick/xgo:latest -v -ldflags="-s -w" -go $GO_RELEASE_V -out postgres -dest ../../../bin \
195+ # Verify module state matches main module (excluding plugin-specific deps)
196+ echo "Verifying module state consistency..."
197+ GOWORK=off go list -m all | grep -v "github.com/lib/pq" | sort | sha256sum > plugin-state.hash
198+ if ! diff ../../../module-state.hash plugin-state.hash; then
199+ echo "WARNING: Plugin module state differs from main module"
200+ fi
201+
202+ GOWORK=off xgo -image $XGO_IMAGE -v -ldflags="$BUILD_LDFLAGS" -go $GO_VERSION -out postgres -dest ../../../bin \
174203 -buildmode=plugin -targets="linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64" \
175204 -env="GO111MODULE=on,GOPROXY=https://proxy.golang.org,direct,GOWORK=off" .
176205
177- # Restore original go.mod if it existed
178- if [ -f "./go.mod.backup" ]; then
179- mv ./go.mod.backup ./go.mod
180- mv ./go.sum.backup ./go.sum
181- fi
182-
206+ # Restore original module files
207+ rm -f go.mod go.sum plugin-state.hash
208+ mv go.mod.original go.mod 2>/dev/null || true
209+ mv go.sum.original go.sum 2>/dev/null || true
183210 cd ../../..
184211 fi
185212
0 commit comments