Home

Awesome

License: MIT CI Status

Publish Rust crates using GitHub Actions

The action is using cargo metadata with format version 1 to collect the information about crates and workspace.

Features

Unimplemented features

Inputs

Each local package (workspace member) potentially may be modified since last published version without corresponding version bump. This situation is dangerous and should be prevented. In order to do it this action uses GitHub API to get date of latest commit which modified contents by path of corresponding package. This date compares with date of last published version of that package. When option check-repo set to true (which is by default) this action will throw error in case when last commit date cannot be determined. This happenned in case of detached refs (like pull requests). Usually you should never publish packages via pull-requests so you may simply disable this action for run in such cases (via if expression as example). When you want to run action (say with dry-run set to true) prevent failing you may simply set check-repo to false too.

NOTE: You should avoid setting both check-repo and dry-run to false.

Usually you don't need to set publish-delay because this action check availability of previously published packages before publishing other but in some cases it may help work around crates.io inconsistency problems.

Outputs

You may want to use it with fromJSON function and object filters syntax 1, 2.

This works whether "dry-run" is enabled or not. That means that when dry-run: true you will get packages that could have been published.

Usage examples

Basic usage (Cargo.toml sits in repository root):

steps:
    - uses: actions/checkout@v3
    - uses: actions-rs/toolchain@v1
      with:
          toolchain: stable
          override: true
    - uses: katyo/publish-crates@v2
      with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Advanced usage (Cargo.toml sits in 'packages' subdir, and you would like to skip verification and bypass real publishing):

steps:
    - uses: actions/checkout@v3
    - uses: actions-rs/toolchain@v1
      with:
          toolchain: stable
          override: true
    - uses: katyo/publish-crates@v2
      with:
          path: './packages'
          args: --no-verify
          dry-run: true

Do all checks in both push and pull requests, but only publish on push:

steps:
    - uses: actions/checkout@v3
    - uses: actions-rs/toolchain@v1
      with:
          toolchain: stable
          override: true
    - uses: katyo/publish-crates@v2
      with:
          dry-run: ${{ github.event_name != 'push' }}

Prevent failing when there is no new version to publish:

steps:
    - uses: actions/checkout@v3
    - uses: actions-rs/toolchain@v1
      with:
          toolchain: stable
          override: true
    - uses: katyo/publish-crates@v2
      with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          ignore-unpublished-changes: true

Output usage:

    - uses: katyo/publish-crates@v2
      id: publish-crates
      with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

    - name: if my-crate published
          if: fromJSON(steps.publish-crates.outputs.published).*
          run: |
            LIST="${{ join(fromJSON(steps.publish-crates.outputs.published).*.name, ', ')) }}"
            echo "Published crates: $LIST"

NOTE: This is also works if dry-run is enabled. It explained in Outputs.