Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actions/workers/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
directory:
description: Directory containing the Worker's package and Wrangler configuration
default: '.'
dev-shell:
description: Flake dev shell attribute providing Node and pnpm
default: ''
wrangler-environment:
description: Wrangler environment for a branch deployment
default: ''
Expand Down Expand Up @@ -32,6 +35,7 @@ runs:
env:
GH_TOKEN: ${{ github.token }}
WORKER_DIRECTORY: ${{ inputs.directory }}
WORKER_DEV_SHELL: ${{ inputs.dev-shell }}
WRANGLER_ENVIRONMENT: ${{ inputs.wrangler-environment }}
D1_DATABASE: ${{ inputs.d1-database }}
run: |
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/docs-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Docs Preview Cleanup

on:
workflow_call:
inputs:
directory:
description: Directory containing the docs site package
type: string
default: '.'
shell:
description: Flake dev shell attribute providing the docs toolchain
type: string
default: 'default'
sparse-checkout:
description: Non-cone sparse-checkout patterns passed to actions/checkout
type: string
default: ''
submodules:
description: Check out submodules
type: boolean
default: false
secrets:
CLOUDFLARE_API_TOKEN:
description: Cloudflare API token for preview cleanup
required: true
CLOUDFLARE_ACCOUNT_ID:
description: Cloudflare account that owns the Worker if Wrangler omits account_id
required: false

permissions:
contents: read
pull-requests: read

jobs:
cleanup:
name: Delete Preview
if: >-
github.event_name == 'pull_request_target' &&
github.event.action == 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login != 'dependabot[bot]'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
pull-requests: read
concurrency:
group: preview-${{ github.event.pull_request.number }}
queue: max

steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
sparse-checkout: ${{ inputs.sparse-checkout }}
sparse-checkout-cone-mode: ${{ inputs.sparse-checkout == '' }}
submodules: ${{ inputs.submodules }}

- name: Set up Nix
uses: $/.github/actions/setup-nix

- name: Install dependencies
env:
DOCS_DIRECTORY: ${{ inputs.directory }}
DOCS_SHELL: ${{ inputs.shell }}
run: |
nix develop ".#$DOCS_SHELL" \
--print-build-logs \
-c pnpm --dir "$DOCS_DIRECTORY" install --frozen-lockfile

- name: Delete preview
uses: $/.github/actions/workers
with:
directory: ${{ inputs.directory }}
dev-shell: ${{ inputs.shell }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
267 changes: 267 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
name: Docs

on:
workflow_call:
inputs:
directory:
description: Directory containing the docs site package
type: string
default: '.'
shell:
description: Flake dev shell attribute providing the docs toolchain
type: string
default: 'default'
lychee:
description: Check internal links in the built dist output with lychee
type: boolean
default: true
e2e:
description: Run Playwright end-to-end tests
type: boolean
default: false
deploy:
description: Upload dist and deploy pull request previews and default-branch builds to Workers
type: boolean
default: false
wrangler-environment:
description: Wrangler environment for production deployments
type: string
default: ''
sparse-checkout:
description: Non-cone sparse-checkout patterns passed to actions/checkout
type: string
default: ''
submodules:
description: Check out submodules
type: boolean
default: false
secrets:
CACHIX_AUTH_TOKEN:
description: Upload token for the `hakula` Cachix cache
CLOUDFLARE_API_TOKEN:
description: Cloudflare API token for preview and production deployments
required: false
CLOUDFLARE_ACCOUNT_ID:
description: Cloudflare account that owns the Worker if Wrangler omits account_id
required: false

permissions:
contents: read

jobs:
build:
name: Build & Check
runs-on: ubuntu-latest
env:
DOCS_DIRECTORY: ${{ inputs.directory }}
DOCS_SHELL: ${{ inputs.shell }}

steps:
- name: Checkout
uses: actions/checkout@v7
with:
persist-credentials: false
sparse-checkout: ${{ inputs.sparse-checkout }}
sparse-checkout-cone-mode: ${{ inputs.sparse-checkout == '' }}
submodules: ${{ inputs.submodules }}

- name: Set up Nix
uses: $/.github/actions/setup-nix
with:
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Install dependencies
run: |
nix develop ".#$DOCS_SHELL" \
--print-build-logs \
-c pnpm --dir "$DOCS_DIRECTORY" install --frozen-lockfile

- name: Check formatting
run: nix develop ".#$DOCS_SHELL" -c pnpm --dir "$DOCS_DIRECTORY" run format:check

- name: Typecheck
run: nix develop ".#$DOCS_SHELL" -c pnpm --dir "$DOCS_DIRECTORY" run check

- name: Lint
run: nix develop ".#$DOCS_SHELL" -c pnpm --dir "$DOCS_DIRECTORY" run lint

- name: Build
run: nix develop ".#$DOCS_SHELL" -c pnpm --dir "$DOCS_DIRECTORY" run build

- name: Check links
if: ${{ inputs.lychee }}
run: |
nix develop ".#$DOCS_SHELL" -c sh -s -- "$DOCS_DIRECTORY" <<'EOF'
set -eu
cd "$1"
exec lychee \
--offline \
--root-dir "$PWD/dist" \
dist
EOF

- name: Run E2E tests
if: ${{ inputs.e2e }}
run: nix develop ".#$DOCS_SHELL" -c pnpm --dir "$DOCS_DIRECTORY" run test:e2e

- name: Upload site artifact
if: ${{ inputs.deploy }}
uses: actions/upload-artifact@v7
with:
name: docs-dist
path: ${{ inputs.directory }}/dist
if-no-files-found: error

deploy-preview:
name: Deploy Preview
needs: [build]
if: >-
inputs.deploy &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login != 'dependabot[bot]'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
pull-requests: write
concurrency:
group: preview-${{ github.event.pull_request.number }}
queue: max

steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
sparse-checkout: ${{ inputs.sparse-checkout }}
sparse-checkout-cone-mode: ${{ inputs.sparse-checkout == '' }}
submodules: ${{ inputs.submodules }}

- name: Set up Nix
uses: $/.github/actions/setup-nix
with:
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Install dependencies
env:
DOCS_DIRECTORY: ${{ inputs.directory }}
DOCS_SHELL: ${{ inputs.shell }}
run: |
nix develop ".#$DOCS_SHELL" \
--print-build-logs \
-c pnpm --dir "$DOCS_DIRECTORY" install --frozen-lockfile

- name: Download site artifact
uses: actions/download-artifact@v8
with:
name: docs-dist
path: ${{ inputs.directory }}/dist

- name: Deploy preview
id: workers
uses: $/.github/actions/workers
with:
directory: ${{ inputs.directory }}
dev-shell: ${{ inputs.shell }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

- name: Comment preview URL
if: ${{ steps.workers.outputs.applied == 'true' }}
uses: actions/github-script@v9
env:
PREVIEW_URL: ${{ steps.workers.outputs.preview-url }}
DEPLOYMENT_URL: ${{ steps.workers.outputs.deployment-url }}
with:
script: |
const marker = '<!-- docs-preview -->';
const body = [
marker,
`Preview: ${process.env.PREVIEW_URL}`,
`Deployment: ${process.env.DEPLOYMENT_URL}`,
].join('\n');

const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existing = comments.find(
(comment) =>
comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker),
);

if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}

