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