name: staging-deployment
# Trigger deployment only on push to develop branch
on:
  push:
    branches:
      - develop
jobs:
  deploy:
    name: Deploy latest develop branch to staging
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - name: Executing remote ssh commands using ssh key
        uses: appleboy/ssh-action@v1.0.3
        env:
          GITHUB_BRANCH: develop
          GITHUB_SHA: ${{ github.sha }}
        with:
          host: ${{ secrets.HOST_DNS }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          envs: GITHUB_BRANCH,GITHUB_SHA
          command_timeout: 60m
          script: |
            echo "GITHUB_BRANCH: ${GITHUB_BRANCH}"
            echo "GITHUB_SHA: ${GITHUB_SHA}"
            export DOCKER_TAG="${GITHUB_SHA:0:7}" # needed for child process to access it
            export OTELCOL_TAG="main"
            export PATH="/usr/local/go/bin/:$PATH" # needed for Golang to work
            docker system prune --force
            docker pull signoz/signoz-otel-collector:main
            docker pull signoz/signoz-schema-migrator:main
            cd ~/signoz
            git status
            git add .
            git stash push -m "stashed on $(date --iso-8601=seconds)"
            git fetch origin
            git checkout ${GITHUB_BRANCH}
            git pull
            make build-ee-query-service-amd64
            make build-frontend-amd64
            make run-signoz