-
Notifications
You must be signed in to change notification settings - Fork 407
250 lines (231 loc) · 9.77 KB
/
Copy pathdependabot-automation.yml
File metadata and controls
250 lines (231 loc) · 9.77 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
name: 'Dependabot Automation'
on:
pull_request:
types:
- opened
- reopened
- synchronize
env:
# Add Groups here to enable auto-merge for Dependabot PRs
GROUPS: '["dev-minor-and-patch-dependencies", "gh-actions-packages", "test-versions"]'
jobs:
dependabot:
if: github.event.pull_request.user.login == 'dependabot[bot]'
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
id: octo-sts
with:
scope: DataDog/dd-trace-js
policy: dependabot-automation
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # 2.5.0
with:
github-token: "${{ steps.octo-sts.outputs.token }}"
- name: Approve a PR
if: contains(fromJSON(env.GROUPS), steps.metadata.outputs.dependency-group)
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
- name: Enable auto-merge for Dependabot PRs
if: contains(fromJSON(env.GROUPS), steps.metadata.outputs.dependency-group)
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
vendor-build:
if: github.event.pull_request.user.login == 'dependabot[bot]'
runs-on: ubuntu-latest
# Security: this job checks out and runs code from the PR (vendoring build),
# so it is intentionally restricted to read-only permissions and produces a
# patch artifact instead of pushing directly.
permissions:
contents: read
pull-requests: read
outputs:
has_changes: ${{ steps.diff.outputs.has_changes }}
is_vendor_group: ${{ steps.ctx.outputs.is_vendor_group }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # 2.5.0
- name: Compute vendor context
id: ctx
run: |
set -euo pipefail
echo "is_vendor_group=${{ steps.metadata.outputs.directory == '/vendor' }}" >> $GITHUB_OUTPUT
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: steps.ctx.outputs.is_vendor_group == 'true'
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 1
persist-credentials: false
- name: Restore trusted Node setup actions
if: steps.ctx.outputs.is_vendor_group == 'true'
run: |
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
git checkout "${{ github.event.pull_request.base.sha }}" -- .github/actions/node
- name: Restore trusted vendoring scripts
if: steps.ctx.outputs.is_vendor_group == 'true'
run: |
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
git checkout "${{ github.event.pull_request.base.sha }}" -- vendor/rspack.js vendor/rspack.config.js
- uses: ./.github/actions/node/active-lts
if: steps.ctx.outputs.is_vendor_group == 'true'
- name: Install vendoring deps (no lifecycle scripts)
if: steps.ctx.outputs.is_vendor_group == 'true'
run: yarn --ignore-scripts --frozen-lockfile --non-interactive
working-directory: ./vendor
- name: Build vendored bundles (trusted script)
if: steps.ctx.outputs.is_vendor_group == 'true'
run: node ./rspack.js
working-directory: ./vendor
- name: Create patch (restricted paths only)
id: diff
run: |
set -euo pipefail
if [ "${{ steps.ctx.outputs.is_vendor_group }}" != "true" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
allowed_prefix_1="vendor/dist/"
allowed_file_1="vendor/package.json"
allowed_file_2="vendor/yarn.lock"
bad=0
while IFS= read -r file; do
case "$file" in
"$allowed_file_1" | "$allowed_file_2" | "$allowed_prefix_1"*)
;;
*)
echo "Unexpected changed path: $file"
bad=1
;;
esac
done < <(git diff --name-only)
if [ "$bad" -ne 0 ]; then
echo "Refusing to proceed: unexpected paths changed during vendoring."
exit 1
fi
git diff --binary --no-color > "${RUNNER_TEMP}/vendor.patch"
echo "has_changes=true" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
if: steps.diff.outputs.has_changes == 'true'
with:
name: vendor-patch
path: ${{ runner.temp }}/vendor.patch
if-no-files-found: error
vendor-push:
if: github.event.pull_request.user.login == 'dependabot[bot]' && needs.vendor-build.outputs.is_vendor_group == 'true' && needs.vendor-build.outputs.has_changes == 'true'
runs-on: ubuntu-latest
needs: vendor-build
# Security: this job has write permissions but never runs installs/builds.
# It only applies the vetted patch artifact and pushes a single commit.
permissions:
contents: write
id-token: write
steps:
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
id: octo-sts
with:
scope: DataDog/dd-trace-js
policy: dependabot-automation
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ steps.octo-sts.outputs.token }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: vendor-patch
path: ${{ runner.temp }}/vendor-artifact
- name: Apply patch
run: git apply --whitespace=nowarn "${{ runner.temp }}/vendor-artifact/vendor.patch"
- name: Validate changed paths
run: |
set -euo pipefail
allowed_prefix_1="vendor/dist/"
allowed_file_1="vendor/package.json"
allowed_file_2="vendor/yarn.lock"
bad=0
while IFS= read -r file; do
case "$file" in
"$allowed_file_1" | "$allowed_file_2" | "$allowed_prefix_1"*)
;;
*)
echo "Unexpected changed path after applying patch: $file"
bad=1
;;
esac
done < <(git diff --name-only)
if [ "$bad" -ne 0 ]; then
echo "Refusing to proceed: unexpected paths changed."
exit 1
fi
- name: Create commit
id: create-commit
run: |
set -euo pipefail
git config user.name github-actions
git config user.email github-actions@github.com
git add vendor/dist vendor/package.json vendor/yarn.lock
git commit -m "update vendored dependencies with new versions"
echo "commits=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Push commit
uses: DataDog/commit-headless@583489e08d78037e7fa256c14adf998d5463f6a0 # action/v2.0.2
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
with:
branch: ${{ github.event.pull_request.head.ref }}
command: push
commits: "${{ steps.create-commit.outputs.commits }}"
vendor-validate:
# Run validation after the generated vendor patch has been pushed, to ensure the PR contains
# the committed `vendor/dist/*` outputs. This runs inside the same workflow as the push, so it
# doesn't rely on additional workflows being triggered by that push.
if: github.event.pull_request.user.login == 'dependabot[bot]' && needs.vendor-build.outputs.is_vendor_group == 'true' && needs.vendor-build.outputs.has_changes == 'true'
runs-on: ubuntu-latest
needs:
- vendor-build
- vendor-push
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 1
persist-credentials: false
- name: Restore trusted Node setup actions
run: |
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
git checkout "${{ github.event.pull_request.base.sha }}" -- .github/actions/node
- name: Restore trusted vendoring scripts
run: |
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
git checkout "${{ github.event.pull_request.base.sha }}" -- vendor/rspack.js vendor/rspack.config.js
- uses: ./.github/actions/node/active-lts
# Running `yarn` also automatically runs Rspack as a postinstall script.
- run: yarn --frozen-lockfile
working-directory: vendor
- name: Ensure no untracked outputs
run: |
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
echo "Working tree is dirty after vendoring:"
git status --porcelain
exit 1
fi
- name: Diff only expected paths
run: git diff --exit-code -- vendor/dist vendor/package.json vendor/yarn.lock