Add auto API deploy

This commit is contained in:
MartinBraquet
2025-12-04 20:45:54 +01:00
parent af334c7142
commit 50d8e6388e
2 changed files with 56 additions and 2 deletions

54
.github/workflows/cd-api.yml vendored Normal file
View File

@@ -0,0 +1,54 @@
name: Deploy API on Version Change
on:
push:
paths:
- "backend/api/package.json"
- ".github/workflows/cd-api.yml"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2 # required so we can compare with previous commit
- name: Install jq
run: sudo apt-get install -y jq
- name: Read current version
id: current
run: |
current=$(jq -r '.version' backend/api/package.json)
echo "version=$current" >> $GITHUB_OUTPUT
- name: Read previous version
id: previous
run: |
# Get previous commits package.json (if it existed)
if git show HEAD^:backend/api/package.json >/dev/null 2>&1; then
previous=$(git show HEAD^:backend/api/package.json | jq -r '.version')
else
previous="none"
fi
echo "version=$previous" >> $GITHUB_OUTPUT
- name: Check version change
id: check
run: |
echo "current=${{ steps.current.outputs.version }}"
echo "previous=${{ steps.previous.outputs.version }}"
if [ "${{ steps.current.outputs.version }}" = "${{ steps.previous.outputs.version }}" ]; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run deploy script
if: steps.check.outputs.changed == 'true'
run: |
chmod +x backend/api/deploy-api.sh
backend/api/deploy-api.sh

View File

@@ -1,7 +1,7 @@
{
"git": {
"revision": "a4a6abe",
"commitDate": "2025-12-04 20:36:32 +0100",
"revision": "af334c7",
"commitDate": "2025-12-04 20:39:20 +0100",
"author": "MartinBraquet"
}
}