ci: speedup docker builds with cache reuse #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: create release assets | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- README.md | |
- doc/** | |
- .github/** | |
- renovate.json5 | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: login to ghcr.io | |
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
fetch-depth: 0 | |
- name: Calculate new version with autotag | |
id: autotag | |
run: | | |
curl -sL https://git.io/autotag-install | sh -s -- -b "${RUNNER_TEMP}/bin" | |
set -x | |
version=$(${RUNNER_TEMP}/bin/autotag -n) | |
echo "version=$version" >> $GITHUB_ENV | |
echo "version=${version}" >> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3 | |
- name: Build and push | |
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ghcr.io/planetscale/k8s-node-tagger:v${{ steps.autotag.outputs.version }} | |
cache-from: | | |
type=gha,scope=go-cache | |
cache-to: | | |
type=gha,mode=max,scope=go-cache | |
- name: Create Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release create "v${version}" \ | |
--target main \ | |
--title "v${version}" \ | |
--generate-notes | |
# - name: Release | |
# run: | | |
# set -eou pipefail | |
# set -x | |
# image="ghcr.io/planetscale/k8s-node-tagger:v${version}" | |
# git reset --hard && git clean -ffdx && git pull | |
# docker buildx build \ | |
# -t "$image" \ | |
# --platform linux/amd64,linux/arm64 \ | |
# --push \ | |
# . | |
# gh release create "v${version}" --target main --title "v${version}" --generate-notes | |
# env: | |
# GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |