ci: speedup docker builds with cache reuse #33
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: Cache | |
uses: actions/cache@v3 | |
id: cache | |
with: | |
path: | | |
go-pkg-mod | |
go-build | |
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}-v2 | |
# - name: inject go-pkg-mod cache into docker | |
# uses: reproducible-containers/[email protected] | |
# with: | |
# cache-source: go-pkg-mod | |
# cache-target: /go/pkg/mod | |
- name: inject go-build cache into docker | |
uses: reproducible-containers/[email protected] | |
with: | |
cache-map: | | |
{ | |
"go-pkg-mod": "/go/pkg/mod", | |
"go-build": "/root/.cache/go-build" | |
} | |
skip-extraction: ${{ steps.cache.outputs.cache-hit }} | |
# cache-source: go-build | |
# cache-target: /root/.cache/go-build | |
- 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 }} | |
# - name: Create Release | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# run: | | |
# gh release create "v${version}" \ | |
# --target main \ | |
# --title "v${version}" \ | |
# --generate-notes |