| 1 |
name: Publish Artifacts to harlequin.sh |
| 2 |
|
| 3 |
# Three files are generated here and read on the site: the base config schema, |
| 4 |
# whose `$id` is a URL there; the generated CLI reference; and the skill. |
| 5 |
# `tconbeer/harlequin-web` vendors them under `static/artifacts/` rather than |
| 6 |
# fetching them at build time, so its build stays hermetic and a network blip |
| 7 |
# cannot fail a deploy. This opens the PR that updates them; a human merges it, |
| 8 |
# and until they do the site serves the previous release's copies. |
| 9 |
# |
| 10 |
# Runs after a release publishes, and by hand for any ref -- a release that |
| 11 |
# went out before this existed is `Run workflow` on the tag. |
| 12 |
|
| 13 |
on: |
| 14 |
workflow_call: |
| 15 |
inputs: |
| 16 |
ref: |
| 17 |
description: The harlequin ref to publish the artifacts from |
| 18 |
type: string |
| 19 |
required: false |
| 20 |
default: main |
| 21 |
workflow_dispatch: |
| 22 |
inputs: |
| 23 |
ref: |
| 24 |
description: The harlequin ref to publish the artifacts from (e.g., "v2.13.0") |
| 25 |
type: string |
| 26 |
required: false |
| 27 |
default: main |
| 28 |
|
| 29 |
jobs: |
| 30 |
publish-artifacts: |
| 31 |
runs-on: ubuntu-latest |
| 32 |
|
| 33 |
env: |
| 34 |
# write access to the other repo, which the default GITHUB_TOKEN does not |
| 35 |
# have. A fine-grained PAT scoped to harlequin-web alone, with Contents |
| 36 |
# read and write (the branch this pushes) and Pull requests read and |
| 37 |
# write (the PR it opens); nothing here touches that repo's workflows. |
| 38 |
# It must be a repository secret -- this job joins no environment, so an |
| 39 |
# environment secret is not visible to it, and the first step says so. |
| 40 |
SITE_TOKEN: ${{ secrets.HARLEQUIN_WEB_TOKEN }} |
| 41 |
SITE_REPO: tconbeer/harlequin-web |
| 42 |
SITE_ARTIFACTS_DIR: static/artifacts |
| 43 |
STAGED_DIR: ${{ github.workspace }}/dist/artifacts |
| 44 |
|
| 45 |
steps: |
| 46 |
- name: Check that a token for the site is configured |
| 47 |
# before anything is built, and loudly: a publish that quietly does |
| 48 |
# nothing leaves the site a release behind with nothing to notice it. |
| 49 |
run: | |
| 50 |
if [ -z "$SITE_TOKEN" ]; then |
| 51 |
echo "::error::HARLEQUIN_WEB_TOKEN is not set (or has expired); cannot open a PR against $SITE_REPO." |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
- name: Check out harlequin |
| 56 |
uses: actions/checkout@v7 |
| 57 |
with: |
| 58 |
ref: ${{ inputs.ref }} |
| 59 |
|
| 60 |
- name: Set up Python 3.10 |
| 61 |
uses: actions/setup-python@v7 |
| 62 |
with: |
| 63 |
python-version: "3.10" |
| 64 |
|
| 65 |
- name: Install uv |
| 66 |
uses: astral-sh/[email protected] |
| 67 |
with: |
| 68 |
version: "0.12.8" |
| 69 |
|
| 70 |
- name: Name this release, and the branch that carries it |
| 71 |
id: release |
| 72 |
run: | |
| 73 |
version=$(uv version --short) |
| 74 |
echo "version=$version" >> $GITHUB_OUTPUT |
| 75 |
echo "branch=artifacts/harlequin-v$version" >> $GITHUB_OUTPUT |
| 76 |
|
| 77 |
- name: Check that the generated artifacts are current |
| 78 |
# this publishes the committed files, so a generator that disagrees |
| 79 |
# with them would put a page on the site that is in no release. |
| 80 |
run: | |
| 81 |
uv run python scripts/write_config_schema.py |
| 82 |
uv run python scripts/write_cli_reference.py |
| 83 |
if ! git diff --exit-code; then |
| 84 |
echo "::error::The committed artifacts are not what the generators write; regenerate and commit them." |
| 85 |
exit 1 |
| 86 |
fi |
| 87 |
|
| 88 |
- name: Stage the artifacts |
| 89 |
run: uv run python scripts/publish_artifacts.py --output "$STAGED_DIR" |
| 90 |
|
| 91 |
- name: Check out harlequin-web |
| 92 |
uses: actions/checkout@v7 |
| 93 |
with: |
| 94 |
repository: ${{ env.SITE_REPO }} |
| 95 |
token: ${{ env.SITE_TOKEN }} |
| 96 |
path: site |
| 97 |
|
| 98 |
- name: Vendor the artifacts |
| 99 |
# replaced wholesale, so a file this repo stops publishing stops being |
| 100 |
# served rather than lingering as the one copy nothing regenerates. |
| 101 |
run: | |
| 102 |
rm -rf "site/$SITE_ARTIFACTS_DIR" |
| 103 |
mkdir -p "site/$SITE_ARTIFACTS_DIR" |
| 104 |
cp -R "$STAGED_DIR/." "site/$SITE_ARTIFACTS_DIR/" |
| 105 |
|
| 106 |
- name: Commit the artifacts |
| 107 |
id: commit |
| 108 |
uses: stefanzweifel/git-auto-commit-action@v7 |
| 109 |
with: |
| 110 |
repository: site |
| 111 |
file_pattern: ${{ env.SITE_ARTIFACTS_DIR }} |
| 112 |
branch: ${{ steps.release.outputs.branch }} |
| 113 |
create_branch: true |
| 114 |
# the branch is this workflow's own, one per version: a re-run for |
| 115 |
# the same version replaces what the last one pushed. |
| 116 |
push_options: --force |
| 117 |
commit_message: Vendor harlequin v${{ steps.release.outputs.version }}'s published artifacts |
| 118 |
|
| 119 |
- name: Look for a pull request this run would duplicate |
| 120 |
# GitHub takes one open PR per branch, and a re-run pushes onto the |
| 121 |
# branch its last run made -- which has just updated that PR. |
| 122 |
id: open_pr |
| 123 |
if: ${{ steps.commit.outputs.changes_detected == 'true' }} |
| 124 |
env: |
| 125 |
GH_TOKEN: ${{ env.SITE_TOKEN }} |
| 126 |
run: | |
| 127 |
number=$(gh pr list --repo "$SITE_REPO" --head "${{ steps.release.outputs.branch }}" --state open --json number --jq '.[].number') |
| 128 |
echo "number=$number" >> $GITHUB_OUTPUT |
| 129 |
|
| 130 |
- name: Create pull request into harlequin-web |
| 131 |
if: ${{ steps.commit.outputs.changes_detected == 'true' && steps.open_pr.outputs.number == '' }} |
| 132 |
uses: thomaseizinger/[email protected] |
| 133 |
env: |
| 134 |
GITHUB_TOKEN: ${{ env.SITE_TOKEN }} |
| 135 |
with: |
| 136 |
repository: ${{ env.SITE_REPO }} |
| 137 |
head: ${{ steps.release.outputs.branch }} |
| 138 |
base: main |
| 139 |
title: Vendor harlequin v${{ steps.release.outputs.version }}'s published artifacts |
| 140 |
body: > |
| 141 |
This PR was automatically generated by `publish-artifacts.yml` in |
| 142 |
tconbeer/harlequin. It vendors the artifacts harlequin |
| 143 |
v${{ steps.release.outputs.version }} generates: the base config schema |
| 144 |
served at `/schemas/config/v1.json`, the generated `hsql` CLI reference, |
| 145 |
and the Agent Skill and its references. `manifest.json` records the |
| 146 |
version they came from. |
| 147 |
|
| 148 |
Nothing under `static/artifacts/` is written by hand. Edits belong in |
| 149 |
tconbeer/harlequin, and the next release overwrites them. |