-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust web workflow to use gh-pages branch (#3397)
- Loading branch information
Showing
3 changed files
with
3,451 additions
and
5,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.