fix ci-cd
Some checks failed
Deploy triz-docs to civital server test / build-and-deploy (push) Failing after 1h8m6s
Deploy triz-docs to civital server / build-and-deploy (push) Failing after 1h8m4s

This commit is contained in:
Othmane Ataallah 2026-04-28 11:05:11 +01:00
parent 50cb4157fe
commit 9664433b5e

View File

@ -1,5 +1,4 @@
name: Deploy triz-docs to civital server test
name: Deploy triz-docs to civital server
on:
push:
@ -13,52 +12,106 @@ jobs:
# === PROJECT ===
GIT_REPO_URL: 145.239.66.197:3000/TrizTech/triz-docs.git
BRANCH: main
GIT_TOKEN: ${{ secrets.GITEAACTTOKEN }}
# === WORKSPACE ===
WORKSPACE_DIR: C:\CICD\workspace
# Isolated per-job folder to avoid collisions if runs overlap
WORKSPACE_DIR: C:\CICD\workspace\triz-docs
steps:
# --------------------------------------------------
# 1. Prepare clean workspace (no source kept)
# 1. Clean slate — wipe any leftover from a previous run
# --------------------------------------------------
- name: Prepare workspace
shell: cmd
shell: pwsh
run: |
if exist %WORKSPACE_DIR% rmdir /S /Q %WORKSPACE_DIR%
mkdir %WORKSPACE_DIR%
if (Test-Path $env:WORKSPACE_DIR) {
Remove-Item -Recurse -Force $env:WORKSPACE_DIR
}
New-Item -ItemType Directory -Force -Path $env:WORKSPACE_DIR | Out-Null
# --------------------------------------------------
# 2. Clone source (shallow, fast) --depth 1 -b %BRANCH%
# 2. Shallow clone — credentials via env var, not URL,
# to avoid token appearing in git's own error output
# --------------------------------------------------
- name: Clone source code
shell: cmd
shell: pwsh
env:
GIT_TOKEN: ${{ secrets.GITEAACTTOKEN }}
run: |
cd %WORKSPACE_DIR%
git clone --depth 1 --branch %BRANCH% http://ciRunner:%GIT_TOKEN%@%GIT_REPO_URL% .
- name: Install deps
run: |
cd %WORKSPACE_DIR%
npm ci
- name: Build
run: |
cd %WORKSPACE_DIR%
npm run build
- name: Deploy
run: |
cd %WORKSPACE_DIR%
rm -rf /var/www/docs/*
cp -r build/* /var/www/docs/
$repoUrl = "http://ciRunner:$env:GIT_TOKEN@$env:GIT_REPO_URL"
git clone --depth 1 --branch $env:BRANCH $repoUrl $env:WORKSPACE_DIR
if ($LASTEXITCODE -ne 0) { throw "git clone failed" }
# --------------------------------------------------
# 10. Cleanup source code (no trace left)
# 3. Install exact dependency tree from lock file
# --------------------------------------------------
- name: Install dependencies
if: success()
shell: pwsh
run: |
Set-Location $env:WORKSPACE_DIR
npm ci
if ($LASTEXITCODE -ne 0) { throw "npm ci failed" }
# --------------------------------------------------
# 4. Build Docusaurus static site
# --------------------------------------------------
- name: Build
if: success()
shell: pwsh
run: |
Set-Location $env:WORKSPACE_DIR
npm run build
if ($LASTEXITCODE -ne 0) { throw "Build failed" }
# --------------------------------------------------
# 5a. Deploy — OPTION A: Windows web root (IIS / local folder)
# Use this if your web server root is a Windows path.
# Replace DEPLOY_DIR with your actual IIS / web root path.
# --------------------------------------------------
- name: Deploy (Windows target)
if: success()
shell: pwsh
env:
DEPLOY_DIR: C:\inetpub\wwwroot\docs # ← adjust to your web root
run: |
if (-not (Test-Path $env:DEPLOY_DIR)) {
New-Item -ItemType Directory -Force -Path $env:DEPLOY_DIR | Out-Null
}
# Clear old build, then copy new one atomically-ish with robocopy
Remove-Item -Recurse -Force "$env:DEPLOY_DIR\*" -ErrorAction SilentlyContinue
robocopy "$env:WORKSPACE_DIR\build" $env:DEPLOY_DIR /E /NFL /NDL /NJH /NJS
# robocopy exit codes 0-7 are success (bitmask of what changed)
if ($LASTEXITCODE -gt 7) { throw "robocopy deploy failed with code $LASTEXITCODE" }
# --------------------------------------------------
# 5b. Deploy — OPTION B: Remote Linux server over SSH
# Use this if your web server is a separate Linux machine.
# Add SSH_KEY, SSH_USER, SSH_HOST as Gitea secrets.
# --------------------------------------------------
# - name: Deploy (remote Linux target via SSH)
# if: success()
# shell: pwsh
# env:
# SSH_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
# SSH_USER: ${{ secrets.SSH_USER }}
# SSH_HOST: ${{ secrets.SSH_HOST }}
# run: |
# $keyFile = "$env:WORKSPACE_DIR\deploy_key"
# Set-Content -Path $keyFile -Value $env:SSH_KEY -NoNewline
# icacls $keyFile /inheritance:r /grant:r "$env:USERNAME:R"
# scp -i $keyFile -o StrictHostKeyChecking=no -r `
# "$env:WORKSPACE_DIR\build\*" `
# "$env:SSH_USER@${env:SSH_HOST}:/var/www/docs/"
# if ($LASTEXITCODE -ne 0) { throw "scp deploy failed" }
# --------------------------------------------------
# 6. Always clean up — no source code left on the runner
# --------------------------------------------------
- name: Cleanup workspace
if: always()
shell: cmd
shell: pwsh
run: |
rmdir /S /Q %WORKSPACE_DIR%
if (Test-Path $env:WORKSPACE_DIR) {
Remove-Item -Recurse -Force $env:WORKSPACE_DIR
}