name: Publish Artifacts to harlequin.sh # Three files are generated here and read on the site: the base config schema, # whose `$id` is a URL there; the generated CLI reference; and the skill. # `tconbeer/harlequin-web` vendors them under `static/artifacts/` rather than # fetching them at build time, so its build stays hermetic and a network blip # cannot fail a deploy. This opens the PR that updates them; a human merges it, # and until they do the site serves the previous release's copies. # # Runs after a release publishes, and by hand for any ref -- a release that # went out before this existed is `Run workflow` on the tag. on: workflow_call: inputs: ref: description: The harlequin ref to publish the artifacts from type: string required: false default: main workflow_dispatch: inputs: ref: description: The harlequin ref to publish the artifacts from (e.g., "v2.13.0") type: string required: false default: main jobs: publish-artifacts: runs-on: ubuntu-latest env: # write access to the other repo, which the default GITHUB_TOKEN does not # have. A fine-grained PAT scoped to harlequin-web alone, with Contents # read and write (the branch this pushes) and Pull requests read and # write (the PR it opens); nothing here touches that repo's workflows. # It must be a repository secret -- this job joins no environment, so an # environment secret is not visible to it, and the first step says so. SITE_TOKEN: ${{ secrets.HARLEQUIN_WEB_TOKEN }} SITE_REPO: tconbeer/harlequin-web SITE_ARTIFACTS_DIR: static/artifacts STAGED_DIR: ${{ github.workspace }}/dist/artifacts steps: - name: Check that a token for the site is configured # before anything is built, and loudly: a publish that quietly does # nothing leaves the site a release behind with nothing to notice it. run: | if [ -z "$SITE_TOKEN" ]; then echo "::error::HARLEQUIN_WEB_TOKEN is not set (or has expired); cannot open a PR against $SITE_REPO." exit 1 fi - name: Check out harlequin uses: actions/checkout@v7 with: ref: ${{ inputs.ref }} - name: Set up Python 3.10 uses: actions/setup-python@v7 with: python-version: "3.10" - name: Install uv uses: astral-sh/setup-uv@v10.1.0 with: version: "0.12.13" - name: Name this release, and the branch that carries it id: release run: | version=$(uv version --short) echo "version=$version" >> $GITHUB_OUTPUT echo "branch=artifacts/harlequin-v$version" >> $GITHUB_OUTPUT - name: Check that the generated artifacts are current # this publishes the committed files, so a generator that disagrees # with them would put a page on the site that is in no release. run: | uv run python scripts/write_config_schema.py uv run python scripts/write_cli_reference.py if ! git diff --exit-code; then echo "::error::The committed artifacts are not what the generators write; regenerate and commit them." exit 1 fi - name: Stage the artifacts run: uv run python scripts/publish_artifacts.py --output "$STAGED_DIR" - name: Check out harlequin-web uses: actions/checkout@v7 with: repository: ${{ env.SITE_REPO }} token: ${{ env.SITE_TOKEN }} path: site - name: Vendor the artifacts # replaced wholesale, so a file this repo stops publishing stops being # served rather than lingering as the one copy nothing regenerates. run: | rm -rf "site/$SITE_ARTIFACTS_DIR" mkdir -p "site/$SITE_ARTIFACTS_DIR" cp -R "$STAGED_DIR/." "site/$SITE_ARTIFACTS_DIR/" - name: Commit the artifacts id: commit uses: stefanzweifel/git-auto-commit-action@v7 with: repository: site file_pattern: ${{ env.SITE_ARTIFACTS_DIR }} branch: ${{ steps.release.outputs.branch }} create_branch: true # the branch is this workflow's own, one per version: a re-run for # the same version replaces what the last one pushed. push_options: --force commit_message: Vendor harlequin v${{ steps.release.outputs.version }}'s published artifacts - name: Look for a pull request this run would duplicate # GitHub takes one open PR per branch, and a re-run pushes onto the # branch its last run made -- which has just updated that PR. id: open_pr if: ${{ steps.commit.outputs.changes_detected == 'true' }} env: GH_TOKEN: ${{ env.SITE_TOKEN }} run: | number=$(gh pr list --repo "$SITE_REPO" --head "${{ steps.release.outputs.branch }}" --state open --json number --jq '.[].number') echo "number=$number" >> $GITHUB_OUTPUT - name: Create pull request into harlequin-web if: ${{ steps.commit.outputs.changes_detected == 'true' && steps.open_pr.outputs.number == '' }} uses: thomaseizinger/create-pull-request@1.4.0 env: GITHUB_TOKEN: ${{ env.SITE_TOKEN }} with: repository: ${{ env.SITE_REPO }} head: ${{ steps.release.outputs.branch }} base: main title: Vendor harlequin v${{ steps.release.outputs.version }}'s published artifacts body: > This PR was automatically generated by `publish-artifacts.yml` in tconbeer/harlequin. It vendors the artifacts harlequin v${{ steps.release.outputs.version }} generates: the base config schema served at `/schemas/config/v1.json`, the generated `hsql` CLI reference, and the Agent Skill and its references. `manifest.json` records the version they came from. Nothing under `static/artifacts/` is written by hand. Edits belong in tconbeer/harlequin, and the next release overwrites them.