Skip to content

Commit 15351d3

Browse files
authored
Fix build wheels workflow to allow triggering it on workflow dispatch (DataDog#21985)
* Fix build wheels workflow to allow running on dispatch * Ensure image digest is persisted if we are going to build and lock files * Unindent EOF * Pin krb5 to avoid the failed build * Revert "Pin krb5 to avoid the failed build" This reverts commit 71154ef. * Try new krb5 pin * wip: Work in Progress * Add back dependency on dcb alongside requests-kerberos * Remove pin and opened a separate PR for that * Remove redundant if condition and chomping pipes * Extract complex logic to separate bash scripts * Ensure we checkout the repo to get the scritps
1 parent 0882132 commit 15351d3

3 files changed

Lines changed: 89 additions & 73 deletions

File tree

.github/workflows/resolve-build-deps.yaml

Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Resolve Dependencies and Build Wheels
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
branches:
67
- master
@@ -26,39 +27,36 @@ env:
2627
# https://reproducible-builds.org/specs/source-date-epoch/
2728
SOURCE_DATE_EPOCH: "1580601600"
2829

29-
jobs:
30+
jobs:
3031
# measure-disk-usage.yml depends on this workflow being triggered and completed,
3132
# so it can wait for the build to calculate dependency sizes.
3233
# The 'on' setting ensures it runs, but this job cancels it if no dependency changes are detected.
3334

34-
check-dependency-changes:
35-
name: Check dependency changes
35+
check-should-run:
36+
name: Check if build should run
3637
runs-on: ubuntu-22.04
3738
permissions:
3839
actions: write
40+
contents: read
3941
outputs:
40-
dependency_changed: ${{ steps.dependency-check.outputs.dependency_changed }}
4142
builder_changed: ${{ steps.dependency-check.outputs.builder_changed }}
43+
should_run_build: ${{ steps.dependency-check.outputs.should_run_build }}
4244
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
4348
- name: Define diff commits
4449
id: set_sha
45-
run: |
46-
if [ "${{ github.event_name }}" == "pull_request" ]; then
47-
PREV_SHA=${{ github.event.pull_request.base.sha }}
48-
CURR_SHA=${{ github.event.pull_request.head.sha }}
49-
else
50-
PREV_SHA=${{ github.event.before }}
51-
CURR_SHA=${{ github.sha }}
52-
fi
53-
54-
echo "prev_sha=$PREV_SHA" >> $GITHUB_OUTPUT
55-
echo "curr_sha=$CURR_SHA" >> $GITHUB_OUTPUT
56-
57-
echo "Current SHA: $CURR_SHA"
58-
echo "Previous SHA: $PREV_SHA"
50+
if: github.event_name != 'workflow_dispatch'
51+
run: .github/workflows/scripts/resolve_deps_define_diff_commits.sh
52+
env:
53+
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
54+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
55+
EVENT_BEFORE: ${{ github.event.before }}
5956

6057
- name: Get changed files
6158
id: changed-files
59+
if: github.event_name != 'workflow_dispatch'
6260
run: |
6361
REPO="${{ github.repository }}"
6462
@@ -70,50 +68,24 @@ jobs:
7068
env:
7169
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7270

73-
- name: Check for dependency changes
71+
- name: Check if build should run
7472
id: dependency-check
75-
run: |
76-
FILES_CHANGED="${{ steps.changed-files.outputs.files_changed }}"
77-
78-
cat << EOF > dependency_files.txt
79-
agent_requirements\.in
80-
\.github/workflows/resolve-build-deps\.yaml
81-
\.builders/
82-
EOF
83-
84-
cat <<EOF > builder_files.txt
85-
\.builders/
86-
EOF
87-
88-
DEPENDENCY_CHANGED=$(
89-
echo "$FILES_CHANGED" | \
90-
grep -qf dependency_files.txt \
91-
&& echo "true" || echo "false"
92-
)
93-
94-
BUILDER_CHANGED=$(
95-
echo "$FILES_CHANGED" | \
96-
grep -qf builder_files.txt \
97-
&& echo "true" || echo "false"
98-
)
99-
100-
101-
echo "dependency_changed=$DEPENDENCY_CHANGED" | tee -a $GITHUB_OUTPUT
102-
echo "builder_changed=$BUILDER_CHANGED" | tee -a $GITHUB_OUTPUT
103-
73+
run: .github/workflows/scripts/resolve_deps_check_should_run.sh
10474
env:
10575
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
FILES_CHANGED: ${{ steps.changed-files.outputs.files_changed }}
10677

10778
test:
10879
name: Run tests
10980
needs:
110-
- check-dependency-changes
111-
if: needs.check-dependency-changes.outputs.dependency_changed == 'true'
81+
- check-should-run
82+
if: needs.check-should-run.outputs.should_run_build == 'true'
11283
runs-on: ubuntu-22.04
11384
steps:
11485
- name: Checkout code
11586
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
116-
- name: Set up Python ${{ env.PYTHON_VERSION }}
87+
88+
- name: Set up Python ${{ env.PYTHON_VERSION }}
11789
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
11890
with:
11991
python-version: ${{ env.PYTHON_VERSION }}
@@ -129,8 +101,8 @@ jobs:
129101
build:
130102
name: Target ${{ matrix.job.image }} on ${{ matrix.job.os }}
131103
needs:
132-
- check-dependency-changes
133-
if: needs.check-dependency-changes.outputs.dependency_changed == 'true'
104+
- check-should-run
105+
if: needs.check-should-run.outputs.should_run_build == 'true'
134106
runs-on: ${{ matrix.job.os }}
135107
strategy:
136108
fail-fast: false
@@ -161,8 +133,7 @@ jobs:
161133
python-version: ${{ env.PYTHON_VERSION }}
162134

163135
- name: Install management dependencies
164-
run: |
165-
pip install -r .builders/deps/host_dependencies.txt
136+
run: pip install -r .builders/deps/host_dependencies.txt
166137

167138
- name: Log in to GitHub Packages
168139
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
@@ -172,29 +143,28 @@ jobs:
172143
password: ${{ secrets.GITHUB_TOKEN }}
173144

174145
- name: Build image and wheels
175-
if: needs.check-dependency-changes.outputs.builder_changed == 'true'
176-
run: |-
177-
python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3
146+
if: needs.check-should-run.outputs.builder_changed == 'true'
147+
run: python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3
178148

179149
- name: Pull image and build wheels
180-
if: needs.check-dependency-changes.outputs.builder_changed == 'false'
181-
run: |-
150+
if: needs.check-should-run.outputs.builder_changed == 'false'
151+
run: |
182152
digest=$(jq -r '.["${{ matrix.job.image }}"]' .deps/image_digests.json)
183153
python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3 --digest $digest
184154
185155
- name: Publish image
186-
if: github.event_name == 'push' && needs.check-dependency-changes.outputs.builder_changed == 'true'
156+
if: github.event_name == 'push' && needs.check-should-run.outputs.builder_changed == 'true'
187157
run: ${DOCKER} push ${{ env.BUILDER_IMAGE }}
188158

189159
- name: Save new image digest
190-
if: github.event_name == 'push' && needs.check-dependency-changes.outputs.builder_changed == 'true'
160+
if: github.event_name == 'push' && needs.check-should-run.outputs.builder_changed == 'true'
191161
run: >-
192162
${DOCKER} inspect --format "{{index .RepoDigests 0}}" ${{ env.BUILDER_IMAGE }}
193163
| cut -d '@' -f 2
194164
> ${{ env.OUT_DIR }}/image_digest
195165
196166
- name: Persist current image digest
197-
if: github.event_name == 'push' && needs.check-dependency-changes.outputs.builder_changed == 'false'
167+
if: needs.check-should-run.outputs.builder_changed == 'false'
198168
run: >-
199169
jq -r '.["${{ matrix.job.image }}"]' .deps/image_digests.json
200170
> ${{ env.OUT_DIR }}/image_digest
@@ -208,8 +178,8 @@ jobs:
208178
build-macos:
209179
name: Target macOS/${{ matrix.job.arch }} on ${{ matrix.job.os }}
210180
needs:
211-
- check-dependency-changes
212-
if: needs.check-dependency-changes.outputs.dependency_changed == 'true'
181+
- check-should-run
182+
if: needs.check-should-run.outputs.should_run_build == 'true'
213183
runs-on: ${{ matrix.job.os }}
214184
strategy:
215185
fail-fast: false
@@ -229,7 +199,7 @@ jobs:
229199

230200
steps:
231201
- name: Set up environment
232-
run: |-
202+
run: |
233203
# We remove everything that comes pre-installed via Homebrew to avoid depending on or shipping stuff that
234204
# comes in the runner through Homebrew to better control what might get shipped in the wheels via `delocate`
235205
brew remove --force --ignore-dependencies $(brew list --formula)
@@ -239,7 +209,7 @@ jobs:
239209
env:
240210
# Despite the name, this is built for the macOS 11 SDK on arm64 and 10.9+ on intel
241211
PYTHON3_DOWNLOAD_URL: "https://www.python.org/ftp/python/3.13.9/python-3.13.9-macos11.pkg"
242-
run: |-
212+
run: |
243213
curl "$PYTHON3_DOWNLOAD_URL" -o python3.pkg
244214
sudo installer -pkg python3.pkg -target /
245215
@@ -255,16 +225,15 @@ jobs:
255225
id: cache-builder-root
256226
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
257227
with:
258-
path: |
259-
~/builder_root
228+
path: ~/builder_root
260229
key: macos-${{ matrix.job.arch }}-deps-builder-root-cache-${{ hashFiles('./.builders/images/macos/*', './.builders/images/*', './.builders/deps/*', './.builders/build.py', './.github/workflows/resolve-build-deps.yml') }}
261230

262231
- name: Run the build
263232
env:
264233
# This sets the minimum macOS version compatible for all built artifacts
265234
MACOSX_DEPLOYMENT_TARGET: "11.0" # https://docs.datadoghq.com/agent/supported_platforms/?tab=macos
266235
CACHE_HIT: ${{ steps.cache-builder-root.outputs.cache-hit }}
267-
run: |-
236+
run: |
268237
# If we hit the cache, we can skip the builder setup
269238
if [[ ${CACHE_HIT} == "true" ]]; then
270239
${DD_PYTHON3} .builders/build.py ${{ env.TARGET_NAME }} --builder-root ~/builder_root --python 3 ${{ env.OUT_DIR }}/py3 --skip-setup
@@ -282,11 +251,11 @@ jobs:
282251

283252
publish:
284253
name: Publish artifacts and update lockfiles via PR
285-
if: needs.check-dependency-changes.outputs.dependency_changed == 'true' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && (github.ref_name == github.event.repository.default_branch || startsWith(github.ref_name, '7.'))))
254+
if: needs.check-should-run.outputs.should_run_build == 'true' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && (github.ref_name == github.event.repository.default_branch || startsWith(github.ref_name, '7.'))))
286255
needs:
287256
- build
288257
- build-macos
289-
- check-dependency-changes
258+
- check-should-run
290259
runs-on: ubuntu-latest
291260

