forked from homotechsual/NinjaOne
-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (85 loc) · 3.69 KB
/
Copy pathsync-development-docs.yml
File metadata and controls
104 lines (85 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Sync Development Documentation
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
workflow_run:
workflows: ['CI']
types: [completed]
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.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'develop'
steps:
- name: Download development docs artifact
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
gh run download ${{ github.event.workflow_run.id }} --name module-docs --dir docs-artifact --repo homotechsual/NinjaOne
- name: Clone and update homotechsualdocs
shell: pwsh
env:
GH_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$sourceDevelopmentPath = Get-ChildItem -Path 'docs-artifact' -Directory -Recurse |
Where-Object {
$_.Name -eq 'development' -and
$_.Parent -and
$_.Parent.Name -ieq 'ninjaone'
} |
Select-Object -First 1 -ExpandProperty FullName
if (-not (Test-Path -Path $sourceDevelopmentPath -PathType Container)) {
Write-Error 'Documentation artifact does not contain a docs/ninjaone/development directory.'
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/ninjaone/development') {
Remove-Item -Path 'docs/ninjaone/development' -Recurse -Force
}
New-Item -Path 'docs/ninjaone/development' -ItemType Directory -Force | Out-Null
Copy-Item -Path (Join-Path -Path $sourceDevelopmentPath -ChildPath '*') -Destination 'docs/ninjaone/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/ninjaone/development
$commitMsg = 'Sync NinjaOne development docs from develop'
git commit -m $commitMsg
git push origin "HEAD:$targetBranch"
Write-Host '✓ Development documentation published to homotechsualdocs' -ForegroundColor Green
} finally {
Pop-Location
}