Skip to content

Commit 1f14ae7

Browse files
bioballHT154
andauthored
Add check pkl eval job (#35)
Co-authored-by: Jen Basch <[email protected]>
1 parent 85a5884 commit 1f14ae7

File tree

9 files changed

+173
-6
lines changed

9 files changed

+173
-6
lines changed

.github/PklProject.deps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@0": {
1212
"type": "local",
13-
"uri": "projectpackage://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@0.6.1",
13+
"uri": "projectpackage://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@0.7.0",
1414
"path": "../packages/pkl.impl.ghactions"
1515
}
1616
}

.github/workflows/prb.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
with:
3030
name: test-results-xml-build-and-test
3131
path: build/test-results/**/*.xml
32+
if-no-files-found: ignore
3233
upload-event-file:
3334
runs-on: ubuntu-latest
3435
steps:
@@ -38,3 +39,31 @@ jobs:
3839
with:
3940
name: test-results-event-file
4041
path: ${{ github.event_path }}
42+
check-pkl-github-actions:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v5
46+
- name: Setup Pkl
47+
id: setup-pkl
48+
env:
49+
PKL_VERSION: 0.30.0
50+
PKL_FILENAME: pkl
51+
PKL_DOWNLOAD_URL: https://github.com/apple/pkl/releases/download/0.30.0/pkl-linux-amd64
52+
shell: bash
53+
run: |-
54+
DIR="$(mktemp -d /tmp/pkl-$PKL_VERSION-XXXXXX)"
55+
PKL_EXEC="$DIR/$PKL_FILENAME"
56+
curl -sfL -o $PKL_EXEC "$PKL_DOWNLOAD_URL"
57+
chmod +x $PKL_EXEC
58+
echo "$DIR" >> "$GITHUB_PATH"
59+
echo "pkl_exec=$PKL_EXEC" >> "$GITHUB_OUTPUT"
60+
- shell: bash
61+
run: pkl eval -m .github/ --project-dir .github/ .github/index.pkl
62+
- name: check git status
63+
shell: bash
64+
run: |-
65+
if [ -n "$(git status --porcelain)" ]; then
66+
echo "Running pkl resulted in a diff! You likely need to run 'pkl eval' and commit the changes."
67+
git diff --name-only
68+
exit 1
69+
fi

packages/pkl.impl.ghactions/PklCI.pkl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,19 @@ import "@gha/Workflow.pkl"
2121

2222
import "actions/PublishUnitTestResult.pkl"
2323
import "helpers.pkl"
24+
import "jobs/CheckPklEval.pkl"
2425
import "util.pkl"
2526

27+
local checkPklGHADefinitions: CheckPklEval = new {
28+
command {
29+
modules {
30+
".github/index.pkl"
31+
}
32+
projectDir = ".github/"
33+
multipleFileOutputPath = ".github/"
34+
}
35+
}
36+
2637
/// The workflow that runs during pull requests.
2738
///
2839
/// The following fields are overwritten and therefore don't need to be set:
@@ -235,6 +246,7 @@ local effectivePrbWorkflow = (prb) {
235246
}
236247
}
237248
}
249+
["check-pkl-github-actions"] = checkPklGHADefinitions.job
238250
}
239251
}
240252

packages/pkl.impl.ghactions/PklProject

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
amends "../basePklProject.pkl"
1818

1919
package {
20-
version = "0.6.2"
20+
version = "0.7.0"
2121
}
2222

2323
dependencies {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}

packages/pkl.impl.ghactions/jobs/HawkeyeCheck.pkl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
//===----------------------------------------------------------------------===//
1616
module pkl.impl.ghactions.jobs.HawkeyeCheck
1717

18+
extends "PklJob.pkl"
19+
1820
import "@gha/actions/Common.pkl"
19-
import "@gha/Workflow.pkl"
2021

2122
image: String =
2223
"ghcr.io/korandoru/hawkeye@sha256:c3ab994c0d81f3d116aabf9afc534e18648e3e90d7525d741c1e99dd8166ec85"
@@ -27,9 +28,7 @@ failIfUnknown: Boolean = true
2728

2829
failIfMissing: Boolean = false
2930

30-
local self = this
31-
32-
fixed job: Workflow.Job = new {
31+
fixed job {
3332
// TODO when upstream pkl-gha supports it
3433
// This is currently injected in ../PklCI.pkl via an output converter
3534
// container {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
abstract module pkl.impl.ghactions.jobs.PklJob
17+
18+
import "@gha/Workflow.pkl"
19+
20+
/// The underlying job output.
21+
fixed job: Workflow.Job

packages/pkl.impl.ghactions/steps/SetupPkl.pkl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fixed step: Workflow.Step = new {
3737
["PKL_FILENAME"] = "pkl\(fileExtension)"
3838
["PKL_DOWNLOAD_URL"] = downloadUrl
3939
}
40+
name = "Setup Pkl"
4041
// language=bash
4142
run =
4243
"""

packages/pkl.impl.ghactions/tests/examples.pkl-expected.pcf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ examples {
3535
with:
3636
name: test-results-event-file
3737
path: ${{ github.event_path }}
38+
check-pkl-github-actions:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v5
42+
- name: Setup Pkl
43+
id: setup-pkl
44+
env:
45+
PKL_VERSION: 0.30.0
46+
PKL_FILENAME: pkl
47+
PKL_DOWNLOAD_URL: https://github.com/apple/pkl/releases/download/0.30.0/pkl-linux-amd64
48+
shell: bash
49+
run: |-
50+
DIR="$(mktemp -d /tmp/pkl-$PKL_VERSION-XXXXXX)"
51+
PKL_EXEC="$DIR/$PKL_FILENAME"
52+
curl -sfL -o $PKL_EXEC "$PKL_DOWNLOAD_URL"
53+
chmod +x $PKL_EXEC
54+
echo "$DIR" >> "$GITHUB_PATH"
55+
echo "pkl_exec=$PKL_EXEC" >> "$GITHUB_OUTPUT"
56+
- shell: bash
57+
run: pkl eval -m .github/ --project-dir .github/ .github/index.pkl
58+
- name: check git status
59+
shell: bash
60+
run: |-
61+
if [ -n "$(git status --porcelain)" ]; then
62+
echo "Running pkl resulted in a diff! You likely need to run 'pkl eval' and commit the changes."
63+
git diff --name-only
64+
exit 1
65+
fi
3866

3967
"""
4068
}

0 commit comments

Comments
 (0)