Skip to content

Commit 0579aa8

Browse files
authored
Add the workspace hash to ccache key (#811)
Depending on the runner configuration, `github.workspace` might be set up differently, resulting in issues when restoring previous builds from sccache. In order to work around this issue, this adds a hash of `github.workspace` to the sccache key to uniquely identify the build between different runner types.
1 parent 034d28f commit 0579aa8

File tree

1 file changed

+91
-7
lines changed

1 file changed

+91
-7
lines changed

.github/workflows/swift-toolchain.yml

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,23 @@ jobs:
254254
components: 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64;Microsoft.VisualStudio.Component.VC.Tools.ARM64'
255255
arch: ${{ matrix.arch }}
256256

257+
- name: Compute workspace hash
258+
id: workspace_hash
259+
shell: pwsh
260+
run: |
261+
$stringAsStream = [System.IO.MemoryStream]::new()
262+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
263+
$writer.write("${{ github.workspace }}")
264+
$writer.Flush()
265+
$stringAsStream.Position = 0
266+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
267+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
268+
257269
- name: Setup sccache
258270
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
259271
with:
260272
max-size: 100M
261-
key: ${{ matrix.os }}-${{ matrix.arch }}-sqlite
273+
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-sqlite
262274
variant: sccache
263275

264276
- name: Configure SQLite
@@ -311,11 +323,23 @@ jobs:
311323
components: 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64;Microsoft.VisualStudio.Component.VC.Tools.ARM64'
312324
arch: ${{ matrix.arch }}
313325

326+
- name: Compute workspace hash
327+
id: workspace_hash
328+
shell: pwsh
329+
run: |
330+
$stringAsStream = [System.IO.MemoryStream]::new()
331+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
332+
$writer.write("${{ github.workspace }}")
333+
$writer.Flush()
334+
$stringAsStream.Position = 0
335+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
336+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
337+
314338
- name: Setup sccache
315339
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
316340
with:
317341
max-size: 1M
318-
key: windows-${{ matrix.arch }}-cmark-gfm
342+
key: ${{ steps.workspace_hash.outputs.hash }}-windows-${{ matrix.arch }}-cmark-gfm
319343
variant: sccache
320344

321345
- name: Configure cmark-gfm
@@ -371,11 +395,23 @@ jobs:
371395

372396
- uses: compnerd/gha-setup-vsdevenv@main
373397

398+
- name: Compute workspace hash
399+
id: workspace_hash
400+
shell: pwsh
401+
run: |
402+
$stringAsStream = [System.IO.MemoryStream]::new()
403+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
404+
$writer.write("${{ github.workspace }}")
405+
$writer.Flush()
406+
$stringAsStream.Position = 0
407+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
408+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
409+
374410
- name: Setup sccache
375411
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
376412
with:
377413
max-size: 100M
378-
key: windows-amd64-build_tools
414+
key: ${{ steps.workspace_hash.outputs.hash }}-windows-amd64-build_tools
379415
variant: sccache
380416

381417
- name: Configure Tools
@@ -554,11 +590,23 @@ jobs:
554590
with:
555591
ndk-version: r26b
556592

593+
- name: Compute workspace hash
594+
id: workspace_hash
595+
shell: pwsh
596+
run: |
597+
$stringAsStream = [System.IO.MemoryStream]::new()
598+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
599+
$writer.write("${{ github.workspace }}")
600+
$writer.Flush()
601+
$stringAsStream.Position = 0
602+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
603+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
604+
557605
- name: Setup sccache
558606
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
559607
with:
560608
max-size: 500M
561-
key: windows-${{ matrix.arch }}-compilers
609+
key: ${{ steps.workspace_hash.outputs.hash }}-windows-${{ matrix.arch }}-compilers
562610
variant: sccache
563611

564612
- name: Configure Compilers
@@ -786,11 +834,23 @@ jobs:
786834
components: 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64;Microsoft.VisualStudio.Component.VC.Tools.ARM64'
787835
arch: ${{ matrix.arch }}
788836

837+
- name: Compute workspace hash
838+
id: workspace_hash
839+
shell: pwsh
840+
run: |
841+
$stringAsStream = [System.IO.MemoryStream]::new()
842+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
843+
$writer.write("${{ github.workspace }}")
844+
$writer.Flush()
845+
$stringAsStream.Position = 0
846+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
847+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
848+
789849
- name: Setup sccache
790850
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
791851
with:
792852
max-size: 100M
793-
key: ${{ matrix.os }}-${{ matrix.arch }}-zlib
853+
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-zlib
794854
variant: sccache
795855

796856
- uses: nttld/setup-ndk@v1
@@ -914,11 +974,23 @@ jobs:
914974
components: 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64;Microsoft.VisualStudio.Component.VC.Tools.ARM64'
915975
arch: ${{ matrix.arch }}
916976

977+
- name: Compute workspace hash
978+
id: workspace_hash
979+
shell: pwsh
980+
run: |
981+
$stringAsStream = [System.IO.MemoryStream]::new()
982+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
983+
$writer.write("${{ github.workspace }}")
984+
$writer.Flush()
985+
$stringAsStream.Position = 0
986+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
987+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
988+
917989
- name: Setup sccache
918990
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
919991
with:
920992
max-size: 100M
921-
key: ${{ matrix.os }}-${{ matrix.arch }}-curl
993+
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-curl
922994
variant: sccache
923995

924996
- uses: nttld/setup-ndk@v1
@@ -1113,11 +1185,23 @@ jobs:
11131185
components: 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64;Microsoft.VisualStudio.Component.VC.Tools.ARM64'
11141186
arch: ${{ matrix.arch }}
11151187

1188+
- name: Compute workspace hash
1189+
id: workspace_hash
1190+
shell: pwsh
1191+
run: |
1192+
$stringAsStream = [System.IO.MemoryStream]::new()
1193+
$writer = [System.IO.StreamWriter]::new($stringAsStream)
1194+
$writer.write("${{ github.workspace }}")
1195+
$writer.Flush()
1196+
$stringAsStream.Position = 0
1197+
$hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash
1198+
echo "hash=$hash" >> $env:GITHUB_OUTPUT
1199+
11161200
- name: Setup sccache
11171201
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
11181202
with:
11191203
max-size: 100M
1120-
key: ${{ matrix.os }}-${{ matrix.arch }}-libxml2
1204+
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-libxml2
11211205
variant: sccache
11221206

11231207
- uses: nttld/setup-ndk@v1

0 commit comments

Comments
 (0)