-
Notifications
You must be signed in to change notification settings - Fork 15
38 lines (34 loc) · 1.2 KB
/
cache-sync.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# This workflow is necessary in order for the the proper Event to be used
# so we can pull the source and destination branch details
name: PR Cache Sync
on:
pull_request:
branches: [main]
types:
- closed
paths:
- Dockerfile
env:
DOCKER_BUILDKIT: "1"
COSIGN_EXPERIMENTAL: "1"
jobs:
cache-sync:
name: PR cache sync
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Install regctl
uses: iarekylew00t/regctl-installer@c552a6ea85fb38c900cb63feccaa69145ad0883c # v3.1.4
- name: Copy PR build cache to branch
shell: bash
run: |
IMAGE_NAME=$(echo "${GITHUB_REPOSITORY/docker-/}" | tr '[:upper:]' '[:lower:]')
BASE_BRANCH=$(echo "${GITHUB_BASE_REF//[^a-zA-Z0-9]/-}" | tr '[:upper:]' '[:lower:]')
HEAD_BRANCH=$(echo "${GITHUB_HEAD_REF//[^a-zA-Z0-9]/-}" | tr '[:upper:]' '[:lower:]')
echo "ttl.sh/$IMAGE_NAME:$HEAD_BRANCH --> ttl.sh/$IMAGE_NAME:$BASE_BRANCH"
regctl image copy \
--verbosity info \
--digest-tags \
--force-recursive \
"ttl.sh/$IMAGE_NAME:$HEAD_BRANCH" \
"ttl.sh/$IMAGE_NAME:$BASE_BRANCH"