Repository navigation
174 lines (160 loc) · 7.89 KB
/
Copy pathmodel-diff.yml
File metadata and controls
174 lines (160 loc) · 7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: model-diff
# saiku#1434 — when a pull request touches a semantic model, diff it against the base branch and
# report every saved query, dashboard and app the change would break.
#
# Deliberately NOT part of the required `ci` check:
# * it needs the base branch's model, so it cannot run on a push;
# * the finding is information for the reviewer, not a merge blocker — a rename that lands
# before the dashboards are updated is a normal (recoverable) state to be in.
# The workflow posts a sticky PR comment and fails only if the validator itself cannot run.
on:
pull_request:
paths:
- "**/*.xml"
- "**/*.yaml"
- "**/*.yml"
- "saiku-launcher/src/main/resources/seed/**"
- "saiku-core/saiku-service/src/main/java/org/saiku/service/schema/diff/**"
- ".github/workflows/model-diff.yml"
concurrency:
group: model-diff-${{ github.event.pull_request.number }}
cancel-in-progress: true
# Read the repo, write a comment. No other permission is used.
permissions:
contents: read
pull-requests: write
jobs:
diff:
name: semantic model diff
runs-on: ubuntu-latest
steps:
# Full history: the baseline is a blob in the base branch, not in the checkout.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up JDK 22
uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0
with:
distribution: temurin
java-version: "22"
cache: maven
# Never run a PR-controlled Maven build while a package credential is present: build the
# validator from the trusted base commit, then return to the PR content (saiku#2305).
- name: Select trusted base source
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
set -euo pipefail
git rev-parse HEAD > "$RUNNER_TEMP/model-diff-pr-head"
git checkout --detach "$BASE_SHA"
# The Spiculate dependencies live across three GitHub Packages registries, each needing a
# <server> entry; the auto-issued GITHUB_TOKEN cannot read packages across orgs, so the PAT
# secret is used. Same settings.xml shape as ci.yml.
- name: Configure Maven settings.xml
env:
GH_PACKAGES_USER: ${{ github.actor }}
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<EOF
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
<servers>
<server><id>github-mondrian-saiku</id><username>${GH_PACKAGES_USER}</username><password>${GH_PACKAGES_TOKEN}</password></server>
<server><id>github-olap4j</id><username>${GH_PACKAGES_USER}</username><password>${GH_PACKAGES_TOKEN}</password></server>
<server><id>github-olap4j-xmlaserver</id><username>${GH_PACKAGES_USER}</username><password>${GH_PACKAGES_TOKEN}</password></server>
<server><id>github-saiku-query</id><username>${GH_PACKAGES_USER}</username><password>${GH_PACKAGES_TOKEN}</password></server>
<server><id>github-ossie</id><username>${GH_PACKAGES_USER}</username><password>${GH_PACKAGES_TOKEN}</password></server>
</servers>
</settings>
EOF
# Only saiku-service is built: the validator is self-contained there, so this job skips the
# SvelteKit bundle that saiku-webapp's frontend plugin would otherwise download and build.
- name: Build saiku-service
run: mvn -B -ntp -q -pl saiku-core/saiku-service -am -DskipTests -Dmaven.test.skip=true install
- name: Resolve classpath and return to PR content
run: |
set -euo pipefail
mvn -B -ntp -q -pl saiku-core/saiku-service dependency:build-classpath \
-Dmdep.outputFile="$PWD/target/classpath.txt"
rm -f ~/.m2/settings.xml
git checkout --detach "$(cat "$RUNNER_TEMP/model-diff-pr-head")"
- name: Collect the repository content
run: |
set -euo pipefail
mkdir -p target/repository
# Everything under a repository/ directory in the tree: saved queries, dashboards, apps.
# (git ls-files keeps this deterministic and skips build output.)
while IFS= read -r file; do
case "$file" in
*/repository/*|repository/*)
mkdir -p "target/repository/$(dirname "${file#*repository/}")"
cp "$file" "target/repository/${file#*repository/}"
;;
esac
done < <(git ls-files)
echo "repository files: $(find target/repository -type f | wc -l)"
- name: Run the validator
id: validator
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
set -uo pipefail
BASE="origin/${BASE_REF}"
git fetch --no-tags origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}" || true
MODEL="org.saiku.service.schema.diff.ModelDiffTool"
CP="saiku-core/saiku-service/target/classes:$(cat target/classpath.txt)"
status=0
report=""
# Every model file the pull request touched, diffed against its base-branch version.
while IFS= read -r model; do
echo "--- $model"
if ! git cat-file -e "${BASE}:${model}" 2>/dev/null; then
echo "::notice::$model is new in this pull request — nothing to diff it against."
continue
fi
# The path filter is deliberately broad (any xml/yaml), so most matches are NOT semantic
# models: workflows, poms, Spring XML. The tool exits 2 when it cannot read a file as a
# model; that means "not a model", not "the validator is broken", so skip it rather than
# fail every pull request that touches a workflow. (The step runs under `bash -e`, hence
# the explicit `|| rc=$?`.)
rc=0
out=$(java -cp "$CP" "$MODEL" \
--from-git "$BASE" --from-git HEAD \
--before "$model" --after "$model" \
--repository target/repository --no-fail-on-broken 2>&1) || rc=$?
if [ "$rc" -eq 2 ]; then
echo "::notice::$model is not a semantic model — skipped."
continue
fi
echo "$out"
report="${report}${out}"$'\n\n'
if [ "$rc" -ne 0 ]; then
status="$rc"
fi
done < <(git diff --name-only --diff-filter=ACMR "origin/${BASE_REF}...HEAD" -- '*.xml' '*.yaml' '*.yml')
if [ -z "$report" ]; then
report="No semantic model changed in this pull request, so there was nothing to diff."
fi
printf '%s' "$report" > model-diff-report.md
echo "$report" >> "$GITHUB_STEP_SUMMARY"
exit "$status"
- name: Comment the report
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('model-diff-report.md', 'utf8');
const marker = '<!-- saiku-model-diff saiku#1434 -->';
const body = `${marker}\n### Semantic model diff\n\n${report}\n<sub>saiku#1434 · reproduce locally with \`saiku model diff\`</sub>`;
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existing = comments.find((c) => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body });
}