11name : Build and Publish
22
33on :
4- release :
5- types : [published]
6- workflow_dispatch :
7- inputs :
8- version :
9- description : " Optional image version override (e.g. 1.2.3)"
10- required : false
11- type : string
12- repository_dispatch :
13- types : [build-deploy]
4+ push :
5+ branches :
6+ - main
7+ - master
8+ tags :
9+ - ' v*'
1410
1511env :
1612 REGISTRY : ghcr.io
1713
1814jobs :
19- build-app :
15+ # Bump patch version on every push to main/master (skipped on tag pushes and on the
16+ # bot's own follow-up commit). Uses GITHUB_TOKEN; the resulting commit/tag will not
17+ # retrigger this workflow, so build-app/build-addon must `needs:` this job to see
18+ # the new version in ha-addon/config.yaml + server/package.json.
19+ bump-version :
2020 runs-on : ubuntu-latest
21- outputs :
22- version : ${{ steps.ver.outputs.version }}
2321 permissions :
24- contents : read
25- packages : write
26-
22+ contents : write
23+ if : >-
24+ github.event_name == 'push' &&
25+ !startsWith(github.ref, 'refs/tags/') &&
26+ !contains(github.event.head_commit.message, '[skip ci]') &&
27+ !contains(github.event.head_commit.message, 'chore(release):')
28+ outputs :
29+ version : ${{ steps.bump.outputs.version }}
2730 steps :
2831 - name : Checkout repository
2932 uses : actions/checkout@v4
3033 with :
31- ref : ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref }}
32-
33- - name : Set Docker image name (lowercase for GHCR)
34- run : echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
34+ fetch-depth : 0
35+ token : ${{ secrets.GITHUB_TOKEN }}
3536
36- - name : Resolve image version
37- id : ver
38- run : |
39- v=""
40- if [ "${{ github.event_name }}" = "release" ]; then
41- v="${{ github.event.release.tag_name }}"
42- v="${v#v}"
43- elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.version }}" ]; then
44- v="${{ inputs.version }}"
45- elif [ "${{ github.event_name }}" = "repository_dispatch" ] && [ -n "${{ github.event.client_payload.version }}" ]; then
46- v="${{ github.event.client_payload.version }}"
47- fi
48- if [ -z "$v" ]; then
49- v=$(node -e "console.log(require('./server/package.json').version)")
50- fi
51- echo "version=$v" >> "$GITHUB_OUTPUT"
52- echo "Resolved version: $v"
53-
54- - name : Log in to the Container registry
55- uses : docker/login-action@v3
37+ - name : Use Node 20
38+ uses : actions/setup-node@v4
5639 with :
57- registry : ${{ env.REGISTRY }}
58- username : ${{ github.actor }}
59- password : ${{ secrets.GITHUB_TOKEN }}
60-
61- - name : Set up QEMU
62- uses : docker/setup-qemu-action@v3
40+ node-version : ' 20'
6341
64- - name : Set up Docker Buildx
65- uses : docker/setup-buildx-action@v3
42+ - name : Bump patch version
43+ id : bump
44+ run : |
45+ node scripts/bump-version.mjs patch
46+ NEW_VERSION=$(node -e "console.log(require('./server/package.json').version)")
47+ echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
6648
67- - name : Build and push App image
68- uses : docker/build-push-action@v5
69- with :
70- context : .
71- file : ./Dockerfile.app
72- push : true
73- platforms : linux/amd64,linux/arm64,linux/arm/v7
74- tags : |
75- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:${{ steps.ver.outputs.version }}
76- build-args : |
77- VITE_APP_BUILD_VERSION=v${{ steps.ver.outputs.version }}@${{ github.sha }}
78- VITE_INSTALL_KIND=docker
79- cache-from : type=gha
80- cache-to : type=gha,mode=max
49+ - name : Commit and tag
50+ env :
51+ NEW_VERSION : ${{ steps.bump.outputs.version }}
52+ run : |
53+ git config user.name "github-actions[bot]"
54+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
55+ git add server/package.json Dockerfile
56+ if git diff --cached --quiet; then
57+ echo "No version change to commit."
58+ exit 0
59+ fi
60+ git commit -m "chore(release): ${NEW_VERSION} [skip ci]"
61+ git tag "v${NEW_VERSION}"
62+ git push
63+ git push --tags
8164
82- build-addon :
83- needs : [build-app]
65+ build-app :
66+ runs-on : ubuntu-latest
67+ needs : [bump-version]
8468 if : |
8569 always() &&
86- needs.build-app.result == 'success'
87- runs-on : ubuntu-latest
70+ (needs.bump-version.result == 'success' || needs.bump-version.result == 'skipped')
8871 permissions :
8972 contents : read
9073 packages : write
9174
92- strategy :
93- matrix :
94- arch : [amd64, aarch64, armv7]
95- include :
96- - arch : amd64
97- platform : linux/amd64
98- - arch : aarch64
99- platform : linux/arm64
100- - arch : armv7
101- platform : linux/arm/v7
102-
10375 steps :
10476 - name : Checkout repository
10577 uses : actions/checkout@v4
78+ # Pull the freshly-bumped commit (HEAD on the branch already moved by bump-version).
10679 with :
10780 ref : ${{ github.ref }}
10881
@@ -111,9 +84,12 @@ jobs:
11184
11285 - name : Resolve image version
11386 id : ver
87+ # Prefer the bumped version (set on push to main); fall back to ha-addon/config.yaml on tag pushes.
11488 run : |
115- # Reuse the exact app image version so all published images stay in sync.
116- v="${{ needs.build-app.outputs.version }}"
89+ v="${{ needs.bump-version.outputs.version }}"
90+ if [ -z "$v" ]; then
91+ v=$(awk -F'"' '/^version:/ {print $2; exit}' ha-addon/config.yaml)
92+ fi
11793 echo "version=$v" >> "$GITHUB_OUTPUT"
11894 echo "Resolved version: $v"
11995
@@ -130,42 +106,23 @@ jobs:
130106 - name : Set up Docker Buildx
131107 uses : docker/setup-buildx-action@v3
132108
133- - name : Build and push Add-on image
109+ - name : Build and push App image
134110 uses : docker/build-push-action@v5
135111 with :
136112 context : .
137- file : ./Dockerfile
113+ file : ./Dockerfile.app
138114 push : true
139- platforms : ${{ matrix.platform }}
115+ platforms : linux/amd64,linux/arm64,linux/arm/v7
140116 tags : |
141- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-addon-${{ matrix.arch }}:${{ steps.ver.outputs.version }}
117+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:${{ steps.ver.outputs.version }}
118+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:main
142119 build-args : |
143- BUILD_FROM=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:${{ steps.ver.outputs.version }}
144- BUILD_VERSION=${{ steps.ver.outputs.version }}
145120 VITE_APP_BUILD_VERSION=v${{ steps.ver.outputs.version }}@${{ github.sha }}
146121 VITE_INSTALL_KIND=docker
147122 cache-from : type=gha
148123 cache-to : type=gha,mode=max
149124
150- sync-addon-repo :
151- needs : [build-app, build-addon]
152- runs-on : ubuntu-latest
153- permissions :
154- contents : read
155- steps :
156- - name : Checkout repository
157- uses : actions/checkout@v4
158125
159- - name : Resolve image version
160- id : ver
161- run : |
162- v="${{ needs.build-app.outputs.version }}"
163- echo "version=$v" >> "$GITHUB_OUTPUT"
164126
165- - name : Trigger version bump in HA Repository
166- uses : peter-evans/repository-dispatch@v3
167- with :
168- token : ${{ secrets.HA_REPO_SYNC_PAT }}
169- repository : yohaybn/israeli-financial-overview-ha
170- event-type : update-version
171- client-payload : ' {"version": "${{ steps.ver.outputs.version }}"}'
127+
128+
0 commit comments