Skip to content

Commit 0e5b46d

Browse files
committed
Fix CI: release workflow calls build directly via workflow_call
Tags pushed by GITHUB_TOKEN don't trigger other workflows. Instead, release.yml now calls build.yml as a reusable workflow after tagging, passing version and build flags. build.yml also supports workflow_dispatch for manual builds.
1 parent a327f50 commit 0e5b46d

2 files changed

Lines changed: 71 additions & 76 deletions

File tree

.github/workflows/build.yml

Lines changed: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
name: Build and Push Docker Images
22

33
on:
4-
push:
5-
tags: ["v*"]
4+
workflow_call:
5+
inputs:
6+
build_ui:
7+
type: boolean
8+
default: true
9+
build_worker:
10+
type: boolean
11+
default: true
12+
version:
13+
description: 'Version tag (e.g. v0.2.1)'
14+
type: string
15+
required: true
616
workflow_dispatch:
717
inputs:
818
build_ui:
@@ -15,54 +25,49 @@ on:
1525
default: true
1626

1727
concurrency:
18-
group: build-${{ github.ref }}
28+
group: build-${{ inputs.version || github.ref }}
1929
cancel-in-progress: true
2030

2131
jobs:
22-
detect:
32+
resolve-tags:
2333
runs-on: ubuntu-latest
2434
outputs:
25-
build_ui: ${{ steps.check.outputs.ui }}
26-
build_worker: ${{ steps.check.outputs.worker }}
35+
ui_tags: ${{ steps.tags.outputs.ui_tags }}
36+
worker_tags: ${{ steps.tags.outputs.worker_tags }}
2737
steps:
28-
- name: Checkout
29-
uses: actions/checkout@v4
30-
with:
31-
fetch-depth: 2
32-
33-
- name: Detect what to build
34-
id: check
38+
- name: Compute Docker tags
39+
id: tags
3540
run: |
36-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
37-
echo "ui=${{ inputs.build_ui }}" >> "$GITHUB_OUTPUT"
38-
echo "worker=${{ inputs.build_worker }}" >> "$GITHUB_OUTPUT"
41+
VERSION="${{ inputs.version }}"
42+
if [ -z "$VERSION" ]; then
43+
echo "ui_tags=drumsergio/cashpilot:latest" >> "$GITHUB_OUTPUT"
44+
echo "worker_tags=drumsergio/cashpilot-worker:latest" >> "$GITHUB_OUTPUT"
3945
exit 0
4046
fi
41-
42-
CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "all")
43-
BUILD_UI=false
44-
BUILD_WORKER=false
45-
46-
if echo "$CHANGED" | grep -qE '^(Dockerfile|requirements\.txt|app/(main|database|catalog|auth|compose_generator|exchange_rates|collectors|templates|static)|services/)'; then
47-
BUILD_UI=true
48-
fi
49-
if echo "$CHANGED" | grep -qE '^(Dockerfile\.worker|requirements-worker\.txt|app/(worker_api|orchestrator)\.py)'; then
50-
BUILD_WORKER=true
51-
fi
52-
if echo "$CHANGED" | grep -qE '^app/__init__\.py'; then
53-
BUILD_UI=true
54-
BUILD_WORKER=true
55-
fi
56-
57-
# Default: if no specific detection, build both (safety net)
58-
if [ "$BUILD_UI" = "false" ] && [ "$BUILD_WORKER" = "false" ]; then
59-
BUILD_UI=true
60-
BUILD_WORKER=true
61-
fi
62-
63-
echo "ui=$BUILD_UI" >> "$GITHUB_OUTPUT"
64-
echo "worker=$BUILD_WORKER" >> "$GITHUB_OUTPUT"
65-
echo "Build UI: $BUILD_UI, Build Worker: $BUILD_WORKER"
47+
# Strip leading 'v'
48+
VER="${VERSION#v}"
49+
MAJOR_MINOR="$(echo "$VER" | cut -d. -f1).$(echo "$VER" | cut -d. -f2)"
50+
51+
UI="drumsergio/cashpilot:latest"
52+
UI="${UI}
53+
drumsergio/cashpilot:${VER}"
54+
UI="${UI}
55+
drumsergio/cashpilot:${MAJOR_MINOR}"
56+
57+
WORKER="drumsergio/cashpilot-worker:latest"
58+
WORKER="${WORKER}
59+
drumsergio/cashpilot-worker:${VER}"
60+
WORKER="${WORKER}
61+
drumsergio/cashpilot-worker:${MAJOR_MINOR}"
62+
63+
{
64+
echo "ui_tags<<EOF"
65+
echo "$UI"
66+
echo "EOF"
67+
echo "worker_tags<<EOF"
68+
echo "$WORKER"
69+
echo "EOF"
70+
} >> "$GITHUB_OUTPUT"
6671
6772
lint:
6873
runs-on: ubuntu-latest
@@ -82,8 +87,8 @@ jobs:
8287
run: ruff check app/ && ruff format --check app/
8388

8489
build-ui:
85-
needs: [lint, detect]
86-
if: needs.detect.outputs.build_ui == 'true'
90+
needs: [lint, resolve-tags]
91+
if: inputs.build_ui
8792
runs-on: ubuntu-latest
8893
permissions:
8994
contents: read
@@ -104,31 +109,20 @@ jobs:
104109
username: ${{ secrets.DOCKERHUB_USERNAME }}
105110
password: ${{ secrets.DOCKERHUB_TOKEN }}
106111

