Skip to content

Commit 4fe0b75

Browse files
committed
ci: allow to ignore cache by workflow dispatch
1 parent c9b74df commit 4fe0b75

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ on:
66
- main
77
pull_request:
88
branches: [main]
9-
9+
workflow_dispatch:
10+
inputs:
11+
no_cache:
12+
description: "Ignore Build cache"
13+
required: false
14+
default: false
1015
permissions:
1116
contents: write
1217
pull-requests: write
@@ -16,6 +21,16 @@ jobs:
1621
ci:
1722
runs-on: ubuntu-latest
1823
steps:
24+
- name: Determine Cache Behavior
25+
id: cache
26+
run: |
27+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
28+
echo "no_cache=${{ inputs.no_cache }}" >> "$GITHUB_OUTPUT"
29+
echo "NO_CACHE=${{ inputs.no_cache }}" >> "$GITHUB_ENV"
30+
else
31+
echo "no_cache=false" >> "$GITHUB_OUTPUT"
32+
echo "NO_CACHE=false" >> "$GITHUB_ENV"
33+
fi
1934
- name: Checkout Repository
2035
uses: actions/checkout@v4
2136

@@ -24,6 +39,7 @@ jobs:
2439
- name: Set up Go
2540
uses: actions/setup-go@v5
2641
with:
42+
cache: ${{ steps.cache.outputs.no_cache }}
2743
go-version: 1.22
2844
- name: Set up release please
2945
id: release

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ GIT_BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
99
BUILD_DATE := $(shell date +%Y-%m-%dT%H:%M:%SZ)
1010
IMAGE_NAME ?= ghcr.io/segator/transcoderd
1111
PROJECT_VERSION ?= $(shell cat version.txt)-dev
12-
12+
export NO_CACHE
1313

1414
.DEFAULT: help
1515
.PHONY: help
@@ -39,12 +39,13 @@ DOCKER_BUILD_ARG := --cache-to type=inline
3939
.PHONY: buildcontainer-%
4040
.PHONY: publishcontainer-%
4141
buildcontainer-% publishcontainer-%:
42-
@export DOCKER_BUILD_ARG="$(DOCKER_BUILD_ARG) $(if $(findstring publishcontainer,$@),--push,--load)"; \
43-
docker buildx build \
42+
@export DOCKER_BUILD_ARG="$(DOCKER_BUILD_ARG) $(if $(findstring publishcontainer,$@),--push,--load) $(if $(NO_CACHE),--no-cache,) "; \
43+
@docker buildx build \
4444
$${DOCKER_BUILD_ARG} \
45-
--cache-from $(IMAGE_NAME):$*-main \
46-
--cache-from $(IMAGE_NAME):$*-$(GIT_BRANCH_NAME) \
47-
-t $(IMAGE_NAME):$*-$(PROJECT_VERSION) \
45+
--cache-from $(IMAGE_NAME):$*-$(GIT_BRANCH_NAME) \ # Generally for non main branches cache
46+
--cache-from $(IMAGE_NAME):$*-main \ # In case no cache for branches use main cache
47+
-t $(IMAGE_NAME):$*-$(PROJECT_VERSION) \ # Publish specific version image
48+
-t $(IMAGE_NAME):$*-$(GIT_BRANCH_NAME) \ # publish specific branch image for cache porpuses
4849
-f Dockerfile \
4950
--target $* \
5051
. ;

0 commit comments

Comments
 (0)