diff --git a/.circleci/config.pkl b/.circleci/config.pkl index d54da7a..507a403 100644 --- a/.circleci/config.pkl +++ b/.circleci/config.pkl @@ -1,4 +1,6 @@ -amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.0.2#/PklCI.pkl" +amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.1.1#/PklCI.pkl" + +import "pkl:semver" local testJobs = jobs.keys.filter((it) -> it.startsWith("test")) @@ -14,13 +16,23 @@ local class PklDistribution { /// The version of this distribution version: String + /// The parsed semver. + fixed _version: semver.Version = semver.parseOrNull(version)!! + /// The URL to download this distribution fixed downloadUrl: String = "https://github.com/apple/pkl/releases/download/\(version)/pkl-linux-amd64" + + /// The URL to download this distribution + fixed downloadUrlWindows: String = + if (_version.minor < 26) throw("Pkl \(version) is not supported on Windows") + else "https://github.com/apple/pkl/releases/download/\(version)/pkl-windows-amd64.exe" } +local distributionLatest: PklDistribution = new { version = "0.26.0" } + local pklDistributions: Listing = new { new { version = "0.25.3" } - new { version = "0.26.0" } + distributionLatest } release = (buildWorkflow) { @@ -48,52 +60,103 @@ triggerDocsBuild = "release" triggerPackageDocsBuild = "release" jobs { - for (distribution in pklDistributions) { - ["test-pkl-\(distribution.version.replaceAll(".", "-"))"] = (goJob) { - steps { - new RunStep { - name = "go test" - command = """ - curl -L -o pkl.bin '\(distribution.downloadUrl)' - chmod +x pkl.bin - export PKL_EXEC=$(pwd)/pkl.bin - go install github.com/jstemmer/go-junit-report/v2@latest - echo "Running Pkl unit tests" - $PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl - echo "Running Pkl snippet tests" - ./scripts/test_snippets.sh - echo "Running Go unit tests" - go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml - """ - } - new StoreTestResults { - path = "test-results" - } +// for (distribution in pklDistributions) { +// ["test-pkl-\(distribution.version.replaceAll(".", "-"))"] = (goJob) { +// steps { +// new RunStep { +// name = "go test" +// command = """ +// curl -L -o pkl.bin '\(distribution.downloadUrl)' +// chmod +x pkl.bin +// export PKL_EXEC=$(pwd)/pkl.bin +// go install github.com/jstemmer/go-junit-report/v2@latest +// echo "Running Pkl unit tests" +// $PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl +// echo "Running Pkl snippet tests" +// ./scripts/test_snippets.sh +// echo "Running Go unit tests" +// go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml +// """ +// } +// new StoreTestResults { +// path = "test-results" +// } +// } +// } +// } + ["test-windows"] { + machine { + image = "windows-server-2022-gui:current" + } + resource_class = "windows.medium" + steps { + "checkout" + new RunStep { + name = "go test" + shell = "powershell.exe" + command = #""" + echo "Downloading Go" + Invoke-WebRequest "https://go.dev/dl/go1.21.11.windows-386.msi" -OutFile go.exe + + echo "Installing Go" + $pkg = "$PWD\go.exe" + Start-Process msiexec "/i $pkg /qn"; + + echo "Installing Pkl" + Invoke-WebRequest "\#(distributionLatest.downloadUrlWindows)" -OutFile pkl.exe + $env:PKL_EXEC = "$PWD\pkl.exe" + + echo "Running Pkl unit tests" + .\pkl test --junit-reports test-results\ --project-dir codegen\src\ + + echo "Installing go-junit-report" + go install github.com/jstemmer/go-junit-report/v2@latest + + echo "Running Go unit tests" + go test -v .\... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results\go-test-results.xml + """# } } } ["build-pkl-gen-go"] = (goJob) { steps { - for (os in List("macos", "linux")) { + for (os in List("macos", "linux", "windows")) { for (arch in List("amd64", "aarch64")) { new RunStep { name = "go build \(os) \(arch)" environment { - ["GOOS"] = if (os == "linux") os else "darwin" + ["GOOS"] = if (os == "linux" || os == "windows") os else "darwin" ["GOARCH"] = if (arch == "amd64") arch else "arm64" } + local ext = if (os == "windows") "exe" else "bin" command = #""" # strip preceding "v" VERSION="${CIRCLE_TAG:1}" go build \ - -o out/pkl-gen-go/pkl-gen-go-\#(os)-\#(arch).bin \ + -o out/pkl-gen-go/pkl-gen-go-\#(os)-\#(arch).\#(ext) \ -ldflags="-X 'main.Version=$VERSION'" \ cmd/pkl-gen-go/pkl-gen-go.go """# } } } + new RunStep { + name = "go build windows amd64" + environment { + ["GOOS"] = "windows" + ["GOARCH"] = "amd64" + } + command = #""" + # strip preceding "v" + VERSION="${CIRCLE_TAG:1}" + + go build \ + -o out/pkl-gen-go/pkl-gen-go-windows-amd64.exe \ + -ldflags="-X 'main.Version=$VERSION'" \ + cmd/pkl-gen-go/pkl-gen-go.go + """# + } new PersistToWorkspaceStep { root = "." paths { diff --git a/.circleci/config.yml b/.circleci/config.yml index e532388..1391cb1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,46 +3,35 @@ version: '2.1' orbs: pr-approval: apple/pr-approval@0.1.0 jobs: - test-pkl-0-25-3: + test-windows: steps: - checkout - run: command: |- - curl -L -o pkl.bin 'https://github.com/apple/pkl/releases/download/0.25.3/pkl-linux-amd64' - chmod +x pkl.bin - export PKL_EXEC=$(pwd)/pkl.bin - go install github.com/jstemmer/go-junit-report/v2@latest + echo "Downloading Go" + Invoke-WebRequest "https://go.dev/dl/go1.21.11.windows-386.msi" -OutFile go.exe + + echo "Installing Go" + $pkg = "$PWD\go.exe" + Start-Process msiexec "/i $pkg /qn"; + + echo "Installing Pkl" + Invoke-WebRequest "https://github.com/apple/pkl/releases/download/0.26.0/pkl-windows-amd64.exe" -OutFile pkl.exe + $env:PKL_EXEC = "$PWD\pkl.exe" + echo "Running Pkl unit tests" - $PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl - echo "Running Pkl snippet tests" - ./scripts/test_snippets.sh - echo "Running Go unit tests" - go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml - name: go test - - store_test_results: - path: test-results - docker: - - image: cimg/go:1.21 - test-pkl-0-26-0: - steps: - - checkout - - run: - command: |- - curl -L -o pkl.bin 'https://github.com/apple/pkl/releases/download/0.26.0/pkl-linux-amd64' - chmod +x pkl.bin - export PKL_EXEC=$(pwd)/pkl.bin + .\pkl test --junit-reports test-results\ --project-dir codegen\src\ + + echo "Installing go-junit-report" go install github.com/jstemmer/go-junit-report/v2@latest - echo "Running Pkl unit tests" - $PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl - echo "Running Pkl snippet tests" - ./scripts/test_snippets.sh + echo "Running Go unit tests" - go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml + go test -v .\... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results\go-test-results.xml name: go test - - store_test_results: - path: test-results - docker: - - image: cimg/go:1.21 + shell: powershell.exe + resource_class: windows.medium + machine: + image: windows-server-2022-gui:current build-pkl-gen-go: steps: - checkout @@ -98,6 +87,45 @@ jobs: environment: GOOS: linux GOARCH: arm64 + - run: + command: |- + # strip preceding "v" + VERSION="${CIRCLE_TAG:1}" + + go build \ + -o out/pkl-gen-go/pkl-gen-go-windows-amd64.exe \ + -ldflags="-X 'main.Version=$VERSION'" \ + cmd/pkl-gen-go/pkl-gen-go.go + name: go build windows amd64 + environment: + GOOS: windows + GOARCH: amd64 + - run: + command: |- + # strip preceding "v" + VERSION="${CIRCLE_TAG:1}" + + go build \ + -o out/pkl-gen-go/pkl-gen-go-windows-aarch64.exe \ + -ldflags="-X 'main.Version=$VERSION'" \ + cmd/pkl-gen-go/pkl-gen-go.go + name: go build windows aarch64 + environment: + GOOS: windows + GOARCH: arm64 + - run: + command: |- + # strip preceding "v" + VERSION="${CIRCLE_TAG:1}" + + go build \ + -o out/pkl-gen-go/pkl-gen-go-windows-amd64.exe \ + -ldflags="-X 'main.Version=$VERSION'" \ + cmd/pkl-gen-go/pkl-gen-go.go + name: go build windows amd64 + environment: + GOOS: windows + GOARCH: amd64 - persist_to_workspace: root: '.' paths: @@ -212,10 +240,7 @@ workflows: type: approval - pr-approval/authenticate: context: pkl-pr-approval - - test-pkl-0-25-3: - requires: - - hold - - test-pkl-0-26-0: + - test-windows: requires: - hold when: @@ -224,29 +249,20 @@ workflows: pattern: ^pull/\d+(/head)?$ main: jobs: - - test-pkl-0-25-3 - - test-pkl-0-26-0 + - test-windows - build-pkl-gen-go: requires: - - test-pkl-0-25-3 - - test-pkl-0-26-0 + - test-windows - build-pkl-package: requires: - - test-pkl-0-25-3 - - test-pkl-0-26-0 + - test-windows when: equal: - main - << pipeline.git.branch >> release: jobs: - - test-pkl-0-25-3: - filters: - branches: - ignore: /.*/ - tags: - only: /^v?\d+\.\d+\.\d+$/ - - test-pkl-0-26-0: + - test-windows: filters: branches: ignore: /.*/ @@ -254,8 +270,7 @@ workflows: only: /^v?\d+\.\d+\.\d+$/ - build-pkl-gen-go: requires: - - test-pkl-0-25-3 - - test-pkl-0-26-0 + - test-windows filters: branches: ignore: /.*/ @@ -263,8 +278,7 @@ workflows: only: /^v?\d+\.\d+\.\d+$/ - build-pkl-package: requires: - - test-pkl-0-25-3 - - test-pkl-0-26-0 + - test-windows filters: branches: ignore: /.*/ diff --git a/pkl/module_source.go b/pkl/module_source.go index f777122..312536b 100644 --- a/pkl/module_source.go +++ b/pkl/module_source.go @@ -18,8 +18,6 @@ package pkl import ( "net/url" - "os" - "path" ) // ModuleSource represents a source for Pkl evaluation. @@ -34,31 +32,6 @@ type ModuleSource struct { Contents string } -// FileSource builds a ModuleSource, treating its arguments as paths on the file system. -// -// If the provided path is not an absolute path, it will be resolved against the current working -// directory. -// -// If multiple path arguments are provided, they are joined as multiple elements of the path. -// -// It panics if the current working directory cannot be resolved. -func FileSource(pathElems ...string) *ModuleSource { - src := path.Join(pathElems...) - if !path.IsAbs(src) { - p, err := os.Getwd() - if err != nil { - panic(err) - } - src = path.Join(p, src) - } - return &ModuleSource{ - Uri: &url.URL{ - Scheme: "file", - Path: src, - }, - } -} - // TextSource builds a ModuleSource whose contents are the provided text. func TextSource(text string) *ModuleSource { return &ModuleSource{ diff --git a/pkl/module_source_unix.go b/pkl/module_source_unix.go new file mode 100644 index 0000000..ee04b50 --- /dev/null +++ b/pkl/module_source_unix.go @@ -0,0 +1,49 @@ +// ===----------------------------------------------------------------------===// +// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. +// +// 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 +// +// https://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. +// ===----------------------------------------------------------------------===// + +//go:build unix +package pkl + +import ( + "net/url" + "os" + "path" +) + +// FileSource builds a ModuleSource, treating its arguments as paths on the file system. +// +// If the provided path is not an absolute path, it will be resolved against the current working +// directory. +// +// If multiple path arguments are provided, they are joined as multiple elements of the path. +// +// It panics if the current working directory cannot be resolved. +func FileSource(pathElems ...string) *ModuleSource { + src := path.Join(pathElems...) + if !path.IsAbs(src) { + p, err := os.Getwd() + if err != nil { + panic(err) + } + src = path.Join(p, src) + } + return &ModuleSource{ + Uri: &url.URL{ + Scheme: "file", + Path: src, + }, + } +} diff --git a/pkl/module_source_test.go b/pkl/module_source_unix_test.go similarity index 98% rename from pkl/module_source_test.go rename to pkl/module_source_unix_test.go index aea9f12..d925731 100644 --- a/pkl/module_source_test.go +++ b/pkl/module_source_unix_test.go @@ -14,6 +14,7 @@ // limitations under the License. // ===----------------------------------------------------------------------===// +//go:build unix package pkl import ( diff --git a/pkl/module_source_windows.go b/pkl/module_source_windows.go new file mode 100644 index 0000000..1f7c17a --- /dev/null +++ b/pkl/module_source_windows.go @@ -0,0 +1,51 @@ +// ===----------------------------------------------------------------------===// +// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. +// +// 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 +// +// https://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. +// ===----------------------------------------------------------------------===// + +package pkl + +import ( + "net/url" + "os" + "path/filepath" + "strings" +) + +// FileSource builds a ModuleSource, treating its arguments as paths on the file system. +// +// If the provided path is not an absolute path, it will be resolved against the current working +// directory. +// +// If multiple path arguments are provided, they are joined as multiple elements of the path. +// +// It panics if the current working directory cannot be resolved. +func FileSource(pathElems ...string) *ModuleSource { + src := filepath.Join(pathElems...) + // TODO: this can possibly be wrong because the path can be a UNC path. + if !filepath.IsAbs(src) { + p, err := os.Getwd() + if err != nil { + panic(err) + } + src = filepath.Join(p, src) + } + return &ModuleSource{ + Uri: &url.URL{ + Scheme: "file", + Path: "/" + strings.ReplaceAll(src, "\\", "/"), + }, + } +} + diff --git a/pkl/module_source_windows_test.go b/pkl/module_source_windows_test.go new file mode 100644 index 0000000..86a4fce --- /dev/null +++ b/pkl/module_source_windows_test.go @@ -0,0 +1,30 @@ +// ===----------------------------------------------------------------------===// +// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. +// +// 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 +// +// https://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. +// ===----------------------------------------------------------------------===// + +package pkl + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_PathSource(t *testing.T) { + src := FileSource("C:\\path\\to\\myfile.pkl") + assert.Equal(t, "file:///C:/path/to/myfile.pkl", src.Uri.String()) + src = FileSource("C:\\path", "to", "lib", "myotherfile.pkl") + assert.Equal(t, "file:///C:/path/to/lib/myotherfile.pkl", src.Uri.String()) +}