Skip to content

Merge pull request #995 from codemonkey85/dev #581

Merge pull request #995 from codemonkey85/dev

Merge pull request #995 from codemonkey85/dev #581

Workflow file for this run

name: Deploy to GitHub Pages
on:
workflow_dispatch:
push:
branches: [ main ]
paths-ignore:
- "**.md"
- "**.ps1"
- ".editorconfig"
- "TestFiles/*"
- '**/*.gitignore'
- '**/*.gitattributes'
- '**/*.yml'
jobs:
deploy:
name: Deploy to GitHub Pages
# use ubuntu-latest image to run steps on
runs-on: ubuntu-latest
# Deploy the Azure Function first and gate the front-end on its success. The function is
# backward-compatible with older (cached PWA) front-ends, but an old function is NOT forward-
# compatible with a new front-end — so the new front-end must never go live ahead of the
# function it depends on. If the function deploy fails, the front-end is held back too.
needs: deploy_functions
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
contents: write
pages: write
id-token: write
steps:
# uses GitHub's checkout action to checkout code from the release branch
# RELEASE_PAT is a PAT with `workflow` scope; required so the tag push is
# accepted when main contains commits that modify `.github/workflows/*`
# (the default GITHUB_TOKEN cannot be granted the `workflows` scope).
- name: Checkout code
uses: actions/checkout@v6.0.3
with:
persist-credentials: true
token: ${{ secrets.RELEASE_PAT }}
# sets up .NET SDK
- name: Setup .NET
uses: actions/setup-dotnet@v5.3.0
with:
global-json-file: ./global.json
- name: Install WASM workload
run: dotnet workload install wasm-tools
- name: Restore dependencies
run: dotnet restore Pkmds.Web/Pkmds.Web.csproj
# Compute the version number once to ensure consistency
- name: Compute version number
id: version
run: echo "VERSION=$(date -u '+%Y.%m.%d%H.%M%S')" >> $GITHUB_OUTPUT
# publishes Blazor project to the release-folder with the computed version
- name: Publish .NET Project
run: dotnet publish Pkmds.Web/Pkmds.Web.csproj -c Release -o release --nologo /p:Version=${{ steps.version.outputs.VERSION }}
# Create and push git tag with the version number
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.VERSION }}" -m "Release ${{ steps.version.outputs.VERSION }}"
git push origin "${{ steps.version.outputs.VERSION }}"
# copy index.html to 404.html to serve the same file when a file is not found
- name: copy index.html to 404.html
run: cp release/wwwroot/index.html release/wwwroot/404.html
# add .nojekyll file to tell GitHub pages to not treat this as a Jekyll project. (Allow files and folders starting with an underscore)
- name: Add .nojekyll file
run: touch release/wwwroot/.nojekyll
- name: Update version
uses: datamonsters/replace-action@v2
with:
files: 'release/wwwroot/service-worker.published.js'
replacements: '%%CACHE_VERSION%%=${{ github.run_id }}'
- name: Configure GitHub Pages
uses: actions/configure-pages@v6.0.0
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v5.0.0
with:
path: release/wwwroot
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5.0.0
deploy_functions:
name: Deploy Azure Functions
runs-on: ubuntu-latest
# Least-privilege: deploys via the AZURE_CREDENTIALS secret, not GITHUB_TOKEN.
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6.0.3
- name: Setup .NET
uses: actions/setup-dotnet@v5.3.0
with:
global-json-file: ./global.json
- name: Publish Functions
run: dotnet publish Pkmds.Functions/Pkmds.Functions.csproj -c Release -o functions-publish --nologo
- name: Zip publish output
run: cd functions-publish && zip -r ../functions.zip .
- name: Azure login
uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure Functions
run: |
az functionapp deployment source config-zip \
--name pkmds-functions \
--resource-group pkmds-bug-reports \
--src functions.zip