forked from adobe/react-spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (114 loc) · 5.61 KB
/
Copy pathweekly-api-diff.yml
File metadata and controls
131 lines (114 loc) · 5.61 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
name: Weekly API Diff
on:
schedule:
- cron: '0 17 * * 1' # Monday 9am PST / 10am PDT (GH Actions cron is UTC)
workflow_dispatch: # manual trigger for testing
jobs:
weekly-api-diff:
runs-on: ubuntu-latest
permissions:
contents: read
env:
SNAPSHOTS_REPO: LFDanLu/react-spectrum-api-snapshots
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required for build:api-published to find the last Publish commit
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'yarn'
- run: yarn --immutable
# Build current main API (~2 min, always fresh)
- name: Build current API snapshot
run: yarn build:api-branch
# Build release baseline using the last minor/major release commit (skips patch-only releases)
- name: Build release baseline
run: yarn build:api-published
- name: Generate diff
run: yarn compare:apis --isCI > /tmp/diff-current.md || true
# Check out snapshots repo so we can read the previous diff and commit the new one
- uses: actions/checkout@v4
with:
repository: ${{ env.SNAPSHOTS_REPO }}
path: snapshots
token: ${{ secrets.SNAPSHOTS_REPO_TOKEN }}
# Compute week-to-week delta and commit new diff
- name: Save diff and compute delta
run: |
TODAY=$(date +%Y-%m-%d)
echo "TODAY=$TODAY" >> $GITHUB_ENV
CURRENT_PUBLISH=$(git log --grep='^Publish$' --oneline -1 | awk '{print $1}')
PREV_PUBLISH=$(cat snapshots/last-publish-hash.txt 2>/dev/null || echo "")
echo "=== Release detection ==="
echo "CURRENT_PUBLISH=$CURRENT_PUBLISH"
echo "PREV_PUBLISH=$PREV_PUBLISH"
if [ -n "$PREV_PUBLISH" ] && [ "$CURRENT_PUBLISH" != "$PREV_PUBLISH" ]; then
# Detect minor/major vs patch: check if s2 or react-aria-components got a x.y.0 tag on this Publish commit
IS_MINOR=$(git tag --points-at "$CURRENT_PUBLISH" | grep -E '^(@react-spectrum/s2|react-aria-components)@[0-9]+\.[0-9]+\.0$' | head -1)
echo "IS_MINOR_OR_MAJOR=${IS_MINOR:-(none)}"
if [ -n "$IS_MINOR" ]; then
echo "Minor/major release detected, resetting baseline"
echo "NEW_RELEASE=true" >> $GITHUB_ENV
else
echo "Patch release detected, updating hash, continuing with delta"
echo "$CURRENT_PUBLISH" > snapshots/last-publish-hash.txt
fi
else
echo "No new release"
fi
NEW_RELEASE="${NEW_RELEASE:-false}"
if [ "$NEW_RELEASE" != "true" ]; then
# Compare against the last diff in the snapshots repo
PREV=$(ls snapshots/diffs/*.md 2>/dev/null | sort -r | head -1)
echo ""
echo "=== Delta computation ==="
echo "Comparing against: ${PREV:-(none, first run)}"
if [ -n "$PREV" ]; then
diff "$PREV" /tmp/diff-current.md > /tmp/weekly-delta.txt || true
else
echo "(first run — no previous diff to compare against)" > /tmp/weekly-delta.txt
fi
fi
echo ""
echo "=== File sizes ==="
echo "diff-current.md: $(wc -c < /tmp/diff-current.md) bytes"
ls /tmp/weekly-delta.txt 2>/dev/null && echo "weekly-delta.txt: $(wc -c < /tmp/weekly-delta.txt) bytes" || echo "weekly-delta.txt: not created"
echo ""
echo "=== Delta content (first 20 lines) ==="
head -20 /tmp/weekly-delta.txt 2>/dev/null || echo "(none)"
# Commit a diff if there is a new minor/major release (fresh baseline), or diff changed from last week
# 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
echo ""
echo "=== Commit decision ==="
if [ -s /tmp/diff-current.md ] && ([ "$NEW_RELEASE" = "true" ] || [ -s /tmp/weekly-delta.txt ]); then
echo "Committing diff to snapshots repo"
cp /tmp/diff-current.md snapshots/diffs/$TODAY.md
mkdir -p snapshots/deltas
if [ -s /tmp/weekly-delta.txt ]; then
# Save processed delta: strip > / < markers and line-number markers,
# split into two labeled sections so it can be passed directly to the model
{
echo "=== NEW API CHANGES THIS WEEK (not in last week's diff) ==="
grep '^> ' /tmp/weekly-delta.txt | sed 's/^> //'
RELEASED=$(grep '^< ' /tmp/weekly-delta.txt | sed 's/^< //')
if [ -n "$RELEASED" ]; then
echo ""
echo "=== API CHANGES RELEASED SINCE LAST WEEK (were in last week's diff, now gone) ==="
echo "$RELEASED"
fi
} > snapshots/deltas/$TODAY.md
fi
cd snapshots
git config user.email "github-actions@github.com"
git config user.name "GitHub Actions"
git add diffs/$TODAY.md
[ -f deltas/$TODAY.md ] && git add deltas/$TODAY.md
echo "$CURRENT_PUBLISH" > last-publish-hash.txt
git add last-publish-hash.txt
echo "=== Staged changes ==="
git diff --cached --stat
git diff --cached --quiet || (git commit -m "weekly api diff $TODAY" && git push)
else
echo "Skipping commit — diff-current empty=$([ ! -s /tmp/diff-current.md ] && echo yes || echo no), new_release=$NEW_RELEASE, delta_empty=$([ ! -s /tmp/weekly-delta.txt ] && echo yes || echo no)"
fi