58 lines
1.9 KiB
YAML
58 lines
1.9 KiB
YAML
name: promote-prod
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
sha:
|
|
description: "Commit SHA à promouvoir (vide = SHA du push)"
|
|
required: false
|
|
|
|
jobs:
|
|
promote:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with: { fetch-depth: 1 }
|
|
|
|
- name: Promote sur PROD (checkout + restart systemd)
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
env:
|
|
DEPLOY_PULL_TOKEN: ${{ secrets.DEPLOY_PULL_TOKEN }}
|
|
PROMOTE_SHA: ${{ inputs.sha != '' && inputs.sha || github.sha }}
|
|
SYSTEMD_SERVICE: ${{ vars.SYSTEMD_SERVICE }} # ihm-ephapoc
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
port: ${{ secrets.SSH_PORT }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
envs: DEPLOY_PULL_TOKEN,PROMOTE_SHA,SYSTEMD_SERVICE
|
|
script: |
|
|
set -euo pipefail
|
|
repo=/srv/ihm/app/IHMKOS
|
|
svc="${SYSTEMD_SERVICE:-ihm-ephapoc}"
|
|
|
|
git config --global --add safe.directory "${repo}" || true
|
|
|
|
# Auth non interactive vers Gitea (HTTPS)
|
|
umask 077
|
|
cat > ~/.netrc <<EOF
|
|
machine ephagit.ephaitek.com
|
|
login moham
|
|
password ${DEPLOY_PULL_TOKEN}
|
|
EOF
|
|
|
|
cd "${repo}"
|
|
# enregistrer le commit courant pour rollback (dans le dépôt)
|
|
git rev-parse HEAD > .rollback_commit
|
|
|
|
# se positionner exactement sur le commit demandé
|
|
git fetch origin main --depth=50
|
|
git checkout -f "${PROMOTE_SHA}"
|
|
git submodule update --init --recursive || true
|
|
|
|
rm -f ~/.netrc
|
|
|
|
# restart du service systemd (appelle ton docker-run.sh)
|
|
sudo -n systemctl daemon-reload || true
|
|
sudo -n systemctl restart "${svc}.service"
|
|
sudo -n systemctl --no-pager --full status "${svc}.service" -l || true |