From a523aab603b43c830640e5c1fcf273ff0c1d0551 Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Wed, 9 Oct 2024 19:23:46 +0200 Subject: [PATCH 1/2] Provide paths for Windows executable --- .github/workflows/go.build.yaml | 15 ++++++++++-- .gitignore | 1 + pkg/path/path_windows.go | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 pkg/path/path_windows.go diff --git a/.github/workflows/go.build.yaml b/.github/workflows/go.build.yaml index 561c285..c657ee7 100644 --- a/.github/workflows/go.build.yaml +++ b/.github/workflows/go.build.yaml @@ -40,9 +40,14 @@ jobs: echo "--> Building project for: ${os}/${arch}" GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags "-X github.com/flownative/localbeach/pkg/version.Version=${GITHUB_REF#refs/*/}" -o beach . zip "beach_${os}_${arch}.zip" beach - ls -la done + echo "--> Building project for: windows/amd64" + GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X github.com/flownative/localbeach/pkg/version.Version=${GITHUB_REF#refs/*/}" -o beach.exe . + zip "beach_${os}_${arch}.zip" beach.exe + + ls -la + - name: Archive build result (darwin/amd64) uses: actions/upload-artifact@v4 with: @@ -61,6 +66,12 @@ jobs: name: beach-linux path: beach_linux_amd64.zip + - name: Archive build result (windows) + uses: actions/upload-artifact@v4 + with: + name: beach-windows + path: beach_windows_amd64.zip + - name: Create Release uses: ncipollo/release-action@v1 env: @@ -68,7 +79,7 @@ jobs: with: allowUpdates: true artifactErrorsFailBuild: true - artifacts: "beach_linux_amd64.zip,beach_darwin_amd64.zip,beach_darwin_arm64.zip" + artifacts: "beach_linux_amd64.zip,beach_darwin_amd64.zip,beach_darwin_arm64.zip,beach_windows_amd64.zip" artifactContentType: application/zip generateReleaseNotes: false makeLatest: true diff --git a/.gitignore b/.gitignore index e815023..cdfdaca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /bin /assets/compiled.go /beach +/beach.exe go_build_main_go diff --git a/pkg/path/path_windows.go b/pkg/path/path_windows.go new file mode 100644 index 0000000..29a4f4e --- /dev/null +++ b/pkg/path/path_windows.go @@ -0,0 +1,43 @@ +// Copyright 2019-2024 Robert Lemke, Karsten Dambekalns, Christian Müller +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// 💡 See https://golang.org/cmd/go/#hdr-Build_constraints for explanation of build constraints + +//go:build windows + +package path + +import ( + "log" + "os" + "path/filepath" +) + +var OldBase = "" +var Base = "" +var Certificates = "" +var Database = "" + +func init() { + homeDir, err := os.UserHomeDir() + + if err != nil { + log.Fatal("Failed detecting home directory") + return + } + + Base = filepath.Join(homeDir, ".LocalBeach") + Certificates = filepath.Join(Base, "Certificates") + Database = filepath.Join(Base, "MariaDB") +} From e67021c96804749b7417622efefe00b6318ee83f Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Thu, 10 Oct 2024 16:59:27 +0200 Subject: [PATCH 2/2] Fix project root detection (on Windows) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes two issues: - `path.Clean(…)` would transform a path like `C:\User\john\bar` to just `.` – fixed with `filepath.Clean()` - The check for the filesystem root using `/` never works on Windows, as there it is e.g. `C:\` – check for an "unchanged parent" instead --- pkg/beachsandbox/helpers.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/beachsandbox/helpers.go b/pkg/beachsandbox/helpers.go index 8fb5350..a74b9c3 100644 --- a/pkg/beachsandbox/helpers.go +++ b/pkg/beachsandbox/helpers.go @@ -17,7 +17,6 @@ package beachsandbox import ( "errors" "os" - "path" "path/filepath" "strings" @@ -38,15 +37,17 @@ func detectProjectRootPathFromWorkingDir() (rootPath string, err error) { } func detectProjectRootPath(currentPath string) (projectRootPath string, err error) { - projectRootPath = path.Clean(currentPath) + projectRootPath = filepath.Clean(currentPath) + parentPath := filepath.Dir(projectRootPath) if _, err := os.Stat(filepath.Join(projectRootPath, ".localbeach.docker-compose.yaml")); err == nil { return projectRootPath, err - } else if projectRootPath == "/" { + } else if parentPath == projectRootPath { + // We have reached the root folder return "", ErrNoLocalBeachConfigurationFound } - return detectProjectRootPath(path.Dir(projectRootPath)) + return detectProjectRootPath(parentPath) } func loadLocalBeachEnvironment(projectRootPath string) (err error) {