-
Notifications
You must be signed in to change notification settings - Fork 117
ci: share sccache setup across workflows #811
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
Open
abnobdoss
wants to merge
1
commit into
apache:main
Choose a base branch
from
abnobdoss:ci/share-sccache-setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| name: Save sccache | ||
| description: Show sccache stats and save the cache on main branch runs after setup-sccache. | ||
|
|
||
| inputs: | ||
| key-prefix: | ||
| description: Cache key prefix without the run id or Windows compiler suffix. | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Show sccache stats | ||
| if: always() | ||
| shell: bash | ||
| run: sccache --show-stats | ||
|
|
||
| - name: Save sccache cache | ||
| if: ${{ github.ref == 'refs/heads/main' }} | ||
| uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
|
Comment on lines
+34
to
+36
|
||
| with: | ||
| path: ${{ github.workspace }}/.sccache | ||
| key: ${{ inputs.key-prefix }}${{ env.SCCACHE_KEY_SUFFIX }}-${{ github.run_id }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Resolve the MSVC toolset version for use as an sccache cache key suffix. | ||
| # GitHub runner images roll out new cl.exe builds roughly weekly; keying the | ||
| # cache on the toolset version avoids silent misses after each bump. | ||
|
|
||
| $PSNativeCommandUseErrorActionPreference = $false | ||
|
|
||
| function Resolve-Suffix { | ||
| # Locate vswhere, which ships with every VS installation. | ||
| $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' | ||
| if (-not (Test-Path $vswhere)) { return $null } | ||
|
|
||
| # Ask vswhere for the newest installation that includes the C++ toolset. | ||
| $installationPath = (& $vswhere -latest -products * ` | ||
| -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` | ||
| -property installationPath | Select-Object -First 1) | ||
| if (-not $installationPath) { return $null } | ||
|
|
||
| # Read the default toolset version (e.g. "14.44.35217"). | ||
| $versionFile = Join-Path $installationPath.Trim() 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt' | ||
| if (-not (Test-Path $versionFile)) { return $null } | ||
|
|
||
| $version = (Get-Content -Path $versionFile -Raw).Trim() | ||
| if ($version) { return "-$version" } | ||
| return $null | ||
| } | ||
|
|
||
| $suffix = Resolve-Suffix | ||
| if (-not $suffix) { | ||
| # Degrade gracefully: a shared bucket is better than a failed build. | ||
| $suffix = '-unknown' | ||
| Write-Host "::warning::could not resolve MSVC toolset version for sccache key, using '$suffix'" | ||
| } | ||
|
|
||
| # Export to both step outputs (for setup-sccache's restore key) and env (for | ||
| # save-sccache's save key later in the same job). | ||
| Add-Content -Path $env:GITHUB_OUTPUT -Value "suffix=$suffix" | ||
| Add-Content -Path $env:GITHUB_ENV -Value "SCCACHE_KEY_SUFFIX=$suffix" | ||
| Write-Host "Resolved SCCACHE_KEY_SUFFIX=$suffix" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| name: Set up sccache | ||
| description: Configure sccache, restore its cache, and start the sccache action. | ||
|
|
||
| inputs: | ||
| key-prefix: | ||
| description: Cache key prefix without the run id or Windows compiler suffix. | ||
| required: true | ||
| cache-size: | ||
| description: Maximum sccache cache size. | ||
| required: false | ||
| default: 2G | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Configure sccache environment | ||
| shell: bash | ||
| env: | ||
| CACHE_SIZE: ${{ inputs.cache-size }} | ||
| run: | | ||
| echo "SCCACHE_DIR=${{ github.workspace }}/.sccache" >> "$GITHUB_ENV" | ||
| echo "SCCACHE_CACHE_SIZE=${CACHE_SIZE}" >> "$GITHUB_ENV" | ||
| echo "SCCACHE_KEY_SUFFIX=" >> "$GITHUB_ENV" | ||
|
Comment on lines
+38
to
+40
|
||
|
|
||
| # Windows caches include the MSVC toolset version because GitHub runner image | ||
| # rollouts can change the compiler while keeping the same image label. | ||
| - name: Resolve MSVC toolset version for sccache key | ||
| if: ${{ runner.os == 'Windows' }} | ||
| id: msvc-key | ||
| shell: pwsh | ||
| run: '& "${{ github.action_path }}/../sccache/resolve-msvc-key-suffix.ps1"' | ||
|
|
||
| - name: Restore sccache cache | ||
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
| with: | ||
| path: ${{ github.workspace }}/.sccache | ||
| key: ${{ inputs.key-prefix }}${{ steps.msvc-key.outputs.suffix }}-${{ github.run_id }} | ||
| restore-keys: | | ||
| ${{ inputs.key-prefix }}${{ steps.msvc-key.outputs.suffix }}- | ||
|
|
||
| - name: Setup sccache | ||
| uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
always()only applies after the composite action starts. The call sites still default tosuccess(), so this action is skipped after a failed build and stats are not shown. Could we addif: always()to the call sites and keep cache saving success-gated?