diff --git a/.github/workflows/release-lsp.yml b/.github/workflows/release-lsp.yml index c95615d..e29c278 100644 --- a/.github/workflows/release-lsp.yml +++ b/.github/workflows/release-lsp.yml @@ -5,14 +5,16 @@ name: Release (language server) # released as one native program for each platform the pinned toolchain # serves. The archives are attached to the GitHub release, where the toolchain # and a user can take them. The package, `hypermarkdown-lsp`, is published to -# crates.io by hand until a trusted publisher is configured for it. +# crates.io through a trusted publisher. The package and the program have +# different names because `hmd-lsp` on crates.io belongs to another project. # # The prefix begins with `l`, so neither `v[0-9]*` (the Python tool), nor # `ts-core-v*`, `rs-core-v[0-9]*`, `semantics-v[0-9]*` or `vsc-ext-v*` matches # it, and this workflow matches none of theirs. # -# `workflow_dispatch` runs every gate and builds every archive, and cuts no -# release, so the packaging path can be exercised without minting a tag. +# `workflow_dispatch` runs every gate and builds every archive, and publishes +# nothing and cuts no release, so the packaging path can be exercised without +# minting a tag. on: push: tags: ["lsp-v[0-9]*"] @@ -180,9 +182,48 @@ jobs: path: tools/hmd-lsp/dist/* if-no-files-found: error + crates-io: + name: publish to crates.io + # After every platform has built: a version on crates.io can never be + # replaced, so nothing is published from a commit that fails to build + # somewhere. + needs: build + if: startsWith(github.ref, 'refs/tags/lsp-v') + runs-on: ubuntu-latest + environment: + name: crates-io + url: https://crates.io/crates/hypermarkdown-lsp + # Trusted publishing: the job proves its identity to crates.io with a + # short-lived OIDC token, so there is no registry token in repository + # secrets. It requires a trusted publisher configured on the crate's + # crates.io settings: repository `ewiger/hypermarkdown`, workflow + # `release-lsp.yml`, environment `crates-io`. There is deliberately no + # `CARGO_REGISTRY_TOKEN` fallback, the same stance the other releases take. + permissions: + contents: read + id-token: write + defaults: + run: + working-directory: tools/hmd-lsp + steps: + - uses: actions/checkout@v7 + + - name: Install Rust + run: rustup toolchain install stable --profile minimal && rustup default stable + + - uses: rust-lang/crates-io-auth-action@v1 + id: auth + + # The package depends on the resolver crate by version here, not by + # path, so the resolver's release has to be on crates.io already. + - name: Publish + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + run: cargo publish --locked + github-release: name: github release - needs: build + needs: [build, crates-io] if: startsWith(github.ref, 'refs/tags/lsp-v') runs-on: ubuntu-latest # The one job that writes to the repository, and it writes only the release. diff --git a/doc/status/lsp.hmd b/doc/status/lsp.hmd index 0bf8d8a..e5d0490 100644 --- a/doc/status/lsp.hmd +++ b/doc/status/lsp.hmd @@ -42,7 +42,6 @@ linter. | Status | Work | Notes | References | | --- | --- | --- | --- | -| todo | **Publish to crates.io from the workflow.** The first publication is by hand, because crates.io allows a trusted publisher only on a crate that exists. Configure one for `hypermarkdown-lsp`, naming this repository, `release-lsp.yml` and an environment, and add the job | The resolver crate's workflow is the model | [[hmd-0033#distribution]] | | todo | **The toolchain carries the binary** beside `d2` and `hql`, so the extension bundles it and a user installs nothing. The first release is cut, so nothing blocks this; the work is in the toolchain repository | Decide first whether the toolchain repository builds the binary or takes it from this repository's release | [[hmd-0033#distribution]] | | todo | **Go to a heading or a block.** A reference with a fragment leads to the top of the card today. It should lead to the heading or the block the fragment names | The resolver crate reads no heading and no block anchor. The rule that turns a heading's text into the name a fragment matches is the language's, so the code belongs in the crate | [[hmd-0033#go-to-definition]] | | todo | **Tokens for block anchors and frontmatter.** A trailing `^block-id` and the frontmatter block get no token | The crate reports neither position today | [[hmd-0033#semantic-tokens]] | @@ -94,6 +93,11 @@ Nothing known. archives and `SHA256SUMS` on the GitHub release, built by the workflow on its first tagged run, and `hypermarkdown-lsp` 0.1.0 on crates.io, published by hand. The resolver crate 0.4.0 went first. +- **The workflow publishes the package** — an `lsp-vX.Y.Z` tag publishes + `hypermarkdown-lsp` to crates.io through a trusted publisher, in the + `crates-io` environment, after all five platforms have built and before the + GitHub release is cut. First used by the release after 0.1.0 + [[hmd-0033#distribution]]. - **A release workflow** — `release-lsp.yml`, on an `lsp-vX.Y.Z` tag: the gates, one program for each of the five platforms the toolchain serves, named after its Rust target as HQL names its archives, and a GitHub release @@ -121,6 +125,8 @@ cargo test --locked ## Changelog +- 2026-11-25: the release workflow publishes the package to crates.io; the + row for it becomes a Done row. - 2026-11-25: 0.1.0 is released. The row for cutting it becomes a Done row, and the toolchain row is no longer blocked. - 2026-11-25: the package is `hypermarkdown-lsp`, because `hmd-lsp` on diff --git a/doc/status/open.hmd b/doc/status/open.hmd index 53d69f5..b4fe133 100644 --- a/doc/status/open.hmd +++ b/doc/status/open.hmd @@ -76,7 +76,7 @@ the board, in the order this view lists them. | state | rows | | ------- | ---- | | doing | 2 | -| todo | 33 | +| todo | 32 | | blocked | 4 | | backlog | 15 | | parked | 3 | @@ -110,7 +110,6 @@ Every open row, `doing` first, then `todo`, `blocked`, `backlog` and | todo | Validate the grammar, a release requirement for 0.1. | [lang](lang.hmd) | | todo | Review lexical compatibility with CommonMark. | [lang](lang.hmd) | | todo | Accept Mermaid as a diagram language on par with D2. | [lang](lang.hmd) | -| todo | Publish to crates.io from the workflow. | [lsp](lsp.hmd) | | todo | The toolchain carries the binary | [lsp](lsp.hmd) | | todo | Go to a heading or a block. | [lsp](lsp.hmd) | | todo | Tokens for block anchors and frontmatter. | [lsp](lsp.hmd) | diff --git a/tests/test_release.py b/tests/test_release.py index d30c4c6..1938044 100644 --- a/tests/test_release.py +++ b/tests/test_release.py @@ -103,3 +103,22 @@ def test_the_language_server_workflow_fires_on_its_own_tags_only(): continue for pattern in re.findall(r'tags: \["([^"]+)"\]', other.read_text()): assert not fnmatch.fnmatchcase("lsp-v0.1.0", pattern), other.name + + +def test_the_language_server_is_published_through_a_trusted_publisher(): + """crates.io accepts the publish only from this workflow and environment. + + The trusted publisher on the crate names the workflow file and the + environment. A job that publishes from another environment, or with a + stored token, is refused or is a secret nobody rotates. + """ + workflow = (WORKFLOWS / "release-lsp.yml").read_text() + job = workflow[workflow.index(" crates-io:") : workflow.index(" github-release:")] + assert "name: crates-io" in job + assert "id-token: write" in job + assert "rust-lang/crates-io-auth-action" in job + # No stored token anywhere in the workflow, in an expression that reads one. + assert "${{ secrets." not in workflow + # Nothing is published from a manual run, or before every platform built. + assert "startsWith(github.ref, 'refs/tags/lsp-v')" in job + assert "needs: build" in job diff --git a/tools/hmd-lsp/CHANGELOG.md b/tools/hmd-lsp/CHANGELOG.md index b15b050..8318a97 100644 --- a/tools/hmd-lsp/CHANGELOG.md +++ b/tools/hmd-lsp/CHANGELOG.md @@ -19,6 +19,12 @@ Implementation state is tracked in ## [Unreleased] +### Changed + +- **The release workflow publishes the package.** An `lsp-vX.Y.Z` tag now + publishes `hypermarkdown-lsp` to crates.io through a trusted publisher, + after every platform has built. 0.1.0 was published by hand. + ## [0.1.0] — 2026-11-25 The first release. The program is `hmd-lsp`. The package on crates.io is diff --git a/tools/hmd-lsp/DEVELOP.md b/tools/hmd-lsp/DEVELOP.md index f739208..c3908cc 100644 --- a/tools/hmd-lsp/DEVELOP.md +++ b/tools/hmd-lsp/DEVELOP.md @@ -106,11 +106,14 @@ program have different names. A release is: on a path; 3. a run of the workflow by hand (`workflow_dispatch`), which runs every gate and builds all five archives, and cuts no release; -4. the tag `lsp-vX.Y.Z` pushed, which builds the archives again and cuts the - GitHub release; -5. `cargo publish --locked` from this directory. It is run by hand: crates.io - lets a workflow publish through a trusted publisher only for a crate that - exists, and no trusted publisher is configured for this one yet. +4. the tag `lsp-vX.Y.Z` pushed, which builds the archives again, publishes + the package to crates.io, and cuts the GitHub release. + +The package's trusted publisher on crates.io names repository +`ewiger/hypermarkdown`, workflow `release-lsp.yml` and environment +`crates-io`; renaming any of the three breaks publication. 0.1.0 was +published by hand, because crates.io allows a trusted publisher only on a +crate that exists. The platforms are the five the pinned toolchain serves, and a test in `tests/test_release.py` holds the two lists together: