|
| 1 | +# Publishes every shellcell package repository to dl.shellcell.dev. |
| 2 | +# |
| 3 | +# main holds desired state: snailmail.toml, the locks, the publication ledgers |
| 4 | +# and deployment receipts. gh-pages holds the built site, force-pushed as a |
| 5 | +# single orphan commit so the published bytes never accumulate in history. |
| 6 | +# |
| 7 | +# Artifact bytes are in neither branch. Each lock pins an origin on the |
| 8 | +# producing repository's GitHub Release, and snailmail refetches from it and |
| 9 | +# checks it against the committed digest, so a fresh runner can rebuild every |
| 10 | +# repository without any object storage. |
| 11 | +name: publish |
| 12 | + |
| 13 | +on: |
| 14 | + # A tool's release workflow dispatches this after publishing its assets. |
| 15 | + repository_dispatch: |
| 16 | + types: [release] |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + repository: |
| 20 | + description: Tool repository to adopt from, as owner/name |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + tag: |
| 24 | + description: Release tag to adopt, such as v0.1.2 |
| 25 | + required: false |
| 26 | + type: string |
| 27 | + # Republish after a lock is changed by hand: promote, yank or prune. |
| 28 | + push: |
| 29 | + branches: [main] |
| 30 | + |
| 31 | +permissions: |
| 32 | + contents: read |
| 33 | + |
| 34 | +# Publishing rebuilds shared state, so a second run waits rather than racing the |
| 35 | +# lock, the ledger and the branch. |
| 36 | +concurrency: |
| 37 | + group: publish |
| 38 | + cancel-in-progress: false |
| 39 | + |
| 40 | +jobs: |
| 41 | + publish: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + environment: production |
| 44 | + permissions: |
| 45 | + contents: write |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 |
| 48 | + with: |
| 49 | + ref: main |
| 50 | + # Publication ledgers are validated against reachable history. |
| 51 | + fetch-depth: 0 |
| 52 | + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 |
| 53 | + with: |
| 54 | + go-version: '1.25' |
| 55 | + |
| 56 | + # Pinned rather than @latest: the tool that decides what gets published |
| 57 | + # should change when someone decides to change it. This must be a tag that |
| 58 | + # exists and includes origin-backed blob restore, or plan cannot rebuild a |
| 59 | + # repository on a runner that holds no artifacts. |
| 60 | + - name: Install snailmail |
| 61 | + env: |
| 62 | + SNAILMAIL_VERSION: v0.0.2 |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | + go install "github.com/shellcell/snailmail/cmd/snailmail@${SNAILMAIL_VERSION}" |
| 66 | + snailmail version |
| 67 | +
|
| 68 | + - name: Adopt the release |
| 69 | + env: |
| 70 | + TOOL_REPOSITORY: ${{ github.event.client_payload.repository || inputs.repository }} |
| 71 | + TOOL_TAG: ${{ github.event.client_payload.tag || inputs.tag }} |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | + if [ -z "${TOOL_REPOSITORY}" ] || [ -z "${TOOL_TAG}" ]; then |
| 75 | + echo "no release to adopt; republishing current desired state" |
| 76 | + exit 0 |
| 77 | + fi |
| 78 | + bin/adopt-release.sh "${TOOL_REPOSITORY}" "${TOOL_TAG}" |
| 79 | +
|
| 80 | + - name: Commit desired state |
| 81 | + run: | |
| 82 | + set -euo pipefail |
| 83 | + git config user.name "github-actions[bot]" |
| 84 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 85 | + git add snailmail.toml repos |
| 86 | + if git diff --cached --quiet; then |
| 87 | + echo "desired state unchanged" |
| 88 | + else |
| 89 | + git commit -m "adopt ${TOOL_REPOSITORY:-release} ${TOOL_TAG:-}" |
| 90 | + fi |
| 91 | + env: |
| 92 | + TOOL_REPOSITORY: ${{ github.event.client_payload.repository || inputs.repository }} |
| 93 | + TOOL_TAG: ${{ github.event.client_payload.tag || inputs.tag }} |
| 94 | + |
| 95 | + # plan refetches any artifact this runner does not have from the origin |
| 96 | + # its lock records, verifying each against the committed digest. |
| 97 | + - name: Plan |
| 98 | + run: snailmail plan --out snailmail.snailmail-plan.json |
| 99 | + |
| 100 | + # --runner docker so the Debian repository is checked by a real apt |
| 101 | + # installing from the built tree, not only parsed. |
| 102 | + - name: Apply |
| 103 | + run: snailmail apply --plan snailmail.snailmail-plan.json --runner docker |
| 104 | + |
| 105 | + - name: Assemble the site |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | + rm -rf site && mkdir -p site |
| 109 | + # Each published repository is a symlink to its current managed |
| 110 | + # release, so the copy dereferences: Git stores a symlink as a symlink |
| 111 | + # and Pages would serve it as a text file rather than following it. |
| 112 | + # The glob also skips snailmail's control and staging directories, |
| 113 | + # which are dot-prefixed and must not reach the site. |
| 114 | + for repository in docs/*/; do |
| 115 | + name=$(basename "$repository") |
| 116 | + cp -RL "$repository" "site/$name" |
| 117 | + done |
| 118 | + # Owning the apex of the subdomain, so the CNAME lives at the root. |
| 119 | + echo "dl.shellcell.dev" > site/CNAME |
| 120 | + # Pages runs Jekyll by default, which would drop files beginning with |
| 121 | + # an underscore and rewrite others. |
| 122 | + touch site/.nojekyll |
| 123 | + cp public/index.html site/index.html |
| 124 | + find site -maxdepth 2 | sort | head -40 |
| 125 | +
|
| 126 | + - name: Deploy the site |
| 127 | + run: | |
| 128 | + set -euo pipefail |
| 129 | + # An orphan commit each time: the site is a snapshot, and keeping its |
| 130 | + # history would mean keeping every artifact ever published. |
| 131 | + cd site |
| 132 | + git init -q -b gh-pages |
| 133 | + git config user.name "github-actions[bot]" |
| 134 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 135 | + git add -A |
| 136 | + git commit -qm "publish ${GITHUB_SHA}" |
| 137 | + git push --force --quiet \ |
| 138 | + "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" gh-pages |
| 139 | + env: |
| 140 | + GITHUB_TOKEN: ${{ github.token }} |
| 141 | + |
| 142 | + # Ledgers and receipts are written by apply, so desired state and the |
| 143 | + # record of what happened are pushed together after it. |
| 144 | + - name: Push the publication record |
| 145 | + run: | |
| 146 | + set -euo pipefail |
| 147 | + # Neither directory exists until the first apply has written one. |
| 148 | + git add --all -- publications deployments 2>/dev/null || true |
| 149 | + if ! git diff --cached --quiet; then |
| 150 | + git commit -m "record publication ${GITHUB_SHA}" |
| 151 | + fi |
| 152 | + git push origin HEAD:main |
0 commit comments