Skip to content

Commit ca7b9d3

Browse files
committed
Add GitHub Actions workflow for publishing to GitHub Pages
1 parent 9f3bb42 commit ca7b9d3

4 files changed

Lines changed: 103 additions & 1 deletion

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and publish to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
ASPNETCORE_ENVIRONMENT: Production
11+
WEBAPP_PATH: ./Spectre.Docs/
12+
WEBAPP_CSPROJ: Spectre.Docs.csproj
13+
14+
permissions:
15+
contents: read
16+
pages: write
17+
id-token: write
18+
19+
# Allow only one concurrent deployment
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Install .NET
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
global-json-file: global.json
35+
36+
37+
- name: Build the Project
38+
run: |
39+
dotnet build
40+
41+
- name: Run webapp and generate static files
42+
run: |
43+
dotnet run --project ${{ env.WEBAPP_PATH }}${{env.WEBAPP_CSPROJ}} --configuration Release -- build "/SpectreDocsPoc/"
44+
45+
- name: Install minify
46+
run: |
47+
curl -sfL https://github.com/tdewolff/minify/releases/latest/download/minify_linux_amd64.tar.gz | tar -xzf - -C /tmp
48+
sudo mv /tmp/minify /usr/local/bin/
49+
50+
- name: Minify CSS and JavaScript files
51+
run: |
52+
# Find and minify all CSS files
53+
find "${{ env.WEBAPP_PATH }}output" -type f -name "*.css" | while read cssfile; do
54+
/usr/local/bin/minify -o "$cssfile" "$cssfile"
55+
echo "Minified $cssfile"
56+
done
57+
58+
# Find and minify all JavaScript files
59+
find "${{ env.WEBAPP_PATH }}output" -type f -name "*.js" | while read jsfile; do
60+
/usr/local/bin/minify -o "$jsfile" "$jsfile"
61+
echo "Minified $jsfile"
62+
done
63+
64+
- name: Setup Pages
65+
uses: actions/configure-pages@v4
66+
67+
- name: Add .nojekyll file
68+
run: touch ${{ env.WEBAPP_PATH }}output/.nojekyll
69+
70+
- name: Upload artifact
71+
uses: actions/upload-pages-artifact@v3
72+
with:
73+
path: ${{ env.WEBAPP_PATH }}output
74+
75+
deploy:
76+
environment:
77+
name: github-pages
78+
url: ${{ steps.deployment.outputs.page_url }}
79+
runs-on: ubuntu-latest
80+
needs: build
81+
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true)
82+
steps:
83+
- name: Deploy to GitHub Pages
84+
id: deployment
85+
uses: actions/deploy-pages@v4

Spectre.Docs.Examples/Spectre.Docs.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net10.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

Spectre.Docs.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Docs", "Spectre.Doc
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Docs.Examples", "Spectre.Docs.Examples\Spectre.Docs.Examples.csproj", "{8BC53462-4821-40F3-BC23-B44A34328C42}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External Solution Items", "External Solution Items", "{572E276C-2B31-4281-A599-C32258327DEB}"
11+
ProjectSection(SolutionItems) = preProject
12+
.editorconfig = .editorconfig
13+
.gitignore = .gitignore
14+
README.md = README.md
15+
Remove-TagsFromMarkdown.ps1 = Remove-TagsFromMarkdown.ps1
16+
.github\workflows\publish-to-gh-pages.yml = .github\workflows\publish-to-gh-pages.yml
17+
EndProjectSection
18+
EndProject
1019
Global
1120
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1221
Debug|Any CPU = Debug|Any CPU

global.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"projects": [ "src", "tests" ],
3+
"sdk": {
4+
"version": "9.0.100",
5+
"allowPrerelease": true,
6+
"rollForward": "latestFeature"
7+
}
8+
}

0 commit comments

Comments
 (0)