107-
- name: Extract metadata
108-
id: meta
109-
uses: docker/metadata-action@v5
110-
with:
111-
images: drumsergio/cashpilot
112-
tags: |
113-
type=raw,value=latest
114-
type=semver,pattern={{version}}
115-
type=semver,pattern={{major}}.{{minor}}
116-
117112
- name: Build and push UI image
118113
uses: docker/build-push-action@v6
119114
with:
120115
context: .
121116
file: Dockerfile
122117
platforms: linux/amd64,linux/arm64
123118
push: true
124-
tags: ${{ steps.meta.outputs.tags }}
125-
labels: ${{ steps.meta.outputs.labels }}
119+
tags: ${{ needs.resolve-tags.outputs.ui_tags }}
126120
cache-from: type=gha,scope=cashpilot-ui
127121
cache-to: type=gha,mode=max,scope=cashpilot-ui
128122

129123
build-worker:
130-
needs: [lint, detect]
131-
if: needs.detect.outputs.build_worker == 'true'
124+
needs: [lint, resolve-tags]
125+
if: inputs.build_worker
132126
runs-on: ubuntu-latest
133127
permissions:
134128
contents: read
@@ -149,24 +143,13 @@ jobs:
149143
username: ${{ secrets.DOCKERHUB_USERNAME }}
150144
password: ${{ secrets.DOCKERHUB_TOKEN }}
151145

152-
- name: Extract metadata
153-
id: meta
154-
uses: docker/metadata-action@v5
155-
with:
156-
images: drumsergio/cashpilot-worker
157-
tags: |
158-
type=raw,value=latest
159-
type=semver,pattern={{version}}
160-
type=semver,pattern={{major}}.{{minor}}
161-
162146
- name: Build and push Worker image
163147
uses: docker/build-push-action@v6
164148
with:
165149
context: .
166150
file: Dockerfile.worker
167151
platforms: linux/amd64,linux/arm64
168152
push: true
169-
tags: ${{ steps.meta.outputs.tags }}
170-
labels: ${{ steps.meta.outputs.labels }}
153+
tags: ${{ needs.resolve-tags.outputs.worker_tags }}
171154
cache-from: type=gha,scope=cashpilot-worker
172155
cache-to: type=gha,mode=max,scope=cashpilot-worker

.github/workflows/release.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515

1616
permissions:
1717
contents: write
18+
packages: write
1819

1920
jobs:
2021
release:
@@ -34,33 +35,34 @@ jobs:
3435
- name: Detect what changed
3536
id: changes
3637
run: |
37-
# Compare against the previous commit
3838
CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
3939
echo "Changed files: $CHANGED"
4040
4141
BUILD_UI=false
4242
BUILD_WORKER=false
4343
44-
# UI changes: main.py, templates, static, collectors, Dockerfile, requirements.txt
45-
if echo "$CHANGED" | grep -qE '^(Dockerfile|requirements\.txt|app/(main|database|catalog|auth|compose_generator|exchange_rates|collectors|templates|static))' ; then
44+
if echo "$CHANGED" | grep -qE '^(Dockerfile|requirements\.txt|app/(main|database|catalog|auth|compose_generator|exchange_rates|constants|collectors|templates|static))'; then
4645
BUILD_UI=true
4746
fi
48-
# Also trigger UI on services/ changes (catalog data)
4947
if echo "$CHANGED" | grep -qE '^services/'; then
5048
BUILD_UI=true
5149
fi
5250
53-
# Worker changes: worker_api.py, orchestrator.py, Dockerfile.worker, requirements-worker.txt
54-
if echo "$CHANGED" | grep -qE '^(Dockerfile\.worker|requirements-worker\.txt|app/(worker_api|orchestrator)\.py)'; then
51+
if echo "$CHANGED" | grep -qE '^(Dockerfile\.worker|requirements-worker\.txt|app/(worker_api|orchestrator|constants)\.py)'; then
5552
BUILD_WORKER=true
5653
fi
5754
58-
# If both Dockerfiles or shared files changed, build both
5955
if echo "$CHANGED" | grep -qE '^app/__init__\.py'; then
6056
BUILD_UI=true
6157
BUILD_WORKER=true
6258
fi
6359
60+
# Shared constants affect both
61+
if echo "$CHANGED" | grep -qE '^app/constants\.py'; then
62+
BUILD_UI=true
63+
BUILD_WORKER=true
64+
fi
65+
6466
echo "ui=$BUILD_UI" >> "$GITHUB_OUTPUT"
6567
echo "worker=$BUILD_WORKER" >> "$GITHUB_OUTPUT"
6668
echo "Build UI: $BUILD_UI, Build Worker: $BUILD_WORKER"
@@ -102,3 +104,13 @@ jobs:
102104
prerelease: false
103105
env:
104106
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
108+
build:
109+
needs: release
110+
if: needs.release.outputs.new_tag
111+
uses: ./.github/workflows/build.yml
112+
with:
113+
build_ui: ${{ needs.release.outputs.build_ui == 'true' }}
114+
build_worker: ${{ needs.release.outputs.build_worker == 'true' }}
115+
version: ${{ needs.release.outputs.new_tag }}
116+
secrets: inherit

0 commit comments

Comments
 (0)