Repository navigation
refactor: Remove commented-out section for Test & Lint job in backend… #17
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: CI/CD - Backend Deploy to Hostinger | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - '**' | |
| - '.github/workflows/backend-deploy.yml' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Deployment environment' | |
| required: true | |
| default: 'production' | |
| type: choice | |
| options: | |
| - production | |
| env: | |
| GO_VERSION: '1.21' | |
| BINARY_NAME: applens-backend | |
| jobs: | |
| test: | |
| name: Test & Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| cache-dependency-path: go.sum | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Run vet | |
| run: go vet ./... | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.out ./... | |
| - name: Build binary (verify compilation) | |
| run: | | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | |
| -ldflags="-w -s" \ | |
| -o /dev/null ./cmd/main.go | |
| # ========================================================================= | |
| # Job 2: Build Binary & Deploy to Hostinger VPS | |
| # ========================================================================= | |
| deploy: | |
| name: Build & Deploy to Hostinger | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| cache-dependency-path: go.sum | |
| - name: Set build metadata | |
| id: meta | |
| run: | | |
| echo "version=$(git describe --tags --always --dirty 2>/dev/null || echo 'v0.0.0')-$(date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT | |
| echo "git_commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| echo "build_time=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | |
| - name: Build production binary | |
| run: | | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | |
| -a -installsuffix cgo \ | |
| -ldflags="-w -s \ | |
| -X main.Version=${{ steps.meta.outputs.version }} \ | |
| -X main.GitCommit=${{ steps.meta.outputs.git_commit }} \ | |
| -X main.BuildTime=${{ steps.meta.outputs.build_time }}" \ | |
| -o ${{ env.BINARY_NAME }} ./cmd/main.go | |
| chmod +x ${{ env.BINARY_NAME }} | |
| ls -lh ${{ env.BINARY_NAME }} | |
| - name: Upload binary to Hostinger | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USERNAME }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }} | |
| source: "${{ env.BINARY_NAME }}" | |
| target: "/tmp/" | |
| strip_components: 0 | |
| - name: Upload deployment files | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USERNAME }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }} | |
| source: "scripts/deploy.sh,scripts/applens.service,scripts/setup-ssl.sh,nginx/applens-api.conf" | |
| target: "~/applens/" | |
| strip_components: 0 | |
| - name: Deploy on Hostinger | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USERNAME }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }} | |
| script: | | |
| set -e | |
| cd ~/applens | |
| chmod +x scripts/deploy.sh | |
| ./scripts/deploy.sh | |
| - name: Verify deployment | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USERNAME }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }} | |
| script: | | |
| set -e | |
| echo "🔍 Verifying deployment..." | |
| for i in $(seq 1 30); do | |
| if curl -sf http://localhost:8080/health > /dev/null 2>&1; then | |
| echo "✅ Health check passed!" | |
| curl -s http://localhost:8080/health | head -c 200 | |
| echo "" | |
| systemctl is-active applens --quiet && echo "✅ Service: active" || echo "❌ Service: inactive" | |
| exit 0 | |
| fi | |
| echo " Waiting for service... ($i/30)" | |
| sleep 2 | |
| done | |
| echo "❌ Health check failed after 60 seconds" | |
| journalctl -u applens --no-pager --lines=50 | |
| exit 1 | |
| - name: Notify on failure | |
| if: failure() | |
| run: | | |
| echo "::error::Deployment to Hostinger failed! Check the logs above for details." |