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
name: Publish Blazor App to GitHub Pages | ||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: | ||
- 'workshop/MyPortfolio/**' | ||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: write | ||
pages: write | ||
id-token: write | ||
# Allow one concurrent deployment | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: true | ||
jobs: | ||
build_test_artifact: | ||
name: Build App | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup .NET SDK | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: '8.x' | ||
- name: Set basepath on index.html | ||
shell: pwsh | ||
run: | | ||
$filepath = "./src/MyPortfolio/wwwroot/index.html" | ||
$repository = "${{ github.repository }}" -replace "${{ github.repository_owner }}", "" | ||
$html = Get-Content -Path $filepath | ||
$html -replace "<base href=`"/`" />", "<base href=`"$repository/`" />" | Out-File -Path $filepath -Force | ||
- name: Set basepath on JSON objects | ||
shell: pwsh | ||
run: | | ||
$filepath = "./src/MyPortfolio/wwwroot/sample-data" | ||
$repository = "${{ github.repository }}" -replace "${{ github.repository_owner }}", "" | ||
Get-ChildItem -Path $filepath -Filter "*.json" | ForEach-Object { | ||
$json = Get-Content -Path $_.FullName | ||
$json.Replace("../", "$repository/") | Out-File -Path $_.FullName -Force | ||
} | ||
- name: Restore NuGet packages | ||
shell: bash | ||
run: | | ||
dotnet restore ./workshop | ||
- name: Build solution | ||
shell: bash | ||
run: | | ||
dotnet build ./workshop -c Release | ||
- name: Test solution | ||
shell: bash | ||
run: | | ||
dotnet test ./workshop -c Release | ||
- name: Publish artifact | ||
shell: bash | ||
run: | | ||
dotnet publish ./workshop/MyPortfolio -c Release -o published | ||
- name: Upload artifact for web | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: published/wwwroot | ||
deploy: | ||
name: Deploy App to GitHub Pages | ||
needs: | ||
- build_test_artifact | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v1 |