117 lines
4.6 KiB
YAML
117 lines
4.6 KiB
YAML
name: Deploy triz-docs to civital server
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: serveurtest150
|
|
|
|
env:
|
|
# === PROJECT ===
|
|
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
|
|
|
|
steps:
|
|
|
|
# --------------------------------------------------
|
|
# 1. Clean slate — wipe any leftover from a previous run
|
|
# --------------------------------------------------
|
|
- name: Prepare workspace
|
|
shell: pwsh
|
|
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
|
|
|
|
# --------------------------------------------------
|
|
# 2. Shallow clone — credentials via env var, not URL,
|
|
# to avoid token appearing in git's own error output
|
|
# --------------------------------------------------
|
|
- name: Clone source code
|
|
shell: pwsh
|
|
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" }
|
|
|
|
# --------------------------------------------------
|
|
# 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: pwsh
|
|
run: |
|
|
if (Test-Path $env:WORKSPACE_DIR) {
|
|
Remove-Item -Recurse -Force $env:WORKSPACE_DIR
|
|
} |