-
Notifications
You must be signed in to change notification settings - Fork 0
220 lines (188 loc) · 7.17 KB
/
ci.yml
File metadata and controls
220 lines (188 loc) · 7.17 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
pull-request:
name: Pull request checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 9.14.2
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Get changed files
id: changed
run: |
files=$(git diff --name-only --diff-filter=ACMR origin/main...HEAD | tr '\n' ' ')
echo "files=$files" >> "$GITHUB_OUTPUT"
- name: Get changed codemod package dirs
id: codemods
run: |
roots=""
for f in $(git diff --name-only origin/main...HEAD -- 'codemods/' || true); do
[ -z "$f" ] && continue
d=$(dirname "$f")
while [ "$d" != "." ] && [ "$d" != "/" ]; do
if [ -f "$d/package.json" ] && [[ "$d" == codemods/* ]]; then
roots="${roots}"$'\n'"$d"
break
fi
parent=$(dirname "$d")
[ "$parent" = "$d" ] && break
d=$parent
done
done
dirs=$(printf '%s\n' "$roots" | sort -u | grep -v '^$' | tr '\n' ' ')
echo "dirs=$dirs" >> "$GITHUB_OUTPUT"
- name: Format check (changed files)
if: steps.changed.outputs.files != ''
run: pnpm run format:check ${{ steps.changed.outputs.files }}
- name: Lint (changed files)
if: steps.changed.outputs.files != ''
run: pnpm run lint ${{ steps.changed.outputs.files }}
- name: Markdown link check
run: pnpm run docs:links
- name: Test (changed codemods)
if: steps.codemods.outputs.dirs != ''
run: |
for dir in ${{ steps.codemods.outputs.dirs }}; do
(cd "$dir" && pnpm test)
done
- name: Typecheck (changed codemods)
if: steps.codemods.outputs.dirs != ''
run: |
for dir in ${{ steps.codemods.outputs.dirs }}; do
(cd "$dir" && pnpm run check-types)
done
push-verify:
name: Full workspace (main)
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: pnpm/action-setup@v4
with:
version: 9.14.2
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm run docs:links
- run: pnpm run ci
changeset-check:
name: Changeset Check
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 9.14.2
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Check for changeset
env:
SKIP_LABEL: skip-changeset
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
run: |
changed_dirs=""
for f in $(git diff --name-only --diff-filter=ACMR origin/main...HEAD -- 'codemods/' | grep -v '/tests/' || true); do
[ -z "$f" ] && continue
d=$(dirname "$f")
while [ "$d" != "." ] && [ "$d" != "/" ]; do
if [ -f "$d/package.json" ] && [[ "$d" == codemods/* ]]; then
changed_dirs="${changed_dirs}"$'\n'"$d"
break
fi
parent=$(dirname "$d")
[ "$parent" = "$d" ] && break
d=$parent
done
done
# grep exits 1 when it filters down to zero lines; with `bash -e` that would
# abort before we can treat "no codemod dirs" as success (changeset-only PRs).
changed_dirs=$(printf '%s\n' "$changed_dirs" | sort -u | grep -v '^$' || true)
if [ -z "$changed_dirs" ]; then
echo "No codemod source files changed. Changeset not required."
exit 0
fi
changed_packages=""
for dir in $changed_dirs; do
if [ -f "$dir/package.json" ]; then
pkg=$(node -p "require('./$dir/package.json').name")
changed_packages="$changed_packages $pkg"
fi
done
changed_packages=$(echo "$changed_packages" | xargs)
if [ -z "$changed_packages" ]; then
echo "Changed directories have no package.json. Changeset not required."
exit 0
fi
echo "Changed packages:"
echo "$changed_packages" | tr ' ' '\n'
if echo "$PR_LABELS" | grep -q "$SKIP_LABEL"; then
echo "skip-changeset label found. Skipping changeset requirement."
exit 0
fi
# Resolve the whole `.changeset/` tree; a quoted `*.md` pathspec is treated
# literally on many Linux/Git combinations and matches nothing, producing
# false "missing changeset" failures when codemods/ did change.
changeset_files=$(git diff --name-only --diff-filter=ACMR origin/main...HEAD -- .changeset \
| grep '\.md$' \
| grep -v 'README.md' \
|| true)
covered_packages=""
for f in $changeset_files; do
pkgs=$(sed -n '/^---$/,/^---$/{ /^---$/d; s/['\''`]//g; s/:.*//; p; }' "$f")
covered_packages="$covered_packages $pkgs"
done
covered_packages=$(echo "$covered_packages" | xargs)
missing=""
for pkg in $changed_packages; do
# Exact line match: `grep -w` is unreliable for hyphenated npm-style names on GNU grep.
if ! printf '%s\n' $covered_packages | grep -Fxq "$pkg"; then
missing="$missing $pkg"
fi
done
missing=$(echo "$missing" | xargs)
if [ -z "$missing" ]; then
echo "All changed packages have changesets."
exit 0
fi
echo "::error::Missing changeset for: $missing"
echo ""
echo "The following packages were changed but not covered by a changeset:"
for pkg in $missing; do
echo " - $pkg"
done
echo ""
echo "You have three options:"
echo " 1. Run 'pnpm changeset' to add a changeset covering the missing packages"
echo " 2. Add an empty changeset (no packages selected) if no version bump is needed"
echo " 3. Add the 'skip-changeset' label to this PR"
exit 1