Skip to content

Commit 30dfa0b

Browse files
authored
CI: add basic workflow (#27)
This adds a very basic CI workflow, running tests and compliance-tests. Compliance tests currently don't all pass, so that's non-fatal. The workflow will create a summary of the differences of passed/failed compliance tests between main and the PR branch. Notable side-quests: * ci: make test-compliance non-failure * ComplianceSuite/Makefile: don't require rq and gsed That'll make it run without a setup step on the Github runners. * ci: use xcode-select method for swift version I have tried various other methods (docker image, setup-swift action), but each had its own problems. We can revisit this when setup-swift supports 6.2, or when this project can run its compliance tests on Linux. (The latter is an issue tracked elsewhere.) Signed-off-by: Stephan Renatus <[email protected]>
1 parent fd0f953 commit 30dfa0b

File tree

5 files changed

+87
-8
lines changed

5 files changed

+87
-8
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Check
2+
3+
on:
4+
workflow_dispatch: {}
5+
pull_request: {}
6+
7+
# When a new revision is pushed to a PR, cancel all in-progress CI runs for that
8+
# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
ci:
15+
name: 'make all'
16+
runs-on: macos-latest
17+
permissions:
18+
contents: read
19+
steps:
20+
- run: sudo xcode-select -s /Applications/Xcode_26.0.app
21+
- run: swift --version
22+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
- run: make all
24+
- name: make fmt lint (ComplianceSuite)
25+
run: make fmt lint
26+
working-directory: ComplianceSuite
27+
- run: make test-compliance || true # NB: This doesn't succeed yet!
28+
29+
diff:
30+
name: diff compliance tests (vs main)
31+
runs-on: macos-latest
32+
permissions:
33+
contents: read
34+
steps:
35+
- run: sudo xcode-select -s /Applications/Xcode_26.0.app
36+
- run: swift --version
37+
- name: checkout PR
38+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
39+
with:
40+
path: pr/swift-opa
41+
fetch-depth: 0 # fetch all history for all branches and tags
42+
- name: checkout main
43+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
44+
with:
45+
repository: open-policy-agent/swift-opa
46+
ref: main
47+
path: main/swift-opa
48+
- name: compliance tests (main)
49+
run: |
50+
(make test-compliance || true) > results
51+
../../../pr/swift-opa/ComplianceSuite/tools/passed.sh < results > ../../../main-passed
52+
../../../pr/swift-opa/ComplianceSuite/tools/failed.sh < results > ../../../main-failed
53+
working-directory: main/swift-opa/ComplianceSuite
54+
- name: compliance tests (pr)
55+
run: |
56+
(make test-compliance || true) > results
57+
./tools/passed.sh < results > ../../../pr-passed
58+
./tools/failed.sh < results > ../../../pr-failed
59+
working-directory: pr/swift-opa/ComplianceSuite
60+
- name: summary diff
61+
run: |
62+
diff_and_print() {
63+
local file1="$1"
64+
local file2="$2"
65+
local header="$3"
66+
67+
if ! diff -q "$file1" "$file2" > /dev/null 2>&1; then
68+
echo "## $header"
69+
echo '```diff'
70+
diff "$file1" "$file2" || true
71+
echo '```'
72+
fi
73+
}
74+
diff_and_print main-passed pr-passed 'passed (main vs PR)' >> $GITHUB_STEP_SUMMARY
75+
diff_and_print main-failed pr-failed 'failed (main vs PR)' >> $GITHUB_STEP_SUMMARY

ComplianceSuite/Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ test-compliance:
2323
test-failed:
2424
@OPA_COMPLIANCE_TESTS="$(OPA_COMPLIANCE_TESTS)" \
2525
swift test --filter ComplianceTests.ComplianceTests \
26-
| rg '' | rg -v builtinNotFound \
27-
| gsed -nre 's/.*❌ (.*) ->.*/\1/p' \
28-
| sort | uniq
26+
| ./tools/failed.sh
2927

3028
.PHONY: test-passed
3129
test-passed:
3230
@OPA_COMPLIANCE_TESTS="$(OPA_COMPLIANCE_TESTS)" \
3331
swift test --filter ComplianceTests.ComplianceTests \
34-
| rg '' \
35-
| gsed -nre 's/.*✅ (.*) ->.*/\1/p' \
36-
| sort | uniq
32+
| ./tools/passed.sh
3733

3834
.PHONY: clean
3935
clean:

ComplianceSuite/tools/failed.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
sed -n '/❌/ { /builtinUndefinedError/! s/.*❌ \(.*\) ->.*/\1/p; }' \
3+
| sort | uniq

ComplianceSuite/tools/passed.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
sed -n '/✅/ { s/.*✅ \(.*\) ->.*/\1/p; }' \
3+
| sort | uniq

Tests/RegoTests/IREvaluatorTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ struct IREvaluatorTests {
148148

149149
@Test(arguments: validTestCases)
150150
func testValidEvaluations(tc: TestCase) async throws {
151-
var engine = OPA.Engine(bundlePaths: tc.sourceBundles.map({ OPA.Engine.BundlePath(name: $0.lastPathComponent, url: $0) }))
151+
var engine = OPA.Engine(
152+
bundlePaths: tc.sourceBundles.map({ OPA.Engine.BundlePath(name: $0.lastPathComponent, url: $0) }))
152153
let bufferTracer = OPA.Trace.BufferedQueryTracer(level: .full)
153154
let actual = try await engine.prepareForEvaluation(query: tc.query).evaluate(
154155
input: tc.input,
@@ -175,7 +176,8 @@ struct IREvaluatorTests {
175176

176177
@Test(arguments: errorTestCases)
177178
func testInvalidEvaluations(tc: ErrorCase) async throws {
178-
var engine = OPA.Engine(bundlePaths: tc.sourceBundles.map({ OPA.Engine.BundlePath(name: $0.lastPathComponent, url: $0) }))
179+
var engine = OPA.Engine(
180+
bundlePaths: tc.sourceBundles.map({ OPA.Engine.BundlePath(name: $0.lastPathComponent, url: $0) }))
179181

180182
await #expect(Comment(rawValue: tc.description)) {
181183
let _ = try await engine.prepareForEvaluation(query: tc.query).evaluate(input: tc.input)

0 commit comments

Comments
 (0)