2025-08-09 15:24:01 +01:00
|
|
|
name: Deploy eolas-api
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches: [main]
|
|
|
|
|
jobs:
|
|
|
|
|
deploy:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v3
|
2025-10-08 18:53:44 +01:00
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
2025-10-08 19:10:05 +01:00
|
|
|
- name: Determine version bump and update package.json
|
2025-10-08 18:53:44 +01:00
|
|
|
id: version
|
|
|
|
|
run: |
|
|
|
|
|
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
|
|
|
echo "Previous version: $latest_tag"
|
|
|
|
|
|
|
|
|
|
commit_msg=$(git log -1 --pretty=%B)
|
|
|
|
|
|
|
|
|
|
version=${latest_tag#v}
|
|
|
|
|
IFS='.' read -r major minor patch <<< "$version"
|
|
|
|
|
|
2025-10-08 19:10:05 +01:00
|
|
|
if echo "$commit_msg" | grep -qE "^major(\(.*\))?:|BREAKING CHANGE:"; then
|
2025-10-08 18:53:44 +01:00
|
|
|
major=$((major + 1))
|
|
|
|
|
minor=0
|
|
|
|
|
patch=0
|
|
|
|
|
elif echo "$commit_msg" | grep -qE "^feat(\(.*\))?:"; then
|
|
|
|
|
minor=$((minor + 1))
|
|
|
|
|
patch=0
|
|
|
|
|
elif echo "$commit_msg" | grep -qE "^fix(\(.*\))?:"; then
|
|
|
|
|
patch=$((patch + 1))
|
|
|
|
|
else
|
|
|
|
|
echo "No version bump needed"
|
|
|
|
|
echo "new_tag=" >> $GITHUB_OUTPUT
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
new_tag="v${major}.${minor}.${patch}"
|
|
|
|
|
new_version="${major}.${minor}.${patch}"
|
|
|
|
|
echo "New version: $new_tag"
|
|
|
|
|
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
|
|
|
|
|
echo "new_version=$new_version" >> $GITHUB_OUTPUT
|
|
|
|
|
|
2025-10-08 19:15:32 +01:00
|
|
|
echo "$commit_msg" > /tmp/commit_msg.txt
|
|
|
|
|
|
2025-10-08 19:10:05 +01:00
|
|
|
sed -i "s/\"version\": \".*\"/\"version\": \"$new_version\"/" package.json
|
|
|
|
|
|
|
|
|
|
- name: Commit version change
|
2025-10-08 18:53:44 +01:00
|
|
|
if: steps.version.outputs.new_tag != ''
|
|
|
|
|
run: |
|
|
|
|
|
git config user.name "forgejo-actions[bot]"
|
|
|
|
|
git config user.email "forgejo-actions[bot]@noreply"
|
|
|
|
|
git add package.json
|
2025-10-08 19:10:05 +01:00
|
|
|
git commit --amend --no-edit
|
|
|
|
|
git push -f origin main
|
2025-10-08 18:53:44 +01:00
|
|
|
|
|
|
|
|
- name: Create and push tag
|
|
|
|
|
if: steps.version.outputs.new_tag != ''
|
|
|
|
|
run: |
|
|
|
|
|
git tag ${{ steps.version.outputs.new_tag }}
|
|
|
|
|
git push origin ${{ steps.version.outputs.new_tag }}
|
|
|
|
|
|
2025-10-08 19:15:32 +01:00
|
|
|
- name: Deploy to VPS
|
2025-10-08 19:17:13 +01:00
|
|
|
run: |
|
2025-10-15 17:00:07 +01:00
|
|
|
echo "⚡ INFO Installing rsync"
|
2025-10-10 15:24:16 +01:00
|
|
|
apt-get update && apt-get install -y rsync
|
2025-10-15 17:00:07 +01:00
|
|
|
echo "⚡ INFO Retrieving SSH key for deploy user"
|
2025-10-05 19:55:07 +01:00
|
|
|
echo "${{ secrets.VPS_DEPLOY_USER_SSH_KEY }}" > /tmp/ssh_key
|
2025-08-09 15:24:01 +01:00
|
|
|
chmod 600 /tmp/ssh_key
|
2025-10-15 17:00:07 +01:00
|
|
|
echo "⚡ INFO Copy files (rsync)"
|
2025-10-15 15:21:05 +01:00
|
|
|
rsync -avz --delete --inplace --exclude='.env' -e "ssh -i /tmp/ssh_key -o StrictHostKeyChecking=no" ./ ${{ vars.VPS_DEPLOY_USER }}:/var/www/eolas-api/
|
2025-10-15 17:00:07 +01:00
|
|
|
echo "⚡ INFO Run npm install on VPS"
|
|
|
|
|
# npm install --omit=dev
|
|
|
|
|
echo "⚡ INFO Restarting systemd service"
|
|
|
|
|
# sudo systemctl daemon-reload
|
|
|
|
|
# sudo systemctl restart eolas-api
|
2025-08-09 15:24:01 +01:00
|
|
|
rm /tmp/ssh_key
|