-
Notifications
You must be signed in to change notification settings - Fork 10
107 lines (88 loc) · 3.35 KB
/
deploy-pages.yml
File metadata and controls
107 lines (88 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Deploy Blazor to GitHub Pages
on:
push:
branches: [ main, master ]
paths:
- 'src/BlazorTextDiff.Web/**'
- 'src/BlazorTextDiff/**'
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
env:
DOTNET_VERSION: '9.0.x'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install .NET workloads
run: dotnet workload install wasm-tools-net9
- name: Generate version number
id: version
run: |
UTC_DATE=$(date -u '+%Y.%m.%d')
START_OF_DAY=$(date -u -d "today 00:00:00" '+%s')
CURRENT_TIME=$(date -u '+%s')
SECONDS_SINCE_MIDNIGHT=$(( (CURRENT_TIME - START_OF_DAY) / 2 ))
VERSION="$UTC_DATE.$SECONDS_SINCE_MIDNIGHT"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Generated version: $VERSION"
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Restore dependencies
run: |
dotnet workload restore
dotnet restore
- name: Run tests
run: dotnet test --no-restore --configuration Release --verbosity normal
- name: Build Blazor WebAssembly
run: dotnet publish src/BlazorTextDiff.Web/BlazorTextDiff.Web.csproj -c Release -o dist/ -p:Version=${{ steps.version.outputs.version }} -p:PublishUrl=/BlazorTextDiff/
- name: Add .nojekyll file
run: touch dist/wwwroot/.nojekyll
- name: Add version info to site
working-directory: dist/wwwroot
run: |
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
echo "{\"version\":\"${{ steps.version.outputs.version }}\",\"buildDate\":\"$BUILD_DATE\",\"commit\":\"${{ github.sha }}\",\"run\":\"${{ github.run_id }}\"}" > version.json
sed -i '/<\/head>/i \ \ \ \ <!-- Build: ${{ steps.version.outputs.version }} | Commit: ${{ github.sha }} | Run: ${{ github.run_id }} -->' index.html
- name: Change base-tag in index.html for GitHub Pages
working-directory: dist/wwwroot
run: sed -i 's|<base href="/" />|<base href="/BlazorTextDiff/" />|g' index.html
- name: Fix service-worker-assets.js hashes (if exists)
working-directory: dist/wwwroot
run: |
jsFile=$(find . -name 'service-worker-assets.js' | head -1)
if [ ! -z "$jsFile" ]; then
echo "Updating $jsFile"
sed -i 's|"hash": "[^"]*"|"hash": "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="|g' "$jsFile"
fi
- name: Copy index.html to 404.html for SPA routing
working-directory: dist/wwwroot
run: cp index.html 404.html
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: dist/wwwroot
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4