99 lines
2.5 KiB
YAML
99 lines
2.5 KiB
YAML
name: Deploy via SSH
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- beta
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Deploy via SSH
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: ${{ secrets.SERVER_USER }}
|
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
|
|
|
script: |
|
|
|
|
set -e
|
|
|
|
echo "===== DEPLOY START ====="
|
|
echo "Branch: ${{ github.ref }}"
|
|
|
|
DEPLOY_PATH="${{ secrets.DEPLOY_PATH }}"
|
|
DEMO_DEPLOY_PATH="${{ secrets.DEMO_DEPLOY_PATH }}"
|
|
BETA_DEPLOY_PATH="${{ secrets.BETA_DEPLOY_PATH }}"
|
|
|
|
# normalisation des chemins (supprime espaces et slash final)
|
|
normalize() {
|
|
p=$(echo "$1" | xargs)
|
|
p=${p%/}
|
|
echo "$p"
|
|
}
|
|
|
|
DEPLOY_PATH=$(normalize "$DEPLOY_PATH")
|
|
DEMO_DEPLOY_PATH=$(normalize "$DEMO_DEPLOY_PATH")
|
|
BETA_DEPLOY_PATH=$(normalize "$BETA_DEPLOY_PATH")
|
|
|
|
SAFE_PATHS=(
|
|
"/var/www/guide.tv.plex.johnnybegood.fr"
|
|
"/var/www/guide.demo.johnnybegood.fr"
|
|
"/var/www/beta.guide.tv.plex.johnnybegood.fr"
|
|
)
|
|
|
|
is_safe() {
|
|
for allowed in "${SAFE_PATHS[@]}"; do
|
|
if [ "$1" = "$allowed" ]; then
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
deploy_repo() {
|
|
|
|
TARGET=$1
|
|
BRANCH=$2
|
|
|
|
echo "Deploying $BRANCH -> $TARGET"
|
|
|
|
if ! is_safe "$TARGET"; then
|
|
echo "ERROR: unauthorized path"
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$TARGET"
|
|
cd "$TARGET"
|
|
|
|
if [ ! -d ".git" ]; then
|
|
echo "Repo absent -> clone"
|
|
git clone --branch "$BRANCH" https://github.com/Johnnybegood90/GridTV.git .
|
|
else
|
|
echo "Repo présent -> reset"
|
|
git fetch origin
|
|
git reset --hard origin/$BRANCH
|
|
fi
|
|
}
|
|
|
|
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
|
|
|
|
echo "=== DEPLOY MAIN ==="
|
|
|
|
deploy_repo "$DEPLOY_PATH" "main"
|
|
deploy_repo "$DEMO_DEPLOY_PATH" "main"
|
|
|
|
elif [ "${{ github.ref }}" = "refs/heads/beta" ]; then
|
|
|
|
echo "=== DEPLOY BETA ==="
|
|
|
|
deploy_repo "$BETA_DEPLOY_PATH" "beta"
|
|
|
|
fi
|
|
|
|
echo "===== DEPLOY DONE ====="
|