Skip to content

Commit

Permalink
check cache
Browse files Browse the repository at this point in the history
  • Loading branch information
machsix committed Apr 23, 2024
1 parent 2d442ed commit 8a7741f
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,54 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
if: ${{ env.DOCKER_USERNAME != '' }}
run: echo "defined=true" >> $GITHUB_OUTPUT

set-cache:
runs-on: ubuntu-latest
outputs:
cache-from: ${{ steps.final.outputs.cache-from }}
cache-to: ${{ steps.final.outputs.cache-to }}
steps:
- name: Initial check
id: check-cache
uses: actions/cache@v4
with:
path: /tmp/check-cache
key: check-cache

- name: Create dummy cache
if: steps.check-cache.outputs.cache-hit != 'true'
run: cat /proc/version > /tmp/check-cache

- name: Save cache if necessary
if: steps.check-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: /tmp/check-cache
key: check-cache

- name: Second check
if: steps.check-cache.outputs.cache-hit != 'true'
id: check-cache-again
uses: actions/cache@v4
with:
path: /tmp/check-cache
key: check-cache

- name: Finalize cache status
id: final
run: |
if [ "${{ steps.check-cache.outputs.cache-hit }}" = "true" ] || [ "${{ steps.check-cache-again.outputs.cache-hit }}" = "true" ]; then
echo "cache-from=type=gha,scope=docker-release" >> $GITHUB_OUTPUT
echo "cache-to=type=gha,mode=max,scope=docker-release" >> $GITHUB_OUTPUT
else
echo "cache-from=" >> $GITHUB_OUTPUT
echo "cache-to=" >> $GITHUB_OUTPUT
fi
rm /tmp/check-cache
release:
runs-on: ubuntu-latest
needs: check-env
needs: [check-env, set-cache]
if: needs.check-env.outputs.check-docker == 'true'
timeout-minutes: 120
permissions:
Expand Down Expand Up @@ -81,8 +126,8 @@ jobs:
tags: ${{ steps.meta-ordinary.outputs.tags }}
labels: ${{ steps.meta-ordinary.outputs.labels }}
platforms: linux/amd64,linux/arm/v7,linux/arm64
cache-from: type=gha,scope=docker-release
cache-to: type=gha,mode=max,scope=docker-release
cache-from: ${{ needs.set-cache.outputs.cache-from }}
cache-to: ${{ needs.set-cache.outputs.cache-to }}

- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
Expand Down

0 comments on commit 8a7741f

Please sign in to comment.