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

This commit is contained in:
Othmane Ataallah 2026-04-28 11:09:00 +01:00
parent 9664433b5e
commit 2857bddb08

View File

@ -13,8 +13,8 @@ jobs:
GIT_REPO_URL: 145.239.66.197:3000/TrizTech/triz-docs.git
BRANCH: main
# === WORKSPACE ===
# Isolated per-job folder to avoid collisions if runs overlap
WORKSPACE_DIR: C:\CICD\workspace\triz-docs
DEPLOY_DIR: C:\inetpub\wwwroot\docs
steps:
@ -22,96 +22,64 @@ jobs:
# 1. Clean slate — wipe any leftover from a previous run
# --------------------------------------------------
- name: Prepare workspace
shell: pwsh
shell: cmd
run: |
if (Test-Path $env:WORKSPACE_DIR) {
Remove-Item -Recurse -Force $env:WORKSPACE_DIR
}
New-Item -ItemType Directory -Force -Path $env:WORKSPACE_DIR | Out-Null
if exist "%WORKSPACE_DIR%" rmdir /S /Q "%WORKSPACE_DIR%"
mkdir "%WORKSPACE_DIR%"
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
# --------------------------------------------------
# 2. Shallow clone — credentials via env var, not URL,
# to avoid token appearing in git's own error output
# 2. Shallow clone — token scoped to this step only
# to limit its exposure in the environment
# --------------------------------------------------
- name: Clone source code
shell: pwsh
if: success()
shell: cmd
env:
GIT_TOKEN: ${{ secrets.GITEAACTTOKEN }}
run: |
$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" }
git clone --depth 1 --branch %BRANCH% http://ciRunner:%GIT_TOKEN%@%GIT_REPO_URL% "%WORKSPACE_DIR%"
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
# --------------------------------------------------
# 3. Install exact dependency tree from lock file
# --------------------------------------------------
- name: Install dependencies
if: success()
shell: pwsh
shell: cmd
run: |
Set-Location $env:WORKSPACE_DIR
cd /d "%WORKSPACE_DIR%"
npm ci
if ($LASTEXITCODE -ne 0) { throw "npm ci failed" }
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
# --------------------------------------------------
# 4. Build Docusaurus static site
# --------------------------------------------------
- name: Build
if: success()
shell: pwsh
shell: cmd
run: |
Set-Location $env:WORKSPACE_DIR
cd /d "%WORKSPACE_DIR%"
npm run build
if ($LASTEXITCODE -ne 0) { throw "Build failed" }
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
# --------------------------------------------------
# 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.
# 5. Deploy — robocopy exit codes 0-7 are all success
# (bitmask of what changed: copied, skipped, etc.)
# --------------------------------------------------
- name: Deploy (Windows target)
- name: Deploy
if: success()
shell: pwsh
env:
DEPLOY_DIR: C:\inetpub\wwwroot\docs # ← adjust to your web root
shell: cmd
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" }
if not exist "%DEPLOY_DIR%" mkdir "%DEPLOY_DIR%"
robocopy "%WORKSPACE_DIR%\build" "%DEPLOY_DIR%" /E /PURGE /NFL /NDL /NJH /NJS
if %ERRORLEVEL% gtr 7 exit /b %ERRORLEVEL%
# --------------------------------------------------
# 6. Always clean up — no source code left on the runner
# --------------------------------------------------
- name: Cleanup workspace
if: always()
shell: pwsh
shell: cmd
run: |
if (Test-Path $env:WORKSPACE_DIR) {
Remove-Item -Recurse -Force $env:WORKSPACE_DIR
}
if exist "%WORKSPACE_DIR%" rmdir /S /Q "%WORKSPACE_DIR%"