diff --git a/README.md b/README.md index b79df73..5a81a03 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Publish Rust crates using GitHub Actions -The action is using [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html) with format version +The action is using [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html) with format version `1` to collect the information about crates and workspace. ## Features @@ -51,6 +51,20 @@ Usually you don't need to set `publish-delay` because this action check availabi packages before publishing other but in some cases it may help work around __crates.io__ inconsistency problems. +## Outputs + +- `published` JSON formatted string with published crates as array of objects with `name` and `version` fields. + +You may want to use it with [`fromJSON`][fromJSON] function and object filters syntax +[1][object filters-join], [2][object filters-contains]. + +__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. + +[fromJSON]: https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson +[object filters-join]: https://docs.github.com/en/actions/learn-github-actions/expressions#example-of-join +[object filters-contains]: https://docs.github.com/en/actions/learn-github-actions/expressions#example-using-an-object-filter + ## Usage examples Basic usage (`Cargo.toml` sits in repository root): @@ -111,3 +125,19 @@ steps: registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} ignore-unpublished-changes: true ``` + +Output usage: + +```yaml + - 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](#outputs). diff --git a/action.yml b/action.yml index 15d297d..f7319ab 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,9 @@ inputs: ignore-unpublished-changes: description: 'Exit the workflow gracefully if package does not have a new version to publish' default: 'false' +outputs: + published: + description: 'JSON formatted string with published crates as list of objects with `name` and `version` fields' runs: using: 'node16' main: 'dist/index.js' diff --git a/src/main.ts b/src/main.ts index 7b0c70e..0c721d8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { getInput, info, setFailed, + setOutput, warning } from '@actions/core' import {ExecOptions, exec} from '@actions/exec' @@ -44,6 +45,8 @@ async function run(): Promise { const github = githubHandle(token) + const published: {name: string; version: string}[] = [] + try { info(`Searching cargo packages at '${path}'`) const packages = await findPackages(path) @@ -123,11 +126,16 @@ async function run(): Promise { await exec('cargo', ['update', '--dry-run'], exec_opts) info(`Package '${package_name}' published successfully`) } + published.push({ + name: package_name, + version: package_info.version + }) } } } catch (err) { setFailed(`${err}`) } + setOutput('published', published) } run()