From ba8112eb849959aba3828addc8ade0f42af69433 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 18 Apr 2024 09:28:41 -0700 Subject: [PATCH] Add CI job to publish on crates.io when a release is tagged This uses `katyo/publish-crates@v1`, which checks which crates have had their versions bumped, and releases them on crates.io. While making sure to publish dependencies first before the crate that depends on them. This has apparently worked well in drm-rs. Since subcrates are versioned differently, when we discussed this earlier date-based tags names seemed best. So as @elinorbgr suggested, this goes with `release-YYYY-MM-DD` as the tagging scheme. (The CI job checks for tags prefixed with `release-`). I can't really think of anything better than that. So to release, we should be able to simply update the versions in `Cargo.toml` files, update the changelog files, and tag a release. The `publish-crates` action requires that all subcrates depends on the latest version of any other crate in the repository. And it requires that all crates with changes have a bumped version so they can be released. This seems a bit annoying if we wanted to just release a change to `wayland-backend`, for instance, but should help avoid mistakes. Manually dealing with the releases for all the crates here, without any automated checks, is error-prone. The action here does a `dry-run` for all CI runs (and uses `ignore-unpublished-changes` to not error if crates have changes without already having their versions bumped). But disables `dry-run` when a tag is pushed with the right format. A `CRATES_TOKEN` secret will need to be added to the repository for this to work. --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40b64f9761c..bf36af0c5f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,8 @@ on: push: branches: - master + tags: + - 'release-[0-9]+-[0-9]+-[0-9]+' pull_request: jobs: @@ -429,3 +431,24 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./target/doc force_orphan: true + + publish: + needs: + - format + - doc + - check-minimal + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Publish crates + uses: katyo/publish-crates@v1 + with: + registry-token: ${{ secrets.CRATES_TOKEN }} + args: --no-verify + dry-run: ${{ !(github.repository == 'Smithay/wayland-rs' && startsWith(github.ref, 'refs/tags/release-')) }} + ignore-unpublished-changes: ${{ !(github.repository == 'Smithay/wayland-rs' && startsWith(github.ref, 'refs/tags/release-')) }}