-
Notifications
You must be signed in to change notification settings - Fork 52
259 lines (228 loc) · 9.36 KB
/
Copy pathregenerate-test.yml
File metadata and controls
259 lines (228 loc) · 9.36 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# Regenerates smoke test file(s) and creates a PR with the changes.
# Optionally builds a custom updater image from a dependabot-core branch or PR
# to regenerate tests before merging core changes.
#
# Provide 'test' for a single test, or 'ecosystem' to regenerate all tests
# sharing a package-manager (e.g. npm_and_yarn → npm, npm-group-rules, etc.)
name: Regenerate Test
on: # yamllint disable-line rule:truthy
workflow_dispatch:
inputs:
test:
description: 'Test name (e.g. npm, bundler, go). Leave empty if using ecosystem.'
required: false
type: string
ecosystem:
description: 'Regenerate ALL tests for this package-manager (e.g. npm_and_yarn, go_modules, pip)'
required: false
type: string
core-branch:
description: 'dependabot-core branch name (for internal branches)'
required: false
type: string
core-pr-number:
description: 'dependabot-core PR number (for any PR including forks)'
required: false
type: number
permissions:
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INPUT_TEST: ${{ inputs.test }}
INPUT_ECOSYSTEM: ${{ inputs.ecosystem }}
INPUT_CORE_BRANCH: ${{ inputs['core-branch'] }}
INPUT_CORE_PR: ${{ inputs['core-pr-number'] }}
jobs:
regenerate:
runs-on: ubuntu-latest
name: Regenerate ${{ inputs.test || inputs.ecosystem }}
steps:
- uses: actions/checkout@v7
- name: Resolve test list
id: tests
run: |
if [ -z "$INPUT_TEST" ] && [ -z "$INPUT_ECOSYSTEM" ]; then
echo "Error: Provide either 'test' or 'ecosystem'."
exit 1
fi
if [ -n "$INPUT_TEST" ] && [ -n "$INPUT_ECOSYSTEM" ]; then
echo "Error: Provide only one of 'test' or 'ecosystem', not both."
exit 1
fi
if [ -n "$INPUT_CORE_BRANCH" ] && [ -n "$INPUT_CORE_PR" ]; then
echo "Error: Provide only one of 'core-branch' or 'core-pr-number', not both."
exit 1
fi
if [ -n "$INPUT_TEST" ]; then
TEST_FILE="tests/smoke-${INPUT_TEST}.yaml"
if [ ! -f "$TEST_FILE" ]; then
echo "::error::Test file '$TEST_FILE' does not exist."
echo "Available tests:"
ls tests/smoke-*.yaml | sed 's|tests/smoke-||;s|\.yaml||'
exit 1
fi
echo "list=${INPUT_TEST}" >> "$GITHUB_OUTPUT"
echo "label=${INPUT_TEST}" >> "$GITHUB_OUTPUT"
else
MATCHES=$(grep -rl "package-manager: ${INPUT_ECOSYSTEM}" tests/smoke-*.yaml \
| sed 's|tests/smoke-||;s|\.yaml||' | sort)
if [ -z "$MATCHES" ]; then
echo "::error::No tests found with package-manager '${INPUT_ECOSYSTEM}'."
echo "Available package-managers:"
grep -rh 'package-manager:' tests/smoke-*.yaml | awk '{print $2}' | sort -u
exit 1
fi
echo "Found tests for '${INPUT_ECOSYSTEM}':"
echo "$MATCHES"
echo "list=$(echo $MATCHES | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
echo "label=${INPUT_ECOSYSTEM}" >> "$GITHUB_OUTPUT"
fi
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: stable
- name: Install Dependabot CLI
run: go install github.com/dependabot/cli/cmd/dependabot@latest
# When a core branch or PR is specified, check out dependabot-core and
# build the updater image locally — the same approach used by
# dependabot-core's own smoke pipeline.
- name: Checkout dependabot-core
if: inputs.core-branch != '' || inputs.core-pr-number != ''
uses: actions/checkout@v7
with:
repository: dependabot/dependabot-core
path: dependabot-core
submodules: recursive
- name: Checkout core branch or PR
if: inputs.core-branch != '' || inputs.core-pr-number != ''
working-directory: dependabot-core
run: |
if [ -n "$INPUT_CORE_PR" ]; then
echo "Checking out PR #${INPUT_CORE_PR}"
gh pr checkout "$INPUT_CORE_PR" --repo dependabot/dependabot-core
else
echo "Checking out branch '${INPUT_CORE_BRANCH}'"
git fetch origin "$INPUT_CORE_BRANCH"
git checkout -B "$INPUT_CORE_BRANCH" FETCH_HEAD
fi
echo "Checked out commit: $(git rev-parse HEAD)"
- name: Build updater image
id: build
if: inputs.core-branch != '' || inputs.core-pr-number != ''
env:
TEST_LIST: ${{ steps.tests.outputs.list }}
run: |
# All tests for an ecosystem share the same package-manager by
# construction (the resolve step greps for it), so the first is safe.
FIRST_TEST=$(echo "$TEST_LIST" | awk '{print $1}')
PKG_MGR=$(grep 'package-manager:' "tests/smoke-${FIRST_TEST}.yaml" | head -1 | awk '{print $2}')
# Map package-manager names to dependabot-core build directory names
case "$PKG_MGR" in
pip) BUILD_ECO="python" ;;
submodules) BUILD_ECO="git_submodules" ;;
*) BUILD_ECO="$PKG_MGR" ;;
esac
echo "Building image for package-manager: $PKG_MGR (ecosystem: $BUILD_ECO)"
cd dependabot-core
script/build "$BUILD_ECO"
IMAGE=$(docker images --format '{{.Repository}}:{{.Tag}}' | grep 'dependabot-updater-' | grep ':latest$' | head -1)
if [ -z "$IMAGE" ]; then
echo "::error::No dependabot updater image found after building '$PKG_MGR'"
exit 1
fi
echo "Built image: $IMAGE"
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
- name: Regenerate tests
env:
LOCAL_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEST_LIST: ${{ steps.tests.outputs.list }}
UPDATER_IMAGE: ${{ steps.build.outputs.image }}
run: |
UPDATER_IMAGE_ARG=""
if [ -n "$UPDATER_IMAGE" ]; then
UPDATER_IMAGE_ARG="--updater-image=$UPDATER_IMAGE"
fi
FAILED=""
for TEST in $TEST_LIST; do
echo "::group::Regenerating $TEST"
TEST_FILE="tests/smoke-${TEST}.yaml"
RESULT_FILE="result-${TEST}.yaml"
# Download existing proxy cache, same as the Smoke workflow.
rm -rf cache
script/download-cache.sh "$TEST" || true
dependabot test \
-f="$TEST_FILE" \
-o="$RESULT_FILE" \
--timeout=20m \
--cache=cache \
$UPDATER_IMAGE_ARG \
2>&1 | tee "regen-${TEST}.log" || true
if ! grep -q "^output:" "$RESULT_FILE" 2>/dev/null; then
echo "::error::Failed to regenerate $TEST"
FAILED="$FAILED $TEST"
else
cp "$RESULT_FILE" "$TEST_FILE"
echo "✓ $TEST regenerated successfully"
fi
echo "::endgroup::"
done
if [ -n "$FAILED" ]; then
echo "::error::Failed tests:$FAILED"
exit 1
fi
- name: Diff
continue-on-error: true
env:
TEST_LIST: ${{ steps.tests.outputs.list }}
run: |
for TEST in $TEST_LIST; do
echo "--- $TEST ---"
git diff "tests/smoke-${TEST}.yaml" || true
done
- name: Create Pull Request
env:
TEST_LIST: ${{ steps.tests.outputs.list }}
TEST_LABEL: ${{ steps.tests.outputs.label }}
run: |
CHANGED=""
for TEST in $TEST_LIST; do
if ! git diff --quiet "tests/smoke-${TEST}.yaml"; then
CHANGED="$CHANGED $TEST"
fi
done
if [ -z "$CHANGED" ]; then
echo "No changes detected — nothing to do."
exit 0
fi
LABEL="$TEST_LABEL"
BRANCH_NAME="regenerate-test-${LABEL}-$(date +%s)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
for TEST in $CHANGED; do
cp "tests/smoke-${TEST}.yaml" "/tmp/smoke-${TEST}.yaml"
done
git fetch origin main
git checkout -B "$BRANCH_NAME" origin/main
for TEST in $CHANGED; do
cp "/tmp/smoke-${TEST}.yaml" "tests/smoke-${TEST}.yaml"
git add "tests/smoke-${TEST}.yaml"
done
git commit -m "Regenerate ${LABEL} tests"
git push origin "$BRANCH_NAME"
CORE_NOTE=""
if [ -n "$INPUT_CORE_BRANCH" ]; then
CORE_NOTE=$'\n'"**dependabot-core branch:** \`${INPUT_CORE_BRANCH}\`"$'\n'
elif [ -n "$INPUT_CORE_PR" ]; then
CORE_NOTE=$'\n'"**dependabot-core PR:** https://github.com/dependabot/dependabot-core/pull/${INPUT_CORE_PR}"$'\n'
fi
TESTS_LIST=""
for TEST in $CHANGED; do
TESTS_LIST="${TESTS_LIST}"$'\n'"- ${TEST}"
done
BODY="$(printf 'This PR regenerates the following smoke tests:\n%s\n\n%s\nPlease review the changes to ensure they are expected.' "$TESTS_LIST" "$CORE_NOTE")"
gh pr create \
--title "Regenerate ${LABEL} tests" \
--body "$BODY" \
--base main \
--head "$BRANCH_NAME"