Publishing from CI

The Publish button builds the site on your computer and sends the pages to GitHub. A workflow in GitHub Actions can do the same on GitHub's machines: on every change to a site kept on GitHub, or every hour for a site kept in Google Drive. Nobody has to open SeedPage, and the published site is the same. This page is for administrators who know their way around GitHub.

The workflow writes the pages where the Publish button writes them: the docs folder of the main branch of the repository of the pages, which GitHub Pages serves. Both can be used on the same site; whichever ran last is what is online.

What the workflow does

  • Fetches SeedPage itself from its public repository, and Node.js 22.
  • Builds the site with node seedpage/src/build-site.js, from the folder of the sources or from the Drive folder, into dist.
  • Replaces the docs folder of the repository of the pages with dist, and commits when something changed. GitHub Pages then publishes it.

If the site has a domain of your own, the published pages need a CNAME file holding it, as the Publish button writes: add echo clearaccounts.com > dist/CNAME before the pages are copied, with your domain.

A site kept on GitHub, everything public

When the site was made with Everything public, one repository holds the sources at its root and the published pages in docs. Add this file to it as .github/workflows/publish.yml:

YAML
name: Publish
on:
  push:
    branches: [main]
    paths-ignore: [docs/**]
  workflow_dispatch:
permissions:
  contents: write
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          path: pages
      - uses: actions/checkout@v4
        with:
          repository: concriz-group/seedpage
          path: seedpage
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm ci
        working-directory: seedpage
      - run: node seedpage/src/build-site.js --folder pages --out dist
      - name: Put the pages in docs/
        run: |
          touch dist/.nojekyll
          rm -rf pages/docs && cp -r dist pages/docs
          cd pages
          git config user.name "SeedPage CI"
          git config user.email "ci@users.noreply.github.com"
          git add docs
          git diff --cached --quiet || git commit -m "Publish the site" && git push

paths-ignore keeps the workflow's own commit from starting it again. workflow_dispatch adds a Run workflow button in the repository's Actions tab.

A site kept on GitHub, private sources

With private sources there are two repositories: the private one with the sources, and the public one with the pages. The workflow lives in the sources and needs a token to write to the pages repository:

  1. On GitHub, Settings of your account, Developer settings, Fine-grained tokens, generate a token for the pages repository only, with Contents: Read and write.

  2. In the sources repository, Settings, Secrets and variables, Actions, add it as a secret named PAGES_TOKEN.

  3. Add the workflow below as .github/workflows/publish.yml, with the pages repository's owner and name.

YAML
name: Publish
on:
  push:
    branches: [main]
  workflow_dispatch:
permissions:
  contents: read
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          path: site
      - uses: actions/checkout@v4
        with:
          repository: concriz-group/seedpage
          path: seedpage
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm ci
        working-directory: seedpage
      - run: node seedpage/src/build-site.js --folder site --out dist
      - uses: actions/checkout@v4
        with:
          repository: your-name/clear-accounts
          token: ${{ secrets.PAGES_TOKEN }}
          path: pages
      - name: Put the pages in docs/
        run: |
          touch dist/.nojekyll
          rm -rf pages/docs && cp -r dist pages/docs
          cd pages
          git config user.name "SeedPage CI"
          git config user.email "ci@users.noreply.github.com"
          git add docs
          git diff --cached --quiet || git commit -m "Publish the site" && git push

A fine-grained token expires; GitHub e-mails you before it does. Make a new one and replace the secret.

A site kept in Google Drive

The workflow lives in the repository of the pages and reads the site from Drive with a Google service account, an account for programs, which only reads. A change in Drive does not reach GitHub, so the workflow runs on a schedule, every hour here, and with the Run workflow button.

In the Google Cloud project of your SeedPage installation:

  1. APIs and services: make sure the Google Drive, Google Docs and Google Sheets APIs are on.

  2. IAM and admin, Service accounts: create one, for example seedpage-ci. It needs no role in the project. Copy its e-mail address.

  3. In Google Drive, share the site's folder with that e-mail address, as Viewer.

  4. IAM and admin, Workload Identity Federation: create a pool, and in it a provider of type OpenID Connect with issuer https://token.actions.githubusercontent.com, the attribute mapping google.subject = assertion.sub and attribute.repository = assertion.repository, and the condition assertion.repository == 'your-name/clear-accounts', the repository of the pages.

  5. Back in the service account, Permissions, grant the role Workload Identity User to principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL/attribute.repository/your-name/clear-accounts.

Workload Identity Federation lets the workflow act as the service account without a key file: GitHub vouches for the repository, and Google gives it a short-lived token. There is no secret to keep or to leak. Then add the workflow to the repository of the pages:

YAML
name: Publish
on:
  schedule:
    - cron: "17 * * * *"
  workflow_dispatch:
permissions:
  contents: write
  id-token: write
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: google-github-actions/auth@v2
        with:
          workload_identity_provider: projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL/providers/PROVIDER
          service_account: seedpage-ci@PROJECT_ID.iam.gserviceaccount.com
      - uses: actions/checkout@v4
        with:
          repository: concriz-group/seedpage
          path: seedpage
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm ci
        working-directory: seedpage
      - run: node seedpage/src/build-site.js --root FOLDER_ID --out dist
        env:
          SEEDPAGE_GOOGLE_ACCESS: service-account
      - uses: actions/checkout@v4
        with:
          repository: ${{ github.repository }}
          token: ${{ github.token }}
          path: pages
      - name: Put the pages in docs/
        run: |
          touch dist/.nojekyll
          rm -rf pages/docs && cp -r dist pages/docs
          cd pages
          git config user.name "SeedPage CI"
          git config user.email "ci@users.noreply.github.com"
          git add docs
          git diff --cached --quiet || git commit -m "Publish the site" && git push

FOLDER_ID is the site's folder in Drive: the last part of its address when you open it, after folders/. PROJECT_NUMBER, PROJECT_ID, POOL and PROVIDER come from the Google Cloud console.

When something goes wrong

  • The build step prints warnings: they do not stop the publish, and the same ones show in SeedPage's editor. Fix them there and the next run publishes the fix.
  • Permission denied or 404 when the build reads Drive: the folder is not shared with the service account, or one of the three APIs is off.
  • The auth step fails: the provider's condition names another repository, or the role Workload Identity User was granted to another principal.
  • The push is refused: the token has no write access to the pages repository, or has expired; or contents: write is missing from permissions.