Skip to content

Commit 4880395

Browse files
committed
Simplify spec-drift body construction
- Capture the diff directly in the existing `if ! diff …` (errexit is already exempt inside `if`), removing the separate `-q` pre-check, the intermediate pretty-printed tempfiles, and the `|| true` workaround. - Replace the multi-echo body wrapper with two `printf`s and a 1-line bash `&&` truncation marker. - Pass `--label vendored --label upstream` to `diff` so the issue body shows meaningful headers instead of `/dev/fd/63`.
1 parent f546cc6 commit 4880395

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

.github/workflows/spec-drift.yml

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,27 @@ jobs:
2222
- name: Check for drift
2323
id: drift
2424
run: |
25-
python3 -m json.tool --sort-keys openapi.json > /tmp/vendored-spec.json
26-
python3 -m json.tool --sort-keys /tmp/latest-spec.json > /tmp/upstream-spec.json
27-
if diff -q /tmp/vendored-spec.json /tmp/upstream-spec.json > /dev/null 2>&1; then
28-
exit 0
25+
if ! diff -u --label vendored --label upstream <(python3 -m json.tool --sort-keys openapi.json) <(python3 -m json.tool --sort-keys /tmp/latest-spec.json) > /tmp/spec.diff; then
26+
echo "drifted=true" >> "$GITHUB_OUTPUT"
2927
fi
30-
echo "drifted=true" >> "$GITHUB_OUTPUT"
31-
# diff exits 1 when files differ; pipefail would trip errexit, so capture first.
32-
diff -u /tmp/vendored-spec.json /tmp/upstream-spec.json > /tmp/spec.diff || true
33-
{
34-
echo "The spec at api.ionq.co/v0.4/api-docs has diverged from the vendored openapi.json. Fetch the new spec and regenerate the client."
35-
echo
36-
echo "<details><summary>Diff (vendored → upstream, pretty-printed JSON)</summary>"
37-
echo
38-
echo '```diff'
39-
head -c 60000 /tmp/spec.diff
40-
if [[ $(wc -c < /tmp/spec.diff) -gt 60000 ]]; then
41-
echo
42-
echo "... (diff truncated at 60000 bytes; fetch the spec to see the rest)"
43-
fi
44-
echo '```'
45-
echo
46-
echo "</details>"
47-
} > /tmp/issue-body.md
4828
- name: Open or update issue
4929
if: steps.drift.outputs.drifted == 'true'
5030
env:
5131
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5232
run: |
33+
{
34+
echo "The spec at api.ionq.co/v0.4/api-docs has diverged from the vendored openapi.json. Fetch the new spec and regenerate the client."
35+
printf '\n<details><summary>Diff (sorted, pretty-printed JSON)</summary>\n\n```diff\n'
36+
head -c 60000 /tmp/spec.diff
37+
[[ $(wc -c < /tmp/spec.diff) -gt 60000 ]] && printf '\n... (truncated)\n'
38+
printf '```\n</details>\n'
39+
} > /tmp/body.md
5340
existing=$(gh issue list --label spec-drift --state open --json number --jq '.[0].number // empty')
5441
if [[ -z "$existing" ]]; then
5542
gh issue create \
5643
--title "OpenAPI spec has changed upstream" \
57-
--body-file /tmp/issue-body.md \
44+
--body-file /tmp/body.md \
5845
--label spec-drift
5946
else
60-
gh issue edit "$existing" --body-file /tmp/issue-body.md
47+
gh issue edit "$existing" --body-file /tmp/body.md
6148
fi

0 commit comments

Comments
 (0)