Skip to content

Commit 475c6d0

Browse files
committed
ci: use registry cache (on ghcr.io) instead of GHA cache
1 parent 778ac6b commit 475c6d0

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ jobs:
6767
needs: build_matrix
6868
runs-on: ${{ matrix.runner }}
6969
permissions:
70-
actions: write # this permission is needed to delete cache
70+
packages: write
71+
contents: read
7172
strategy:
7273
fail-fast: false
7374
matrix:
@@ -90,31 +91,17 @@ jobs:
9091
- name: Set up Docker Buildx
9192
uses: docker/setup-buildx-action@v3
9293

93-
- name: Restore cache
94-
if: github.event_name != 'workflow_dispatch' || fromJSON(github.event.inputs.useCache)
95-
uses: actions/cache/restore@v4
94+
- name: Login to GitHub Container Registry
95+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'pypa/manylinux'
96+
uses: docker/login-action@v3
9697
with:
97-
path: .buildx-cache-${{ matrix.policy }}_${{ matrix.platform }}/*
98-
key: buildx-cache-${{ matrix.policy }}-${{ matrix.platform }}
98+
registry: ghcr.io
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
99101

100102
- name: Build
101103
run: ./build.sh
102104

103-
- name: Delete cache
104-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
105-
run: |
106-
KEY="buildx-cache-${{ matrix.policy }}-${{ matrix.platform }}"
107-
gh cache delete ${KEY} || true
108-
env:
109-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110-
111-
- name: Save cache
112-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
113-
uses: actions/cache/save@v4
114-
with:
115-
path: .buildx-cache-${{ matrix.policy }}_${{ matrix.platform }}/*
116-
key: buildx-cache-${{ matrix.policy }}-${{ matrix.platform }}
117-
118105
- name: Deploy
119106
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'pypa/manylinux'
120107
run: ./deploy.sh

build.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ elif [ "${MANYLINUX_BUILD_FRONTEND}" == "podman" ]; then
9595
TEST_COMMAND="podman"
9696
podman build "${BUILD_ARGS_COMMON[@]}"
9797
elif [ "${MANYLINUX_BUILD_FRONTEND}" == "docker-buildx" ]; then
98-
USE_LOCAL_CACHE=1
98+
if [ "${GITHUB_REPOSITORY:-}_${GITHUB_EVENT_NAME:-}_${GITHUB_REF:-}" == "pypa/manylinux_push_refs/heads/main" ]; then
99+
CACHE_STORE="--cache-to=type=registry,ref=ghcr.io/pypa/manylinux-cache:${POLICY}_${PLATFORM}_main,mode=max,compression=zstd,compression-level=22,force-compression=true"
100+
else
101+
USE_LOCAL_CACHE=1
102+
CACHE_STORE="--cache-to=type=local,dest=$(pwd)/.buildx-cache-staging-${POLICY}_${PLATFORM},mode=max,compression=zstd,compression-level=22,force-compression=true"
103+
fi
99104
docker buildx build \
100105
--load \
106+
"--cache-from=type=registry,ref=ghcr.io/pypa/manylinux-cache:${POLICY}_${PLATFORM}_main" \
101107
"--cache-from=type=local,src=$(pwd)/.buildx-cache-${POLICY}_${PLATFORM}" \
102-
"--cache-to=type=local,dest=$(pwd)/.buildx-cache-staging-${POLICY}_${PLATFORM},mode=max,compression=zstd,compression-level=22,force-compression=true" \
108+
"${CACHE_STORE}" \
103109
"${BUILD_ARGS_COMMON[@]}"
104110
else
105111
echo "Unsupported build frontend: '${MANYLINUX_BUILD_FRONTEND}'"

0 commit comments

Comments
 (0)