Pass missing branch_name/pm2_id to deploy workflow, add matching deploy inputs, and harden run_* conditions to support both boolean and string true/false values. Made-with: Cursor
191 lines
5.3 KiB
YAML
191 lines
5.3 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
tech_stack:
|
|
required: true
|
|
type: string
|
|
branch_name:
|
|
required: true
|
|
type: string
|
|
|
|
app_path_beta:
|
|
required: false
|
|
type: string
|
|
app_path_testing:
|
|
required: false
|
|
type: string
|
|
app_path_staging:
|
|
required: false
|
|
type: string
|
|
app_path_prod:
|
|
required: false
|
|
type: string
|
|
deploy_command:
|
|
required: false
|
|
type: string
|
|
|
|
pm2_id:
|
|
required: false
|
|
type: string
|
|
|
|
secrets:
|
|
BETA_SERVER_HOST:
|
|
required: false
|
|
BETA_SERVER_PORT:
|
|
required: false
|
|
BETA_SERVER_USERNAME:
|
|
required: false
|
|
BETA_SERVER_PASSWORD:
|
|
required: false
|
|
BETA_SERVER_KEY:
|
|
required: false
|
|
|
|
STAGING_SERVER_HOST:
|
|
required: false
|
|
STAGING_SERVER_PORT:
|
|
required: false
|
|
STAGING_SERVER_USERNAME:
|
|
required: false
|
|
STAGING_SERVER_PASSWORD:
|
|
required: false
|
|
STAGING_SERVER_KEY:
|
|
required: false
|
|
|
|
PROD_SERVER_HOST:
|
|
required: false
|
|
PROD_SERVER_PORT:
|
|
required: false
|
|
PROD_SERVER_USERNAME:
|
|
required: false
|
|
PROD_SERVER_PASSWORD:
|
|
required: false
|
|
PROD_SERVER_KEY:
|
|
required: false
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
# 🔹 BETA / TESTING
|
|
- name: Deploy Beta/Testing
|
|
if: inputs.branch_name == 'beta' || inputs.branch_name == 'testing'
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.BETA_SERVER_HOST }}
|
|
username: ${{ secrets.BETA_SERVER_USERNAME }}
|
|
port: ${{ secrets.BETA_SERVER_PORT }}
|
|
password: ${{ secrets.BETA_SERVER_PASSWORD }}
|
|
key: ${{ secrets.BETA_SERVER_KEY }}
|
|
|
|
script: |
|
|
set -xe
|
|
if [ "${{ inputs.branch_name }}" = "testing" ] && [ -n "${{ inputs.app_path_testing }}" ]; then
|
|
cd ${{ inputs.app_path_testing }}
|
|
else
|
|
cd ${{ inputs.app_path_beta }}
|
|
fi
|
|
|
|
git fetch
|
|
git reset --hard origin/${{ inputs.branch_name }}
|
|
git pull origin ${{ inputs.branch_name }}
|
|
|
|
case "${{ inputs.tech_stack }}" in
|
|
node|react|nestjs)
|
|
if [ -n "${{ inputs.deploy_command }}" ]; then
|
|
echo "Running custom deploy command"
|
|
${{ inputs.deploy_command }}
|
|
else
|
|
npm install
|
|
npm run build || true
|
|
pm2 reload ${{ inputs.pm2_id }} || true
|
|
fi
|
|
;;
|
|
docker)
|
|
docker compose up -d --build
|
|
;;
|
|
*)
|
|
echo "Unknown tech"
|
|
;;
|
|
esac
|
|
|
|
|
|
# 🔹 STAGING
|
|
- name: Deploy Staging
|
|
if: inputs.branch_name == 'staging'
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.STAGING_SERVER_HOST }}
|
|
username: ${{ secrets.STAGING_SERVER_USERNAME }}
|
|
port: ${{ secrets.STAGING_SERVER_PORT }}
|
|
password: ${{ secrets.STAGING_SERVER_PASSWORD }}
|
|
key: ${{ secrets.STAGING_SERVER_KEY }}
|
|
|
|
script: |
|
|
set -xe
|
|
cd ${{ inputs.app_path_staging }}
|
|
|
|
git fetch
|
|
git reset --hard origin/${{ inputs.branch_name }}
|
|
git pull origin ${{ inputs.branch_name }}
|
|
|
|
case "${{ inputs.tech_stack }}" in
|
|
node|react|nestjs)
|
|
if [ -n "${{ inputs.deploy_command }}" ]; then
|
|
echo "Running custom deploy command"
|
|
${{ inputs.deploy_command }}
|
|
else
|
|
npm install
|
|
npm run build || true
|
|
pm2 reload ${{ inputs.pm2_id }} || true
|
|
fi
|
|
;;
|
|
docker)
|
|
docker compose up -d --build
|
|
;;
|
|
*)
|
|
echo "Unknown tech"
|
|
;;
|
|
esac
|
|
|
|
|
|
# 🔹 PRODUCTION
|
|
- name: Deploy Production
|
|
if: inputs.branch_name == 'main' || inputs.branch_name == 'prod'
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.PROD_SERVER_HOST }}
|
|
username: ${{ secrets.PROD_SERVER_USERNAME }}
|
|
port: ${{ secrets.PROD_SERVER_PORT }}
|
|
password: ${{ secrets.PROD_SERVER_PASSWORD }}
|
|
key: ${{ secrets.PROD_SERVER_KEY }}
|
|
|
|
script: |
|
|
set -xe
|
|
cd ${{ inputs.app_path_prod }}
|
|
|
|
git fetch
|
|
git reset --hard origin/${{ inputs.branch_name }}
|
|
git pull origin ${{ inputs.branch_name }}
|
|
|
|
case "${{ inputs.tech_stack }}" in
|
|
node|react|nestjs)
|
|
if [ -n "${{ inputs.deploy_command }}" ]; then
|
|
echo "Running custom deploy command"
|
|
${{ inputs.deploy_command }}
|
|
else
|
|
npm install
|
|
npm run build || true
|
|
pm2 reload ${{ inputs.pm2_id }} || true
|
|
fi
|
|
;;
|
|
docker)
|
|
docker compose up -d --build
|
|
;;
|
|
*)
|
|
echo "Unknown tech"
|
|
;;
|
|
esac |