|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | +/// Checks that the Pkl definitions eval correctly, and that they produce no diffs in git. |
| 17 | +module pkl.impl.ghactions.jobs.VerifyPklEval |
| 18 | + |
| 19 | +import "@gha/actions/Common.pkl" |
| 20 | +import "@gha/Workflow.pkl" |
| 21 | + |
| 22 | +import "../steps/SetupPkl.pkl" |
| 23 | + |
| 24 | +command: EvalCommand |
| 25 | + |
| 26 | +class EvalCommand { |
| 27 | + modules: Listing<String> |
| 28 | + |
| 29 | + multipleFileOutputPath: String? |
| 30 | + |
| 31 | + outputPath: String(multipleFileOutputPath == null)? |
| 32 | + |
| 33 | + projectDir: String? |
| 34 | + |
| 35 | + fixed run: String = |
| 36 | + new Listing<String> { |
| 37 | + "pkl" |
| 38 | + "eval" |
| 39 | + when (multipleFileOutputPath != null) { |
| 40 | + "-m" |
| 41 | + multipleFileOutputPath |
| 42 | + } |
| 43 | + when (outputPath != null) { |
| 44 | + "-o" |
| 45 | + outputPath |
| 46 | + } |
| 47 | + when (projectDir != null) { |
| 48 | + "--project-dir" |
| 49 | + projectDir |
| 50 | + } |
| 51 | + ...modules |
| 52 | + }.join(" ") |
| 53 | +} |
| 54 | + |
| 55 | +fixed job: Workflow.Job = new { |
| 56 | + `runs-on` = "ubuntu-latest" |
| 57 | + steps { |
| 58 | + new Common.Checkout {} |
| 59 | + new SetupPkl { version = "0.30.0" }.step |
| 60 | + new { |
| 61 | + shell = "bash" |
| 62 | + run = command.run |
| 63 | + } |
| 64 | + new { |
| 65 | + shell = "bash" |
| 66 | + name = "check git status" |
| 67 | + run = |
| 68 | + """ |
| 69 | + if [ -n "$(git status --porcelain)" ]; then |
| 70 | + echo "Running pkl resulted in a diff! You likely need to run 'pkl eval' and commit the changes." |
| 71 | + git diff --name-only |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + """ |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments