|
| 1 | +name: Docs |
| 2 | + |
| 3 | +# Builds the typedoc API reference and publishes it to the Cloudflare Pages |
| 4 | +# project behind tsdoc.libraries.ipregistry.co. Dispatched by the Release |
| 5 | +# workflow after a successful release and can be triggered manually for an |
| 6 | +# existing tag. |
| 7 | +# |
| 8 | +# Requires: |
| 9 | +# - CLOUDFLARE_API_TOKEN secret (API token with the "Cloudflare Pages: Edit" |
| 10 | +# permission) |
| 11 | +# - CLOUDFLARE_ACCOUNT_ID secret |
| 12 | +# - CLOUDFLARE_PAGES_PROJECT_TSDOC repository variable (the Pages project name) |
| 13 | +# |
| 14 | +# When any of them is missing (for example on a fork), publishing skips |
| 15 | +# cleanly and the job still succeeds so releases are not blocked. |
| 16 | +on: |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + tag: |
| 20 | + description: 'Existing release tag to build docs from, e.g. v6.2.0' |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: read |
| 26 | + |
| 27 | +jobs: |
| 28 | + publish: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - name: Determine and validate tag |
| 32 | + # The raw value is passed through the environment (never interpolated |
| 33 | + # into the shell) and strictly validated before being used as a ref. |
| 34 | + env: |
| 35 | + TAG_INPUT: ${{ inputs.tag }} |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | + if ! printf '%s' "$TAG_INPUT" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$'; then |
| 39 | + echo "::error::Invalid tag '$TAG_INPUT'. Expected a tag such as v1.2.0." |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + echo "TAG=$TAG_INPUT" >> "$GITHUB_ENV" |
| 43 | +
|
| 44 | + - uses: actions/checkout@v7 |
| 45 | + with: |
| 46 | + ref: ${{ env.TAG }} |
| 47 | + |
| 48 | + - name: Use Node.js |
| 49 | + uses: actions/setup-node@v6 |
| 50 | + with: |
| 51 | + node-version: 24.x |
| 52 | + |
| 53 | + - name: Install dependencies |
| 54 | + run: npm install |
| 55 | + |
| 56 | + - name: Build API reference |
| 57 | + run: npm run tsdoc |
| 58 | + |
| 59 | + - name: Publish to Cloudflare Pages |
| 60 | + env: |
| 61 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 62 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 63 | + PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT_TSDOC }} |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | + if [ -z "${CLOUDFLARE_API_TOKEN:-}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID:-}" ] || [ -z "${PAGES_PROJECT:-}" ]; then |
| 67 | + echo "::warning::Cloudflare Pages credentials are not configured (CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID secrets and CLOUDFLARE_PAGES_PROJECT_TSDOC variable); skipping docs publication." |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + npx wrangler@4 pages deploy docs --project-name "$PAGES_PROJECT" --branch main |
0 commit comments