Skip to content

Commit 72539f4

Browse files
committed
ci: cache to base manifest only on base branch push
1 parent 9869252 commit 72539f4

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

.github/actions/docker/action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ inputs:
3737
aws_secret_access_key:
3838
description: AWS secret access key
3939
required: true
40+
cache_to_name:
41+
description: 'Save cache to name manifest (should be used only on default branch)'
42+
default: 'false'
4043
outputs:
4144
digest:
4245
value: ${{ steps.docker_build.outputs.digest }}
@@ -79,6 +82,7 @@ runs:
7982
name: ${{ inputs.image_name }}
8083
region: ${{ inputs.region }}
8184
bucket: ${{ inputs.bucket }}
85+
cache_to_name: ${{ inputs.cache_to_name }}
8286

8387
- name: Set HOME variable to github context
8488
shell: bash

.github/actions/s3-layer-cache-settings/action.yaml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ inputs:
2525
mode:
2626
description: Cache mode
2727
default: max
28+
cache_to_name:
29+
description: 'Save cache to name manifest (should be used only on default branch)'
30+
default: 'false'
2831

2932
outputs:
3033
cache_to:
@@ -41,14 +44,6 @@ runs:
4144
id: script
4245
with:
4346
script: |
44-
const sanitizedHeadRef = '${{ inputs.head_ref }}'.replace(/[^a-zA-Z0-9]/g, '-');
45-
46-
const manifestNames = [
47-
'${{ inputs.name }}_sha_${{ github.sha }}',
48-
`${{ inputs.name }}_tag_${ sanitizedHeadRef }`,
49-
'${{ inputs.name }}' // TODO: must be only on default branch
50-
];
51-
5247
const settings = {
5348
type: 's3',
5449
region: '${{ inputs.region }}',
@@ -61,9 +56,30 @@ runs:
6156
.map(([key, value]) => `${key}=${value}`)
6257
.join(',');
6358
64-
const cacheFrom = manifestNames
59+
const sanitizedHeadRef = '${{ inputs.head_ref }}'.replace(/[^a-zA-Z0-9]/g, '-');
60+
61+
const shaManifestName = '${{ inputs.name }}_sha_${{ github.sha }}';
62+
const headRefManifestName = '${{ inputs.name }}_tag_${ sanitizedHeadRef }';
63+
64+
const cacheFromManifestNames = [
65+
shaManifestName,
66+
headRefManifestName,
67+
'${{ inputs.name }}',
68+
];
69+
70+
const cacheFrom = cacheFromManifestNames
6571
.map((name) => `${settingsString},name=${name}`)
6672
.join('\n');
6773
6874
core.setOutput('cache_from', cacheFrom);
75+
76+
const cacheToManifestNames = [
77+
shaManifestName,
78+
headRefManifestName,
79+
];
80+
81+
if ('${{ inputs.cache_to_name }}' === 'true') {
82+
cacheToManifestNames.push('${{ inputs.name }}');
83+
}
84+
6985
core.setOutput('cache_to', `${settingsString},mode=${{ inputs.mode }},name=${manifestNames.join(';')}`);

.github/workflows/tests-build-image.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ jobs:
4848
region: ${{ secrets.AWS_REGION }}
4949
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
5050
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
51+
cache_to_name: ${{ github.event_name == 'push' && 'true' || 'false' }}

0 commit comments

Comments
 (0)