-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Protect CI cache save against cancellation #168310
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
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 |
|---|---|---|
|
|
@@ -366,15 +366,16 @@ jobs: | |
| echo "key=uv-${UV_CACHE_VERSION}-${uv_version}-${HA_SHORT_VERSION}-$(date -u '+%Y-%m-%dT%H:%M:%s')" >> $GITHUB_OUTPUT | ||
| - name: Restore base Python virtual environment | ||
| id: cache-venv | ||
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: venv | ||
| key: >- | ||
| ${{ runner.os }}-${{ runner.arch }}-${{ steps.python.outputs.python-version }}-${{ | ||
| needs.info.outputs.python_cache_key }} | ||
| - name: Restore uv wheel cache | ||
| if: steps.cache-venv.outputs.cache-hit != 'true' | ||
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| id: cache-uv | ||
| uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: ${{ env.UV_CACHE_DIR }} | ||
| key: >- | ||
|
|
@@ -398,6 +399,7 @@ jobs: | |
| if: | | ||
| steps.cache-venv.outputs.cache-hit != 'true' | ||
| || steps.cache-apt-check.outputs.cache-hit != 'true' | ||
| id: install-os-deps | ||
| timeout-minutes: 10 | ||
| env: | ||
| APT_CACHE_HIT: ${{ steps.cache-apt-check.outputs.cache-hit }} | ||
|
|
@@ -431,7 +433,10 @@ jobs: | |
| sudo chmod -R 755 ${APT_CACHE_BASE} | ||
| fi | ||
| - name: Save apt cache | ||
| if: steps.cache-apt-check.outputs.cache-hit != 'true' | ||
| if: | | ||
| always() | ||
| && steps.cache-apt-check.outputs.cache-hit != 'true' | ||
| && steps.install-os-deps.outcome == 'success' | ||
| uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: | | ||
|
|
@@ -441,6 +446,7 @@ jobs: | |
| ${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }} | ||
| - name: Create Python virtual environment | ||
| if: steps.cache-venv.outputs.cache-hit != 'true' | ||
| id: create-venv | ||
| run: | | ||
| python -m venv venv | ||
| . venv/bin/activate | ||
|
|
@@ -471,6 +477,26 @@ jobs: | |
| - name: Check dirty | ||
| run: | | ||
| ./script/check_dirty | ||
| - name: Save uv wheel cache | ||
| if: | | ||
| (success() && steps.cache-venv.outputs.cache-hit != 'true') | ||
| || (always() | ||
| && steps.create-venv.outcome == 'success' | ||
| && steps.cache-uv.outputs.cache-matched-key == '') | ||
| uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: ${{ env.UV_CACHE_DIR }} | ||
| key: >- | ||
| ${{ runner.os }}-${{ runner.arch }}-${{ steps.python.outputs.python-version }}-${{ | ||
| steps.generate-uv-key.outputs.key }} | ||
| - name: Save base Python virtual environment | ||
| if: always() && steps.create-venv.outcome == 'success' | ||
|
Member
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. Can we somehow detect if the workflow gets cancelled during the execution of the step?
Member
Author
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. Not sure I fully understand what you actually want to achieve here. Sure we can detect if an earlier step was cancelled. I'm doing that here with |
||
| uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: venv | ||
| key: >- | ||
| ${{ runner.os }}-${{ runner.arch }}-${{ steps.python.outputs.python-version }}-${{ | ||
| needs.info.outputs.python_cache_key }} | ||
|
|
||
| hassfest: | ||
| name: Check hassfest | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm questioning if the described issue will be existing on the uv cache as this one include the current datetime including seconds... I expect that is not possible because is first canceling the current workflow before starting a new one
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly, as you've guessed already.
What I've tried to achieve here is a minor optimization after a HA version bump where no caches will exist. If there are multiple PRs merged in short succession each and every one will again try to rebuild the venv without a cache. That's just unnecessary work. The change here resolves this as only the first "uv cache save" after a HA version bump will always succeed. For all other cases
steps.cache-uv.outputs.cache-matched-keywill be the restored cache key and thus only the default conditionsuccess() && steps.cache-venv.outputs.cache-hit != 'true'will be used, just like it is now.