11name : Resolve Dependencies and Build Wheels
22
33on :
4+ workflow_dispatch :
45 pull_request :
56 branches :
67 - master
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
0 commit comments