292261
permissions:
@@ -328,7 +297,7 @@ jobs:
328297
run: python .builders/lock.py targets
329298

330299
- name: Clean up repository
331-
run: |-
300+
run: |
332301
rm ${{ steps.auth.outputs.credentials_file_path }}
333302
rm -rf targets
334303
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
if [ "$GITHUB_EVENT_NAME" == 'workflow_dispatch' ]; then
4+
builder_changed="false"
5+
should_run_build="true"
6+
else
7+
8+
cat << EOF > dependency_files.txt
9+
agent_requirements\.in
10+
\.github/workflows/resolve-build-deps\.yaml
11+
\.builders/
12+
EOF
13+
14+
cat <<EOF > builder_files.txt
15+
\.builders/
16+
EOF
17+
18+
should_run_build=$(
19+
echo "$FILES_CHANGED" | \
20+
grep -qf dependency_files.txt \
21+
&& echo "true" || echo "false"
22+
)
23+
24+
builder_changed=$(
25+
echo "$FILES_CHANGED" | \
26+
grep -qf builder_files.txt \
27+
&& echo "true" || echo "false"
28+
)
29+
fi
30+
31+
echo "should_run_build=$should_run_build" | tee -a $GITHUB_OUTPUT
32+
echo "builder_changed=$builder_changed" | tee -a $GITHUB_OUTPUT
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
4+
prev_sha=$PR_BASE_SHA
5+
curr_sha=$PR_HEAD_SHA
6+
else
7+
prev_sha=$EVENT_BEFORE
8+
curr_sha=$GITHUB_SHA
9+
fi
10+
11+
echo "prev_sha=$prev_sha" >> $GITHUB_OUTPUT
12+
echo "curr_sha=$curr_sha" >> $GITHUB_OUTPUT
13+
14+
echo "Current SHA: $curr_sha"
15+
echo "Previous SHA: $prev_sha"

0 commit comments

Comments
 (0)