Skip to content

Commit a3e502f

Browse files
authored
GHA: Add custom sccache setup action
Add a custom sccache setup composite action which we subsequently use throughout the entire build process. This allows us to centralise the logic for the configuration of the sccache bucket, enabling authenticated access to S3 if possible.
1 parent 45010bc commit a3e502f

File tree

2 files changed

+118
-28
lines changed

2 files changed

+118
-28
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: "Setup sccache"
2+
description: "Sets up sccache with S3 or local disk configuration"
3+
4+
inputs:
5+
disk-max-size:
6+
description: "The maximum size of the local disk cache in MB if S3 is unavailable."
7+
required: true
8+
disk-cache-key:
9+
description: "The key to use for the local disk cache."
10+
required: true
11+
s3-bucket:
12+
description: "The s3 bucket to use for cache storage."
13+
required: false
14+
s3-bucket-encryption:
15+
description: "Whether to enable server-side encryption for the S3 bucket."
16+
required: false
17+
default: "true"
18+
aws-arn:
19+
description: "The ARN of the AWS role to assume which has read/write access to the S3 bucket."
20+
required: false
21+
aws-region:
22+
description: "The region of the S3 bucket to use for the cache"
23+
required: false
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: Configure caching enviornment
29+
shell: pwsh
30+
run: |
31+
$AWSArn = '${{ inputs.aws-arn }}'
32+
if ($AWSArn) {
33+
$requiredParams = @{
34+
's3-bucket' = '${{ inputs.s3-bucket }}'
35+
's3-bucket-encryption' = '${{ inputs.s3-bucket-encryption }}'
36+
'aws-region' = '${{ inputs.aws-region }}'
37+
}
38+
39+
foreach ($param in $requiredParams.GetEnumerator()) {
40+
if ([string]::IsNullOrEmpty($param.Value)) {
41+
Write-Error -Message "$($param.Key) input cannot be empty when aws-arn is provided" -ErrorAction Stop
42+
}
43+
}
44+
45+
Write-Host "Using S3 bucket ${{ inputs.s3-bucket }} for cache storage."
46+
Write-Host SCCACHE_BUCKET=${{ inputs.s3-bucket }} | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
47+
Write-Host SCCACHE_REGION=${{ inputs.aws-region }} | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
48+
Write-Host SCCACHE_S3_SERVER_SIDE_ENCRYPTION=${{ inputs.s3-bucket-encryption }} | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
49+
} else {
50+
Write-Host "Using local disk cache."
51+
Write-Host SCCACHE_DIRECT='on' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
52+
}
53+
54+
- name: Authenticate to AWS
55+
uses: aws-actions/configure-aws-credentials@v3
56+
if: inputs.aws-arn != ''
57+
with:
58+
role-to-assume: ${{ inputs.aws-arn }}
59+
role-session-name: ToolchainCISccacheAccess
60+
aws-region: ${{ inputs.aws-region }}
61+
62+
- name: Setup sccache
63+
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
64+
with:
65+
max-size: ${{ inputs.disk-max-size }}
66+
key: ${{ inputs.disk-cache-key }}
67+
variant: sccache

.github/workflows/swift-toolchain.yml

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,10 @@ jobs:
343343
echo "hash=$hash" >> $env:GITHUB_OUTPUT
344344
345345
- name: Setup sccache
346-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
346+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
347347
with:
348-
max-size: 100M
349-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-sqlite
350-
variant: sccache
348+
disk-max-size: 100M
349+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-sqlite
351350

352351
- name: Configure SQLite
353352
run: |
@@ -560,6 +559,11 @@ jobs:
560559
name: ${{ matrix.os }} ${{ matrix.arch }} CMark GFM
561560

562561
steps:
562+
- uses: actions/[email protected]
563+
with:
564+
path: ${{ github.workspace }}/SourceCache/swift-build
565+
show-progress: false
566+
563567
- uses: actions/[email protected]
564568
with:
565569
repository: swiftlang/swift-cmark
@@ -589,11 +593,10 @@ jobs:
589593
echo "hash=$hash" >> $env:GITHUB_OUTPUT
590594
591595
- name: Setup sccache
592-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
596+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
593597
with:
594-
max-size: 1M
595-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-cmark-gfm
596-
variant: sccache
598+
disk-max-size: 1M
599+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-cmark-gfm
597600

598601
- name: Configure cmark-gfm
599602
run: >
@@ -633,6 +636,11 @@ jobs:
633636
name: ${{ matrix.os }} ${{ matrix.arch }} Compiler Build Tools
634637

