-
Notifications
You must be signed in to change notification settings - Fork 1.2k
ci: better depends caching #7029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5c10d85
36c143b
fd070cc
6f7f799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,80 +14,108 @@ on: | |||||
| outputs: | ||||||
| key: | ||||||
| description: "Key needed for restoring depends cache" | ||||||
| value: ${{ jobs.build-depends.outputs.key }} | ||||||
| value: ${{ jobs.check-cache.outputs.cache-key }} | ||||||
| host: | ||||||
| description: "Host triplet for this build target" | ||||||
| value: ${{ jobs.check-cache.outputs.host }} | ||||||
| dep-opts: | ||||||
| description: "DEP_OPTS used to build depends" | ||||||
| value: ${{ jobs.check-cache.outputs.dep-opts }} | ||||||
|
|
||||||
| jobs: | ||||||
| build-depends: | ||||||
| name: Build depends | ||||||
| runs-on: ubuntu-24.04 | ||||||
| check-cache: | ||||||
| name: Check cache | ||||||
| runs-on: ubuntu-latest | ||||||
| outputs: | ||||||
| key: ${{ steps.restore.outputs.cache-primary-key }} | ||||||
| container: | ||||||
| image: ${{ inputs.container-path }} | ||||||
| options: --user root | ||||||
| cache-hit: ${{ steps.cache-check.outputs.cache-hit }} | ||||||
| cache-key: ${{ steps.setup.outputs.cache-key }} | ||||||
| host: ${{ steps.setup.outputs.HOST }} | ||||||
| dep-opts: ${{ steps.setup.outputs.DEP_OPTS }} | ||||||
| steps: | ||||||
| - name: Checkout code | ||||||
| uses: actions/checkout@v4 | ||||||
| with: | ||||||
| ref: ${{ github.event.pull_request.head.sha }} | ||||||
| sparse-checkout: | | ||||||
| ci/dash | ||||||
| ci/test | ||||||
| depends/Makefile | ||||||
| depends/packages | ||||||
| depends/hosts | ||||||
| contrib/containers/ci/ci.Dockerfile | ||||||
| contrib/containers/ci/ci-slim.Dockerfile | ||||||
|
|
||||||
| - name: Initial setup | ||||||
| - name: Compute cache key | ||||||
| id: setup | ||||||
| run: | | ||||||
| BUILD_TARGET="${{ inputs.build-target }}" | ||||||
| source ./ci/dash/matrix.sh | ||||||
| echo "DEP_OPTS=${DEP_OPTS}" >> "${GITHUB_OUTPUT}" | ||||||
| echo "HOST=${HOST}" >> "${GITHUB_OUTPUT}" | ||||||
| DEP_HASH="$(echo -n "${BUILD_TARGET}" "${DEP_OPTS}" "${HOST}" | sha256sum | head -c 64)" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential hash collision risk from space-separated concatenation. The
To ensure deterministic and collision-free hashing, use explicit separators between variables. Consider using explicit delimiters: - DEP_HASH="$(echo -n "${BUILD_TARGET}" "${DEP_OPTS}" "${HOST}" | sha256sum | head -c 64)"
+ DEP_HASH="$(echo -n "${BUILD_TARGET}:${DEP_OPTS}:${HOST}" | sha256sum | head -c 64)"📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't happen because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: Length of output: 2040 🏁 Script executed: Length of output: 1657 @UdjinM6, you're absolutely right. After examining the actual values from
These three variables have completely distinct formats that don't overlap. A BUILD_TARGET will never contain values that look like DEP_OPTS, and DEP_OPTS won't look like a HOST triplet. Given these domain constraints, the collision scenario I described isn't practically possible here. My concern was theoretically valid for arbitrary strings, but your understanding of the actual values in this codebase is correct—no collision can occur. Thanks for the clarification! 🧠 Learnings used |
||||||
| echo "\"${BUILD_TARGET}\" has HOST=\"${HOST}\" and DEP_OPTS=\"${DEP_OPTS}\" with hash \"${DEP_HASH}\"" | ||||||
| echo "DEP_HASH=${DEP_HASH}" >> "${GITHUB_OUTPUT}" | ||||||
|
|
||||||
| DOCKERFILE_HASH="${{ hashFiles('contrib/containers/ci/ci.Dockerfile', 'contrib/containers/ci/ci-slim.Dockerfile') }}" | ||||||
| PACKAGES_HASH="${{ hashFiles('depends/packages/*', 'depends/Makefile') }}" | ||||||
UdjinM6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| CACHE_KEY="depends-${DOCKERFILE_HASH}-${{ inputs.build-target }}-${DEP_HASH}-${PACKAGES_HASH}" | ||||||
| echo "cache-key=${CACHE_KEY}" >> "${GITHUB_OUTPUT}" | ||||||
| echo "Cache key: ${CACHE_KEY}" | ||||||
| shell: bash | ||||||
|
|
||||||
| - name: Check for cached depends | ||||||
| id: cache-check | ||||||
| uses: actions/cache@v4 | ||||||
| with: | ||||||
| path: depends/built/${{ steps.setup.outputs.HOST }} | ||||||
| key: ${{ steps.setup.outputs.cache-key }} | ||||||
| lookup-only: true | ||||||
|
|
||||||
| build: | ||||||
| name: Build depends | ||||||
| needs: [check-cache] | ||||||
| if: needs.check-cache.outputs.cache-hit != 'true' | ||||||
| runs-on: ubuntu-24.04 | ||||||
| container: | ||||||
| image: ${{ inputs.container-path }} | ||||||
| options: --user root | ||||||
| steps: | ||||||
| - name: Checkout code | ||||||
| uses: actions/checkout@v4 | ||||||
| with: | ||||||
| ref: ${{ github.event.pull_request.head.sha }} | ||||||
|
|
||||||
| - name: Restore depends sources | ||||||
| uses: actions/cache/restore@v4 | ||||||
| with: | ||||||
| path: | | ||||||
| depends/sources | ||||||
| path: depends/sources | ||||||
| key: depends-sources-${{ hashFiles('depends/packages/*') }} | ||||||
| restore-keys: | | ||||||
| depends-sources- | ||||||
| restore-keys: depends-sources- | ||||||
|
|
||||||
| - name: Cache SDKs | ||||||
| uses: actions/cache@v4 | ||||||
| if: inputs.build-target == 'mac' | ||||||
| with: | ||||||
| path: | | ||||||
| depends/SDKs | ||||||
| path: depends/SDKs | ||||||
| key: depends-sdks-${{ hashFiles('depends/hosts/darwin.mk') }} | ||||||
| restore-keys: | | ||||||
| depends-sdks- | ||||||
| restore-keys: depends-sdks- | ||||||
|
|
||||||
| - name: Restore cached depends | ||||||
| uses: actions/cache/restore@v4 | ||||||
| id: restore | ||||||
| with: | ||||||
| path: | | ||||||
| depends/built | ||||||
| depends/${{ steps.setup.outputs.HOST }} | ||||||
| key: depends-${{ hashFiles('contrib/containers/ci/ci.Dockerfile') }}-${{ inputs.build-target }}-${{ steps.setup.outputs.DEP_HASH }}-${{ hashFiles('depends/packages/*') }} | ||||||
| path: depends/built/${{ needs.check-cache.outputs.host }} | ||||||
| key: ${{ needs.check-cache.outputs.cache-key }} | ||||||
| restore-keys: | | ||||||
| depends-${{ hashFiles('contrib/containers/ci/ci.Dockerfile') }}-${{ inputs.build-target }}-${{ steps.setup.outputs.DEP_HASH }}- | ||||||
| depends-${{ hashFiles('contrib/containers/ci/ci.Dockerfile') }}-${{ inputs.build-target }}- | ||||||
| depends-${{ hashFiles('contrib/containers/ci/ci.Dockerfile', 'contrib/containers/ci/ci-slim.Dockerfile') }}-${{ inputs.build-target }}- | ||||||
|
|
||||||
| - name: Build depends | ||||||
| run: | | ||||||
| export HOST="${{ steps.setup.outputs.HOST }}" | ||||||
| export HOST="${{ needs.check-cache.outputs.host }}" | ||||||
| if [ "${HOST}" = "x86_64-apple-darwin" ]; then | ||||||
| ./contrib/containers/guix/scripts/setup-sdk | ||||||
| fi | ||||||
| env ${{ steps.setup.outputs.DEP_OPTS }} make -j$(nproc) -C depends | ||||||
| env ${{ needs.check-cache.outputs.dep-opts }} make -j$(nproc) -C depends | ||||||
|
|
||||||
| - name: Save depends cache | ||||||
| uses: actions/cache/save@v4 | ||||||
| if: steps.restore.outputs.cache-hit != 'true' | ||||||
| with: | ||||||
| path: | | ||||||
| depends/built | ||||||
| depends/${{ steps.setup.outputs.HOST }} | ||||||
| key: ${{ steps.restore.outputs.cache-primary-key }} | ||||||
| path: depends/built/${{ needs.check-cache.outputs.host }} | ||||||
| key: ${{ needs.check-cache.outputs.cache-key }} | ||||||
Uh oh!
There was an error while loading. Please reload this page.