Skip to content

Commit

Permalink
add published output
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook authored and katyo committed Sep 14, 2023
1 parent 18ee0da commit 2fcfbf7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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).
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getInput,
info,
setFailed,
setOutput,
warning
} from '@actions/core'
import {ExecOptions, exec} from '@actions/exec'
Expand Down Expand Up @@ -44,6 +45,8 @@ async function run(): Promise<void> {

const github = githubHandle(token)

const published: {name: string; version: string}[] = []

try {
info(`Searching cargo packages at '${path}'`)
const packages = await findPackages(path)
Expand Down Expand Up @@ -123,11 +126,16 @@ async function run(): Promise<void> {
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()

0 comments on commit 2fcfbf7

Please sign in to comment.