Skip to content

Commit 00ef496

Browse files
committed
add clarity for various diff cases
running diff right after new release when there are new changes, running diff between releases, where there are no changes between last run, and when there are no changes from the released code
1 parent 07fda63 commit 00ef496

1 file changed

Lines changed: 35 additions & 12 deletions

File tree

.github/workflows/weekly-api-diff.yml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,33 @@ jobs:
4949
TODAY=$(date +%Y-%m-%d)
5050
echo "TODAY=$TODAY" >> $GITHUB_ENV
5151
52-
# Compare against most recent existing diff BEFORE writing the diff
53-
# so that we dont report a diff if we run before a week passes and nothing has changed
54-
PREV=$(ls -t snapshots/diffs/*.txt 2>/dev/null | head -1)
55-
if [ -n "$PREV" ]; then
56-
diff "$PREV" /tmp/diff-current.txt > /tmp/weekly-delta.txt || true
52+
CURRENT_PUBLISH=$(git log --grep='^Publish$' --oneline -1 | awk '{print $1}')
53+
PREV_PUBLISH=$(cat snapshots/last-publish-hash.txt 2>/dev/null || echo "")
54+
55+
if [ -n "$PREV_PUBLISH" ] && [ "$CURRENT_PUBLISH" != "$PREV_PUBLISH" ]; then
56+
# New release landed so skip comparing to last week, commit fresh as new baseline
57+
echo "NEW_RELEASE=true" >> $GITHUB_ENV
5758
else
58-
echo "(first run — no previous diff to compare against)" > /tmp/weekly-delta.txt
59+
# Compare against the last diff in the snapshots repo
60+
PREV=$(ls -t snapshots/diffs/*.txt 2>/dev/null | head -1)
61+
if [ -n "$PREV" ]; then
62+
diff "$PREV" /tmp/diff-current.txt > /tmp/weekly-delta.txt || true
63+
else
64+
echo "(first run — no previous diff to compare against)" > /tmp/weekly-delta.txt
65+
fi
5966
fi
6067
61-
# Only commit if there are pending API changes and they differ from last week.
62-
# If diff-current is empty (release landed), skip commit so the previous
63-
# non-empty diff stays as the baseline for next week's comparison.
64-
if [ -s /tmp/diff-current.txt ] && [ -s /tmp/weekly-delta.txt ]; then
68+
# Commit a diff if there is a new release (fresh baseline), or diff changed from last week
69+
# Skip if no difference from last diff (aka no change from last week/last run), or if the diff against the release code is empty
70+
NEW_RELEASE="${NEW_RELEASE:-false}"
71+
if [ "$NEW_RELEASE" = "true" ] || ([ -s /tmp/diff-current.txt ] && [ -s /tmp/weekly-delta.txt ]); then
6572
cp /tmp/diff-current.txt snapshots/diffs/$TODAY.txt
6673
cd snapshots
6774
git config user.email "github-actions@github.com"
6875
git config user.name "GitHub Actions"
6976
git add diffs/$TODAY.txt
77+
echo "$CURRENT_PUBLISH" > last-publish-hash.txt
78+
git add last-publish-hash.txt
7079
git diff --cached --quiet || (git commit -m "weekly api diff $TODAY" && git push)
7180
fi
7281
@@ -96,8 +105,22 @@ jobs:
96105
vs_release_size = os.path.getsize('/tmp/diff-current.txt')
97106
vs_last_week_size = os.path.getsize('/tmp/weekly-delta.txt') if os.path.exists('/tmp/weekly-delta.txt') else 0
98107
99-
if vs_release_size == 0 or vs_last_week_size == 0:
100-
message = f"📊 Weekly API Diff — {today}\n\nNo API changes vs release baseline this week — either nothing new has landed on main yet, or all pending changes were included in a release."
108+
prev_files = sorted(
109+
[f for f in __import__('glob').glob(f"{workspace}/snapshots/diffs/*.txt")],
110+
key=os.path.getmtime, reverse=True
111+
)
112+
prev_date = os.path.basename(prev_files[0]).replace('.txt', '') if prev_files else None
113+
prev_url = f"https://github.com/{snapshots_repo}/blob/main/diffs/{prev_date}.txt" if prev_date else None
114+
115+
new_release = os.environ.get('NEW_RELEASE') == 'true'
116+
117+
if vs_release_size == 0:
118+
message = f"📊 Weekly API Diff — {today}\n\nNo API changes detected vs last release — all pending changes have been included in a release."
119+
elif vs_last_week_size == 0 and not new_release:
120+
prev_ref = f"last diff ({prev_date}): {prev_url}" if prev_date else "last diff"
121+
message = f"📊 Weekly API Diff — {today}\n\nNo new API changes since {prev_ref}."
122+
elif new_release:
123+
message = f"📊 Weekly API Diff — {today}\n\nNew release since last diff — resetting baseline. Full diff vs release: {diff_url}\n\nReact ✅ if changes look expected, or 🚨 if something looks wrong."
101124
else:
102125
delta = open('/tmp/weekly-delta.txt').read()[:4000]
103126

0 commit comments

Comments
 (0)