Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust web workflow to use gh-pages branch #3397

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading