|
| 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 |
0 commit comments