diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 00e9f54ae..95278bc12 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -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: @@ -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' }}