Manual Deploy to VPS #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Manual Deploy to VPS | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| source_branch: | |
| description: 'Branch do wypuszczenia (np. develop, fix/typo)' | |
| required: true | |
| default: 'develop' | |
| 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.GITHUB_TOKEN }} | |
| - name: Deploy to VPS | |
| run: | | |
| ssh ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF' | |
| cd /home/deploy/myapp | |
| git pull origin main | |
| docker compose down | |
| docker compose up -d --build | |
| EOF |