Skip to content

Commit 07fda63

Browse files
committed
handle case where new release happens runs and check last diff repo commit rather than just last week
the latter is to handle the case where we run this flow multiple times a day or in the same week and there arent any new changes. Previously it would still use the current weeks diff results rather than reporting that there are no changes
1 parent 7ceb1c1 commit 07fda63

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: yarn build:api-published
3535

3636
- name: Generate diff
37-
run: yarn compare:apis --isCI > /tmp/diff-current.txt || true
37+
run: yarn --silent compare:apis --isCI > /tmp/diff-current.txt || true
3838

3939
# Check out snapshots repo so we can read the previous diff and commit the new one
4040
- uses: actions/checkout@v4
@@ -49,16 +49,20 @@ jobs:
4949
TODAY=$(date +%Y-%m-%d)
5050
echo "TODAY=$TODAY" >> $GITHUB_ENV
5151
52-
cp /tmp/diff-current.txt snapshots/diffs/$TODAY.txt
53-
54-
PREV=$(ls -t snapshots/diffs/*.txt 2>/dev/null | sed -n '2p')
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)
5555
if [ -n "$PREV" ]; then
56-
diff "$PREV" snapshots/diffs/$TODAY.txt > /tmp/weekly-delta.txt || true
56+
diff "$PREV" /tmp/diff-current.txt > /tmp/weekly-delta.txt || true
5757
else
5858
echo "(first run — no previous diff to compare against)" > /tmp/weekly-delta.txt
5959
fi
6060
61-
if [ -s /tmp/diff-current.txt ]; then
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
65+
cp /tmp/diff-current.txt snapshots/diffs/$TODAY.txt
6266
cd snapshots
6367
git config user.email "github-actions@github.com"
6468
git config user.name "GitHub Actions"
@@ -89,9 +93,10 @@ jobs:
8993
workspace = os.environ['GITHUB_WORKSPACE']
9094
diff_url = f"https://github.com/{snapshots_repo}/blob/main/diffs/{today}.txt"
9195
92-
diff_size = os.path.getsize('/tmp/diff-current.txt')
96+
vs_release_size = os.path.getsize('/tmp/diff-current.txt')
97+
vs_last_week_size = os.path.getsize('/tmp/weekly-delta.txt') if os.path.exists('/tmp/weekly-delta.txt') else 0
9398
94-
if diff_size == 0:
99+
if vs_release_size == 0 or vs_last_week_size == 0:
95100
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."
96101
else:
97102
delta = open('/tmp/weekly-delta.txt').read()[:4000]

0 commit comments

Comments
 (0)