diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 59a5e75..3353b7a 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -8,41 +8,46 @@ on: jobs: deploy-frontend: runs-on: ubuntu-latest - steps: - # 1️⃣ Checkout du code - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - # 2️⃣ Setup Node.js (ici Node 22) - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '22' - - # 3️⃣ Installer les dépendances et builder le frontend - - name: Build frontend - run: | - cd chopin-frontend - npm install --omit=dev - npm run build - - # 4️⃣ Setup SSH pour la connexion vers alpha - - name: Setup SSH - env: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Set up SSH run: | mkdir -p ~/.ssh - echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - ssh-keyscan alpha.raphix.fr >> ~/.ssh/known_hosts + ssh-keyscan -H alpha.raphix.fr >> ~/.ssh/known_hosts - # 5️⃣ Copier le build sur alpha - - name: Deploy frontend to Alpha + - name: Deploy frontend run: | - rsync -av --delete chopin-frontend/dist/ raphix@alpha.raphix.fr:/home/gitlab-ci/chopin-frontend/dist/ + ssh raphix@alpha.raphix.fr " + set -e; + APP_DIR=/home/gitlab-ci/chopin-frontend; + REPO_URL=https://git.raphix.fr/subsonics/chopin-frontend; + BRANCH=main; - # 6️⃣ Ajuster permissions sur alpha si nécessaire - - name: Set permissions on Alpha - run: | - ssh raphix@alpha.raphix.fr "sudo chown -R gitlab-ci:gitlab-ci /home/gitlab-ci/chopin-frontend/dist" + echo '[Frontend-Deploy] - START'; + + mkdir -p \$APP_DIR; + + if [ ! -d \$APP_DIR/.git ]; then + echo 'Cloning repository...'; + git clone -b \$BRANCH \$REPO_URL \$APP_DIR; + else + echo 'Updating repository...'; + cd \$APP_DIR; + git fetch origin; + git reset --hard origin/\$BRANCH; + fi; + + cd \$APP_DIR; + + echo 'Installing dependencies...'; + npm ci; + + echo 'Building app...'; + npm run build; + + echo '[Frontend-Deploy] - DONE'; + "