Skip to content

Commit

Permalink
Adjust web workflow to use gh-pages branch (#3397)
Browse files Browse the repository at this point in the history
  • Loading branch information
riverar authored Dec 16, 2024
1 parent c1881bc commit ad8d166
Show file tree
Hide file tree
Showing 3 changed files with 3,451 additions and 5,060 deletions.
95 changes: 56 additions & 39 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,80 @@
name: web

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: 'pages'
cancel-in-progress: false
contents: write

on:
pull_request:
paths:
- 'web/**'
paths: [web/**]
types: [opened, synchronize, reopened, closed]
push:
paths:
- 'web/**'
branches:
- master
paths: [web/**]
branches: [master]
workflow_dispatch:

jobs:
web:
name: web
if: github.repository == 'microsoft/windows-rs'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
path: current

- name: Setup Node
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: '23.1' # Temporary: https://github.com/nodejs/node/issues/55826

- name: Install dependencies
run: npm install
working-directory: web/features
- 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
}
- name: Build project
run: npm run build
working-directory: web/features
- uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages

- name: Stage website (production)
- name: Update gh-pages
shell: pwsh
run: |
mkdir -p web/build/features
cp -r web/features/build/* web/build/features
if: github.event_name != 'pull_request'
cd gh-pages
- name: Stage website (preview)
run: |
mkdir -p web/build/preview/${{ github.event.pull_request.number }}/features
cp -r web/features/build/* web/build/preview/${{ github.event.pull_request.number }}/features
if: github.event_name == 'pull_request'
$sites = Get-ChildItem ../current/web -Directory
foreach ($site in $sites) {
Write-Host "Deploying $($site.Name)"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: web/build
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"
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
$status = git status --porcelain
if ($status) {
git add .
git commit -m "Update from ${{ github.sha }}"
git push
}
19 changes: 19 additions & 0 deletions web/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
param(
[Parameter(Mandatory)]
[string]$Site
)

switch ($Site) {
"features" {
Push-Location features

npm ci
npm run build

Pop-Location
}
default {
Write-Error "Unknown site: $Site"
exit 1
}
}
Loading

0 comments on commit ad8d166

Please sign in to comment.