-
Notifications
You must be signed in to change notification settings - Fork 2
99 lines (83 loc) · 3.09 KB
/
deploy.yml
File metadata and controls
99 lines (83 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Manual Deploy to VPS
on:
workflow_dispatch:
inputs:
source_branch:
description: 'Branch do wypuszczenia (np. develop, fix/typo)'
required: true
default: 'develop'
permissions:
contents: write
pull-requests: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Setup SSH for GitHub and VPS
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-keyscan ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
- name: Checkout source branch via SSH
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
repository: opendexcom/formul.ai
ref: ${{ github.event.inputs.source_branch }}
fetch-depth: 0 # umożliwia fetch tagów później
- name: Fetch tags
run: git fetch --tags
- name: Determine next version
id: version
run: |
LATEST_TAG=$(git tag --sort=-v:refname | grep '^0\.' | head -n 1)
echo "Latest tag: $LATEST_TAG"
if [ -z "$LATEST_TAG" ]; then
MAJOR=0
MINOR=1
PATCH=0
else
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG"
SOURCE_BRANCH="${{ github.event.inputs.source_branch }}"
if [[ "$SOURCE_BRANCH" == fix/* ]]; then
PATCH=$((PATCH + 1))
else
MINOR=$((MINOR + 1))
PATCH=0
fi
fi
NEXT_VERSION="0.$MINOR.$PATCH"
echo "Calculated next version: $NEXT_VERSION"
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Checkout main branch
run: git checkout main
- name: Merge source branch into main
run: |
git config user.name "github-actions"
git config user.email "github-actions@users.noreply.github.com"
echo "merge origin/${{ github.event.inputs.source_branch }}"
git merge origin/${{ github.event.inputs.source_branch }} --no-ff -m "Merge ${{ github.event.inputs.source_branch }} into main"
- name: Push main with merge
run: git push origin main
- name: Create tag and push
run: |
git tag -a ${{ steps.version.outputs.next_version }} -m "Release ${{ steps.version.outputs.next_version }}"
git push origin ${{ steps.version.outputs.next_version }}
- name: Create GitHub Release with autogenerated notes
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.next_version }}
name: Release ${{ steps.version.outputs.next_version }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
- name: Deploy to VPS
run: |
ssh ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF'
cd /home/deploy/myapp
git pull origin main
docker compose up -d --build
docker image prune -f
EOF