Skip to content

ci: improve buildx cache #7

ci: improve buildx cache

ci: improve buildx cache #7

Workflow file for this run

name: build
on:
push:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: build & push (main)
if: ${{ github.ref == 'refs/heads/main' }}
env:
USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo ${GHCR_TOKEN} | docker login ghcr.io -u ${USERNAME} --password-stdin
docker buildx build --push \
--cache-from=type=gha --cache-to=type=gha,mode=max \
--cache-from=ghcr.io/${USERNAME}/ghstats:main \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/${USERNAME}/ghstats:main .
- name: build & push (tag)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ref="$(echo ${{ github.ref}} | cut -d'/' -f3)"
echo ${GHCR_TOKEN} | docker login ghcr.io -u ${USERNAME} --password-stdin
docker buildx build --push \
--cache-from=type=gha --cache-to=type=gha,mode=max \
--cache-from=ghcr.io/${USERNAME}/ghstats:main \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/${USERNAME}/ghstats:${ref} -t ghcr.io/${USERNAME}/ghstats:latest .
- name: Create Github Release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}