Skip to content

Test / Magic cache

Test / Magic cache #84

name: Test / Magic cache
on:
push:
branches:
- main
- v*
- feature/*
- fix/*
workflow_dispatch:
jobs:
magic-cache:
strategy:
fail-fast: false
matrix:
image: [ubuntu24-full-x64, ubuntu24-full-arm64, windows22-base-x64]
runs-on: runs-on=${{ github.run_id }}/cpu=2/family=m7/image=${{ matrix.image }}/extras=s3-cache
env:
ARTEFACT_NAME: ${{ github.run_id }}-${{ strategy.job-index }}-my-artifact
FILENAME: random-file
BLOCKS: 128 # 128MB
steps:
- uses: actions/checkout@v4
- uses: ./
- name: Generate file
if: ${{ runner.os == 'Linux' }}
run: |
echo "Generating ${{ env.BLOCKS }}MiB random file..."
dd if=/dev/urandom of=${{ env.FILENAME }} bs=1M count=${{ env.BLOCKS }}
ls -lh ${{ env.FILENAME }}
- name: Generate file
if: ${{ runner.os == 'Windows' }}
run: |
echo "Generating ${{ env.BLOCKS }}MiB random file..."
$random = New-Object byte[] (${{ env.BLOCKS }} * 1MB)
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($random)
[System.IO.File]::WriteAllBytes("${{ env.FILENAME }}", $random)
Get-Item ${{ env.FILENAME }} | Select-Object Length,Name
# ARTEFACT
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTEFACT_NAME }}
path: ${{ env.FILENAME }}
- if: ${{ runner.os == 'Linux' }}
run: rm -f ${{ env.FILENAME }}
- if: ${{ runner.os == 'Windows' }}
run: Remove-Item ${{ env.FILENAME }}
- uses: actions/download-artifact@v4
with:
name: ${{ env.ARTEFACT_NAME }}
path: .
# END ARTEFACT
# DOCKER GHA CACHE
- uses: actions/checkout@v4
with:
repository: dockersamples/example-voting-app
path: apps
- if: ${{ runner.os == 'Linux' }}
run: cp ${{ env.FILENAME }} apps/vote/random.bin
- if: ${{ runner.os == 'Windows' }}
run: Copy-Item ${{ env.FILENAME }} apps/vote/random.bin
- if: ${{ runner.os == 'Linux' }}
run: ls -lh apps/vote/random.bin
- if: ${{ runner.os == 'Windows' }}
run: Get-ChildItem apps/vote/random.bin | Select-Object Length,Name
- name: Set up Docker Buildx
if: ${{ runner.os == 'Linux' }}
uses: docker/setup-buildx-action@v3
- name: "Build and push image (type=gha)"
if: ${{ runner.os == 'Linux' }}
uses: docker/build-push-action@v4
with:
context: "apps/vote"
push: false
tags: test
cache-from: type=gha,scope=${{ github.run_id }}-${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ github.run_id }}-${{ matrix.image }}
# END DOCKER GHA CACHE
- name: Save to cache (actions/cache)
uses: actions/cache/save@v4
with:
path: ${{ env.FILENAME }}
key: github-${{github.run_id}}-actions-cache-${{strategy.job-index}}-${{ env.BLOCKS }}MiB-${{ env.FILENAME }}
- name: Restore from cache (actions/cache)
uses: actions/cache/restore@v4
with:
path: ${{ env.FILENAME }}
fail-on-cache-miss: true
key: github-${{github.run_id}}-actions-cache-${{strategy.job-index}}-${{ env.BLOCKS }}MiB-${{ env.FILENAME }}
- name: Restore from cache (actions/cache, restoreKeys)
uses: actions/cache/restore@v4
with:
path: ${{ env.FILENAME }}
fail-on-cache-miss: true
key: github-${{github.run_id}}-actions-cache-${{strategy.job-index}}-unknown
restore-keys: |
github-${{github.run_id}}-actions-cache-${{strategy.job-index}}-${{ env.BLOCKS }}MiB-
- name: Save to cache (runs-on/cache)
uses: runs-on/cache/save@v4
with:
path: ${{ env.FILENAME }}
key: github-${{github.run_id}}-runs-on-cache-${{strategy.job-index}}-${{ env.BLOCKS }}MiB-${{ env.FILENAME }}
- name: Restore from cache (runs-on/cache)
uses: runs-on/cache/restore@v4
with:
fail-on-cache-miss: true
path: ${{ env.FILENAME }}
key: github-${{github.run_id}}-runs-on-cache-${{strategy.job-index}}-${{ env.BLOCKS }}MiB-${{ env.FILENAME }}
- name: Restore from cache (runs-on/cache, restoreKeys)
uses: runs-on/cache/restore@v4
with:
fail-on-cache-miss: true
path: ${{ env.FILENAME }}
key: github-${{github.run_id}}-runs-on-cache-${{strategy.job-index}}-unknown
restore-keys: |
github-${{github.run_id}}-runs-on-cache-${{strategy.job-index}}-${{ env.BLOCKS }}MiB-
# END RUNS-ON CACHE