deploy-production:
name: Deploy Production
needs: [build]
if: >-
inputs.deploy &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
concurrency:
group: docs-${{ inputs.wrangler-environment || 'production' }}
queue: max

steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
sparse-checkout: ${{ inputs.sparse-checkout }}
sparse-checkout-cone-mode: ${{ inputs.sparse-checkout == '' }}
submodules: ${{ inputs.submodules }}

- name: Set up Nix
uses: $/.github/actions/setup-nix
with:
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Install dependencies
env:
DOCS_DIRECTORY: ${{ inputs.directory }}
DOCS_SHELL: ${{ inputs.shell }}
run: |
nix develop ".#$DOCS_SHELL" \
--print-build-logs \
-c pnpm --dir "$DOCS_DIRECTORY" install --frozen-lockfile

- name: Download site artifact
uses: actions/download-artifact@v8
with:
name: docs-dist
path: ${{ inputs.directory }}/dist

- name: Deploy production
uses: $/.github/actions/workers
with:
directory: ${{ inputs.directory }}
dev-shell: ${{ inputs.shell }}
wrangler-environment: ${{ inputs.wrangler-environment }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| Nushell application builders, `dk.nushell`, or skill helpers | [Nushell tooling](docs/nushell.md) |
| `nu-test`, `nu-check`, or `nuTests` | [Nushell test runner](docs/nu-test.md) |
| Nix or language CI, `ci-result`, or Workers deployment | [CI workflow and gate](docs/ci.md) |
| `mkDocsShell`, `docs.yml`, or `docs-cleanup.yml` | [Docs site](docs/docs-site.md) |
| An action, a reusable workflow, or `cliff.toml` | [Releasing](docs/releasing.md) |
| A devkit release or versioning decision | [Releasing devkit](RELEASING.md) |
| The Renovate preset | [Renovate preset](docs/renovate.md) |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ devkit provides shared development tools for Hakula's repositories.
| [Nushell tooling](docs/nushell.md) | Application and skill packaging |
| [Nushell test runner](docs/nu-test.md) | Tests and script checks |
| [CI workflow and gate](docs/ci.md) | CI checks and Workers deployment |
| [Docs site](docs/docs-site.md) | Docs shell, checks, and deployment |
| [Releasing](docs/releasing.md) | Release a consumer project |
| [Releasing devkit](RELEASING.md) | Version policy and rollback |
| [Renovate preset](docs/renovate.md) | Dependency updates and automerge |
Expand Down
Loading
Loading