Deploy API #46
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: Deploy API | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: ["Check"] | |
| branches: [main] | |
| types: [completed] | |
| concurrency: | |
| group: deploy-production | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| deploy: | |
| name: Deploy | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| environment: production | |
| steps: | |
| - name: Resolve deploy ref | |
| id: ref | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_run" ]]; then | |
| echo "ref=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "ref=${GITHUB_SHA}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ steps.ref.outputs.ref }} | |
| - name: Validate required secrets | |
| shell: bash | |
| env: | |
| PROD_VPS_PASSWORD: ${{ secrets.PROD_VPS_PASSWORD }} | |
| PROD_QWEN_OAUTH_CREDS: ${{ secrets.PROD_QWEN_OAUTH_CREDS }} | |
| PROD_TELEGRAM_BOT_TOKEN: ${{ secrets.PROD_TELEGRAM_BOT_TOKEN }} | |
| run: | | |
| missing=() | |
| for name in \ | |
| PROD_VPS_PASSWORD \ | |
| PROD_QWEN_OAUTH_CREDS \ | |
| PROD_TELEGRAM_BOT_TOKEN | |
| do | |
| if [[ -z "${!name}" ]]; then | |
| missing+=("$name") | |
| fi | |
| done | |
| if [[ ${#missing[@]} -gt 0 ]]; then | |
| printf 'Missing required secrets: %s\n' "${missing[*]}" >&2 | |
| exit 1 | |
| fi | |
| - name: Install sshpass | |
| run: sudo apt-get update && sudo apt-get install -y sshpass | |
| - name: Validate deploy script | |
| run: bash -n scripts/deploy-prod.sh | |
| - name: Deploy production stack | |
| env: | |
| PROD_VPS_PASSWORD: ${{ secrets.PROD_VPS_PASSWORD }} | |
| PROD_QWEN_OAUTH_CREDS: ${{ secrets.PROD_QWEN_OAUTH_CREDS }} | |
| PROD_TELEGRAM_BOT_TOKEN: ${{ secrets.PROD_TELEGRAM_BOT_TOKEN }} | |
| run: | | |
| # deploy-prod.sh: arg1=SSH password, arg2=Telegram bot token only. | |
| # Qwen OAuth is read from env PROD_QWEN_OAUTH_CREDS (not a CLI arg). | |
| bash ./scripts/deploy-prod.sh \ | |
| "$PROD_VPS_PASSWORD" \ | |
| "$PROD_TELEGRAM_BOT_TOKEN" |