|
| 1 | +name: Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "docs/**" |
| 8 | + - ".github/workflows/docs.yml" |
| 9 | + - "scripts/ensure_cloudflare_pages.py" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + pages: write |
| 15 | + id-token: write |
| 16 | + deployments: write |
| 17 | + |
| 18 | +env: |
| 19 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: docs-${{ github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v6.0.2 |
| 30 | + with: |
| 31 | + submodules: true |
| 32 | + # Sitemap lastmod comes from the latest content commit. |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Checkout tago |
| 36 | + uses: actions/checkout@v6.0.2 |
| 37 | + with: |
| 38 | + repository: tamnd/tago |
| 39 | + path: .tago-src |
| 40 | + fetch-depth: 1 |
| 41 | + |
| 42 | + - name: Setup Go |
| 43 | + uses: actions/setup-go@v6.4.0 |
| 44 | + with: |
| 45 | + go-version-file: .tago-src/go.mod |
| 46 | + cache: false |
| 47 | + |
| 48 | + - name: Cache tago binary |
| 49 | + id: tago-bin-cache |
| 50 | + uses: actions/cache@v5.0.5 |
| 51 | + with: |
| 52 | + path: /usr/local/bin/tago |
| 53 | + key: tago-bin-${{ runner.os }}-${{ hashFiles('.tago-src/go.sum', '.tago-src/**/*.go') }} |
| 54 | + |
| 55 | + - name: Build tago |
| 56 | + if: steps.tago-bin-cache.outputs.cache-hit != 'true' |
| 57 | + run: | |
| 58 | + cd .tago-src |
| 59 | + go build -o /usr/local/bin/tago ./cmd/tago/ |
| 60 | +
|
| 61 | + # Two builds, one per deploy target. The theme links every page and asset |
| 62 | + # with absURL, so each output carries its own base path: the Pages build |
| 63 | + # gets the /cpalgorithms-cli/ sub-path, the Cloudflare build gets the domain root. |
| 64 | + - name: Build for GitHub Pages |
| 65 | + working-directory: docs |
| 66 | + run: tago build --base-url "https://tamnd.github.io/cpalgorithms-cli/" --output public-pages |
| 67 | + |
| 68 | + # tago absURLs theme links but passes markdown content links through, so |
| 69 | + # root-relative links in content need the sub-path prefixed for the Pages |
| 70 | + # mirror. The Cloudflare build serves from the root and needs none. |
| 71 | + - name: Rewrite content links for the Pages sub-path |
| 72 | + run: | |
| 73 | + find docs/public-pages -name '*.html' -print0 | |
| 74 | + xargs -0 perl -pi -e 's|(href=")/(?!/)|${1}/cpalgorithms-cli/|g; s|(src=")/(?!/)|${1}/cpalgorithms-cli/|g' |
| 75 | +
|
| 76 | + - name: Build for Cloudflare Pages |
| 77 | + working-directory: docs |
| 78 | + run: tago build --base-url "https://cpalgorithms-cli.tamnd.com/" --output public-cf |
| 79 | + |
| 80 | + - name: Upload Pages artifact |
| 81 | + uses: actions/upload-pages-artifact@v5.0.0 |
| 82 | + with: |
| 83 | + path: docs/public-pages |
| 84 | + |
| 85 | + - name: Upload Cloudflare artifact |
| 86 | + uses: actions/upload-artifact@v7.0.1 |
| 87 | + with: |
| 88 | + name: public-cf |
| 89 | + path: docs/public-cf |
| 90 | + retention-days: 1 |
| 91 | + |
| 92 | + deploy-pages: |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: build |
| 95 | + environment: |
| 96 | + name: github-pages |
| 97 | + url: ${{ steps.deployment.outputs.page_url }} |
| 98 | + steps: |
| 99 | + - name: Deploy to GitHub Pages |
| 100 | + id: deployment |
| 101 | + uses: actions/deploy-pages@v5.0.0 |
| 102 | + |
| 103 | + deploy-cloudflare: |
| 104 | + runs-on: ubuntu-latest |
| 105 | + needs: build |
| 106 | + concurrency: |
| 107 | + group: cloudflare-pages-cpalgorithms-cli |
| 108 | + cancel-in-progress: true |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v6.0.2 |
| 111 | + with: |
| 112 | + fetch-depth: 1 |
| 113 | + sparse-checkout: scripts/ |
| 114 | + |
| 115 | + - name: Download Cloudflare artifact |
| 116 | + uses: actions/download-artifact@v8.0.1 |
| 117 | + with: |
| 118 | + name: public-cf |
| 119 | + path: public-cf |
| 120 | + |
| 121 | + - name: Ensure Cloudflare Pages config |
| 122 | + env: |
| 123 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 124 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 125 | + run: python3 scripts/ensure_cloudflare_pages.py --project cpalgorithms-cli --domain cpalgorithms-cli.tamnd.com --zone tamnd.com |
| 126 | + |
| 127 | + - name: Deploy to Cloudflare Pages |
| 128 | + env: |
| 129 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 130 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 131 | + run: | |
| 132 | + npx -y wrangler@4 pages deploy public-cf \ |
| 133 | + --project-name=cpalgorithms-cli \ |
| 134 | + --branch=main \ |
| 135 | + --commit-dirty=true |
0 commit comments