Skip to content

Sync Development Documentation #60

Sync Development Documentation

Sync Development Documentation #60

name: Sync Development Documentation
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
workflow_run:
workflows: ['CI']
types:
- completed
workflow_dispatch:
inputs:
dry_run:
description: Skip the git push to homotechsualdocs (test mode)
required: false
default: false
type: boolean
permissions:
actions: read
contents: read
jobs:
publish-development-docs:
name: Publish development docs to homotechsualdocs
runs-on: windows-latest
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
if: >-
github.event_name == 'workflow_dispatch' ||
(
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'develop'
)
steps:
- name: Checkout HaloAPI repository
uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Clone and update homotechsualdocs
shell: pwsh
env:
GH_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$sourceDevelopmentPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Docs\HaloAPI\development'
if (-not (Test-Path -Path $sourceDevelopmentPath -PathType Container)) {
Write-Error "Source development docs path not found: $sourceDevelopmentPath"
exit 1
}
Write-Host "Using development documentation from: $sourceDevelopmentPath" -ForegroundColor Cyan
git -c core.autocrlf=false clone https://x-access-token:$env:GH_TOKEN@github.com/homotechsual/homotechsualdocs.git docs-repo
Push-Location docs-repo
try {
git config core.autocrlf false
git remote set-url origin https://x-access-token:$env:GH_TOKEN@github.com/homotechsual/homotechsualdocs.git
$targetBranch = 'main'
git fetch origin $targetBranch
git checkout -B $targetBranch "origin/$targetBranch"
$pushCheckSucceeded = $true
try {
git push --dry-run origin "HEAD:$targetBranch"
} catch {
$pushCheckSucceeded = $false
}
if (-not $pushCheckSucceeded) {
Write-Error "DOCS_REPO_TOKEN cannot push to homotechsual/homotechsualdocs:$targetBranch. Ensure the token has repository write access (contents:write)."
exit 1
}
if (Test-Path 'docs/haloapi/development') {
Remove-Item -Path 'docs/haloapi/development' -Recurse -Force
}
New-Item -Path 'docs/haloapi/development' -ItemType Directory -Force | Out-Null
Copy-Item -Path (Join-Path -Path $sourceDevelopmentPath -ChildPath '*') -Destination 'docs/haloapi/development' -Recurse -Force
git config user.email 'action@github.com'
git config user.name 'GitHub Action'
$changes = git status --porcelain
if (-not $changes) {
Write-Host 'No development documentation changes to commit.' -ForegroundColor Yellow
exit 0
}
git add docs/haloapi/development
git commit -m 'Sync HaloAPI development docs from develop'
if ('${{ inputs.dry_run }}' -eq 'true') {
Write-Host 'Dry run: skipping git push.' -ForegroundColor Yellow
} else {
git push origin "HEAD:$targetBranch"
}
} finally {
Pop-Location
}