Skip to content

Commit 50d8e63

Browse files
committed
Add auto API deploy
1 parent af334c7 commit 50d8e63

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

.github/workflows/cd-api.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Deploy API on Version Change
2+
3+
on:
4+
push:
5+
paths:
6+
- "backend/api/package.json"
7+
- ".github/workflows/cd-api.yml"
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 2 # required so we can compare with previous commit
18+
19+
- name: Install jq
20+
run: sudo apt-get install -y jq
21+
22+
- name: Read current version
23+
id: current
24+
run: |
25+
current=$(jq -r '.version' backend/api/package.json)
26+
echo "version=$current" >> $GITHUB_OUTPUT
27+
28+
- name: Read previous version
29+
id: previous
30+
run: |
31+
# Get previous commit’s package.json (if it existed)
32+
if git show HEAD^:backend/api/package.json >/dev/null 2>&1; then
33+
previous=$(git show HEAD^:backend/api/package.json | jq -r '.version')
34+
else
35+
previous="none"
36+
fi
37+
echo "version=$previous" >> $GITHUB_OUTPUT
38+
39+
- name: Check version change
40+
id: check
41+
run: |
42+
echo "current=${{ steps.current.outputs.version }}"
43+
echo "previous=${{ steps.previous.outputs.version }}"
44+
if [ "${{ steps.current.outputs.version }}" = "${{ steps.previous.outputs.version }}" ]; then
45+
echo "changed=false" >> $GITHUB_OUTPUT
46+
else
47+
echo "changed=true" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Run deploy script
51+
if: steps.check.outputs.changed == 'true'
52+
run: |
53+
chmod +x backend/api/deploy-api.sh
54+
backend/api/deploy-api.sh

backend/api/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"git": {
3-
"revision": "a4a6abe",
4-
"commitDate": "2025-12-04 20:36:32 +0100",
3+
"revision": "af334c7",
4+
"commitDate": "2025-12-04 20:39:20 +0100",
55
"author": "MartinBraquet"
66
}
77
}

0 commit comments

Comments
 (0)