~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/steps

Shared steps for knotless workflows: Node, npm, Rust lint, coverage tools, SSH keys and waiting for checks

0
0

A step deploys a repository's site

Merged chadtmiller.com asked to merge into main from chadtmiller.com/steps:site
.knotless/steps/site.ymlnew+42−0
@@ -0,0 +1,42 @@
description: >-
Deploys a directory as the repository's site on knotless.page, with
`knotless site`, as the repository's owner. It uploads only the files
the live site does not hold already, then replaces the site's record.
It installs knotless first when the image has none. Give it an app
password of the owner's as SITE_PASSWORD, and run it only on a push to
the branch the site is built from.
inputs:
dir: {required: true, description: "The directory to deploy, in the checkout, such as dist."}
repo: {default: "", description: "The repository whose site it is, as knotless://<owner>/<name>. This run's repository, if empty."}
fallback: {default: "", description: "The page a single-page app answers every other page with, such as index.html. None, if empty."}
not-found: {default: "", description: "The page a missing path gets, with 404, such as 404.html. None, if empty."}
appview: {default: "https://knotless.dev", description: "The appview knotless installs from and reads through."}
needs: [tar]
secrets: [SITE_PASSWORD]
steps:
- name: deploy
run: |
set -eu
if [ -z "${SITE_PASSWORD:-}" ]; then
echo "site: SITE_PASSWORD is not given: pass an app password of the owner's to the step's secrets" >&2
exit 1
fi
export KNOTLESS_APPVIEW="$INPUT_APPVIEW"
if ! command -v knotless >/dev/null; then
export KNOTLESS_INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$KNOTLESS_INSTALL_DIR"
if command -v curl >/dev/null; then
curl -fsSL "$INPUT_APPVIEW/install.sh" | sh
else
wget -qO- "$INPUT_APPVIEW/install.sh" | sh
fi
export PATH="$KNOTLESS_INSTALL_DIR:$PATH"
fi
repo="${INPUT_REPO:-knotless://$KNOTLESS_RUN_REPO}"
owner="${repo#knotless://}"
export KNOTLESS_IDENTIFIER="${owner%%/*}"
export KNOTLESS_PASSWORD="$SITE_PASSWORD"
set -- "$repo" "$INPUT_DIR"
[ -z "$INPUT_FALLBACK" ] || set -- "$@" --fallback "$INPUT_FALLBACK"
[ -z "$INPUT_NOT_FOUND" ] || set -- "$@" --not-found "$INPUT_NOT_FOUND"
knotless site "$@"
README.md+17−0
@@ -22,6 +22,7 @@ Commit the `.knotless/uses.lock` it writes. Runs read it.
| `ssh-key` | Writes the SSH key from the secret `SSH_KEY` to `~/.ssh`. | `name`, `known-hosts` | |
| `wait-for-checks` | Waits for this commit's checks of other workflows to pass. Use it before deploying. | `workflows` (required), `minutes` | |
| `publish-lexicons` | Publishes the lexicons whose authority is in a zone: schema records in an account, and `_lexicon` TXT records naming it. Plans only unless `write` is `true`. | `did` (required), `zone` (required), `dir`, `write` | |
| `site` | Deploys a directory as the repository's site on knotless.page, as its owner, uploading only the files the live site lacks. | `dir` (required), `repo`, `fallback`, `not-found`, `appview` | |
`ssh-key` needs the secret passed to it by name:
@@ -55,6 +56,22 @@ steps:
secrets: [LEX_PASSWORD, CLOUDFLARE_API_TOKEN]
```
`site` takes an app password of the repository owner's as
`SITE_PASSWORD`. Run it only on a push to the branch the site is built
from, after the build:
```yaml
on:
push: {refs: [refs/heads/main]}
secrets: [SITE_PASSWORD]
steps:
- name: build
run: npm ci && npm run build
- uses: chadtmiller.com/steps/site@1
with: {dir: dist, fallback: index.html}
secrets: [SITE_PASSWORD]
```
Each step's `needs` lists the commands it expects in the image, checked
before it runs. A new version of a step is released with: