GitHub Pages CI #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: GitHub Pages CI | |
| on: | |
| push: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deploy.outputs.page_url }} | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/configure-pages@v5 | |
| - name: Build with Jekyll | |
| uses: actions/jekyll-build-pages@v1 | |
| with: | |
| source: ./ | |
| destination: ./_site | |
| - name: Patch | |
| env: | |
| A8B3C6: ${{ secrets.A8B3C6 }} | |
| BF9A72: ${{ secrets.BF9A72 }} | |
| run: | | |
| sudo chown -R "$(id -u):$(id -g)" _site | |
| python3 -c " | |
| import os, sys, pathlib | |
| a, b = os.environ.get('A8B3C6', ''), os.environ.get('BF9A72', '') | |
| total = 0 | |
| for html in pathlib.Path('_site').rglob('*.html'): | |
| try: | |
| text = html.read_text(encoding='utf-8') | |
| except (OSError, UnicodeDecodeError): | |
| continue | |
| patched = text | |
| if a: | |
| patched = patched.replace('<!-- 21b6a9d477431d939dbb1ab1d1c5e45edf12f958 -->', a) | |
| if b: | |
| patched = patched.replace('<!-- -->', b) | |
| if patched != text: | |
| html.write_text(patched, encoding='utf-8') | |
| total += 1 | |
| if total == 0 and (a or b): | |
| sys.exit(1) | |
| " | |
| - uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: _site | |
| - id: deploy | |
| uses: actions/deploy-pages@v4 |