Skip to content

feat: enforce trailing slash consistency for content URLs #226

feat: enforce trailing slash consistency for content URLs

feat: enforce trailing slash consistency for content URLs #226

name: Build and publish to GitHub Pages
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
ASPNETCORE_ENVIRONMENT: Production
WEBAPP_PATH: ./docs/MyLittleContentEngine.Docs/
WEBAPP_CSPROJ: MyLittleContentEngine.Docs.csproj
GITHUB_REPOSITORY: "/MyLittleContentEngine/"
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Cache .NET packages and NuGet cache
- name: Cache .NET packages
uses: actions/cache@v4
with:
path: |
~/.nuget/packages
~/.dotnet
key: ${{ runner.os }}-dotnet-${{ hashFiles('**/*.csproj', '**/global.json', '**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-dotnet-
- name: Install .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'
global-json-file: global.json
- name: Run webapp and generate static files
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
run: |
dotnet build
dotnet run --environment ASPNETCORE_ENVIRONMENT=Production --project ${{ env.WEBAPP_PATH }} --configuration Release -- build ${{ env.GITHUB_REPOSITORY }}
- name: Create examples directory
run: mkdir -p ${{ env.WEBAPP_PATH }}output/examples
- name: Build all example projects
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
run: |
# Build each example project
for example_dir in examples/*/; do
if [ -d "$example_dir" ] && [ -f "${example_dir%/}/"*.csproj ]; then
example_name=$(basename "$example_dir")
echo "Building example: $example_name"
# Skip SingleFileApp as it doesn't follow the standard pattern
if [ "$example_name" = "SingleFileApp" ]; then
echo "Skipping SingleFileApp (different build pattern)"
continue
fi
# Skip Spectre.Console.Examples as it isn't a web app
if [ "$example_name" = "Spectre.Console.Examples" ]; then
echo "Skipping Spectre.Console.Examples (example project used elsewhere)"
continue
fi
# Create output directory for this example
mkdir -p "${{ env.WEBAPP_PATH }}output/examples/$example_name"
# Build the example with custom baseUrl and output path
dotnet run --project "$example_dir" --configuration Release -- build "/MyLittleContentEngine/examples/$example_name/" "../../docs/MyLittleContentEngine.Docs/output/examples/$example_name/"
fi
done
- name: Install minify
run: |
curl -sfL https://github.com/tdewolff/minify/releases/latest/download/minify_linux_amd64.tar.gz | tar -xzf - -C /tmp
sudo mv /tmp/minify /usr/local/bin/
- name: Minify CSS and JavaScript files
run: |
# Find and minify all CSS files (including examples)
find "${{ env.WEBAPP_PATH }}output" -type f -name "*.css" | while read cssfile; do
/usr/local/bin/minify -o "$cssfile" "$cssfile"
echo "Minified $cssfile"
done
# Find and minify all JavaScript files (including examples)
find "${{ env.WEBAPP_PATH }}output" -type f -name "*.js" | while read jsfile; do
/usr/local/bin/minify -o "$jsfile" "$jsfile"
echo "Minified $jsfile"
done
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Add .nojekyll file
run: touch ${{ env.WEBAPP_PATH }}output/.nojekyll
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ env.WEBAPP_PATH }}output
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
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)
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4