635638
steps:
639+
- uses: actions/[email protected]
640+
with:
641+
path: ${{ github.workspace }}/SourceCache/swift-build
642+
show-progress: false
643+
636644
- uses: thebrowsercompany/gha-download-tar-artifact@59992d91335d4ecba543c8535f7d07238e42125d # main
637645
with:
638646
name: ${{ matrix.os }}-${{ matrix.arch }}-cmark-gfm-${{ inputs.swift_cmark_version }}
@@ -673,11 +681,10 @@ jobs:
673681
echo "hash=$hash" >> $env:GITHUB_OUTPUT
674682
675683
- name: Setup sccache
676-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
684+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
677685
with:
678-
max-size: 100M
679-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-build_tools
680-
variant: sccache
686+
disk-max-size: 100M
687+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-build_tools
681688

682689
- name: Configure Tools
683690
run: |
@@ -915,6 +922,11 @@ jobs:
915922
name: ${{ matrix.os }} ${{ matrix.arch }} ${{ matrix.variant }} Toolchain
916923

917924
steps:
925+
- uses: actions/[email protected]
926+
with:
927+
path: ${{ github.workspace }}/SourceCache/swift-build
928+
show-progress: false
929+
918930
- uses: thebrowsercompany/gha-download-tar-artifact@59992d91335d4ecba543c8535f7d07238e42125d # main
919931
with:
920932
name: ${{ inputs.build_os }}-${{ inputs.build_arch }}-build-tools
@@ -1070,11 +1082,10 @@ jobs:
10701082
echo "hash=$hash" >> $env:GITHUB_OUTPUT
10711083
10721084
- name: Setup sccache
1073-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
1085+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
10741086
with:
1075-
max-size: 500M
1076-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.variant }}-compilers
1077-
variant: sccache
1087+
disk-max-size: 500M
1088+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.variant }}-compilers
10781089

10791090
- name: Setup context
10801091
id: setup-context
@@ -1316,6 +1327,11 @@ jobs:
13161327
name: ${{ matrix.os }} ${{ matrix.arch }} zlib
13171328

13181329
steps:
1330+
- uses: actions/[email protected]
1331+
with:
1332+
path: ${{ github.workspace }}/SourceCache/swift-build
1333+
show-progress: false
1334+
13191335
- uses: actions/[email protected]
13201336
with:
13211337
repository: madler/zlib
@@ -1345,11 +1361,10 @@ jobs:
13451361
echo "hash=$hash" >> $env:GITHUB_OUTPUT
13461362
13471363
- name: Setup sccache
1348-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
1364+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
13491365
with:
1350-
max-size: 100M
1351-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-zlib
1352-
variant: sccache
1366+
disk-max-size: 100M
1367+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-zlib
13531368

13541369
- uses: nttld/setup-ndk@v1
13551370
if: matrix.os == 'Android'
@@ -1406,6 +1421,11 @@ jobs:
14061421
name: ${{ matrix.os }} ${{ matrix.arch }} curl
14071422

14081423
steps:
1424+
- uses: actions/[email protected]
1425+
with:
1426+
path: ${{ github.workspace }}/SourceCache/swift-build
1427+
show-progress: false
1428+
14091429
- uses: actions/[email protected]
14101430
with:
14111431
repository: curl/curl
@@ -1440,11 +1460,10 @@ jobs:
14401460
echo "hash=$hash" >> $env:GITHUB_OUTPUT
14411461
14421462
- name: Setup sccache
1443-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
1463+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
14441464
with:
1445-
max-size: 100M
1446-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-curl
1447-
variant: sccache
1465+
disk-max-size: 100M
1466+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-curl
14481467

14491468
- uses: nttld/setup-ndk@v1
14501469
if: matrix.os == 'Android'
@@ -1577,6 +1596,11 @@ jobs:
15771596
name: ${{ matrix.os }} ${{ matrix.arch }} libxml2
15781597

15791598
steps:
1599+
- uses: actions/[email protected]
1600+
with:
1601+
path: ${{ github.workspace }}/SourceCache/swift-build
1602+
show-progress: false
1603+
15801604
- uses: actions/[email protected]
15811605
with:
15821606
repository: gnome/libxml2
@@ -1607,11 +1631,10 @@ jobs:
16071631
echo "hash=$hash" >> $env:GITHUB_OUTPUT
16081632
16091633
- name: Setup sccache
1610-
uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6
1634+
uses: ./SourceCache/swift-build/.github/actions/setup-sccache
16111635
with:
1612-
max-size: 100M
1613-
key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-libxml2
1614-
variant: sccache
1636+
disk-max-size: 100M
1637+
disk-cache-key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-libxml2
16151638

16161639
- uses: nttld/setup-ndk@v1
16171640
if: matrix.os == 'Android'

0 commit comments

Comments
 (0)