-
Notifications
You must be signed in to change notification settings - Fork 513
80 lines (69 loc) · 2.61 KB
/
web.yml
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
name: web
permissions:
contents: write
on:
pull_request:
paths: [web/**]
types: [opened, synchronize, reopened, closed]
push:
paths: [web/**]
branches: [master]
workflow_dispatch:
jobs:
web:
if: github.repository == 'microsoft/windows-rs'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: current
- uses: actions/setup-node@v4
with:
node-version: '23.1' # Temporary: https://github.com/nodejs/node/issues/55826
- name: Build sites
shell: pwsh
run: |
cd current/web
$sites = Get-ChildItem -Directory
foreach ($site in $sites) {
Write-Host "Building $($site.Name)"
./build.ps1 $site.Name
}
- uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
- name: Update gh-pages
shell: pwsh
run: |
cd gh-pages
$sites = Get-ChildItem ../current/web -Directory
foreach ($site in $sites) {
Write-Host "Deploying $($site.Name)"
if ("${{ github.event_name }}" -eq "pull_request") {
if ("${{ github.event.action }}" -eq "closed") {
Remove-Item -Recurse -Force -ErrorAction Ignore "$($site.Name)/preview/pr-${{ github.event.number }}"
} else {
if (Test-Path "$($site.FullName)/build") {
$previewPath = "$($site.Name)/preview/pr-${{ github.event.number }}"
New-Item -ItemType Directory -Force $previewPath | Out-Null
Remove-Item -Recurse -Force -ErrorAction Ignore "$previewPath/*"
Copy-Item "$($site.FullName)/build/*" $previewPath -Recurse -Force
}
}
} elseif ("${{ github.ref }}" -eq "refs/heads/master") {
if (Test-Path "$($site.FullName)/build") {
New-Item -ItemType Directory -Force $site.Name | Out-Null
Get-ChildItem "$($site.Name)/*" -Exclude "preview" | Remove-Item -Recurse -Force -ErrorAction Ignore
Copy-Item "$($site.FullName)/build/*" $site.Name -Recurse -Force
}
}
}
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
$status = git status --porcelain
if ($status) {
git add .
git commit -m "Update from ${{ github.sha }}"
git push
}