Skip to content

Commit

Permalink
Use cargo metadata to collect information about packages (#600)
Browse files Browse the repository at this point in the history
Added support of `{ workspace = true }` syntax.
  • Loading branch information
xgreenx committed Jan 27, 2023
1 parent 71853c8 commit 050b71d
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
check-repo: ${{ github.event_name == 'push' }}

publish: # publish dependency-free release with only self-contained dist directory
if: github.repository == 'katyo/publish-crates' && github.event_name == 'push' && github.ref_name == 'main'
if: github.event_name == 'push' && github.ref_name == 'main'
runs-on: ubuntu-latest
needs:
- build
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

# 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
`1` to collect the information about crates and workspace.

## Features

- Reads manifests to get info about crates and dependencies
Expand All @@ -13,6 +16,8 @@
- Publishes updated crates in right order according to dependencies
- Awaits when published crate will be available in registry before publishing crates which depends from it
- Works fine in workspaces without cyclic dependencies
- Support `{ workspace = true }` syntax in the `Cargo.toml`. [This](https://rust-lang.github.io/rfcs/2906-cargo-workspace-deduplicate.html)
feature was stabilized in Rust 1.64.

## Unimplemented features

Expand Down
12 changes: 12 additions & 0 deletions __tests__/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
[workspace]
members = [
"pkg-sys",
"pkg-skip",
"pkg-build",
"pkg-lib",
"pkg-bin",
'pkg-dev',
]

[workspace.package]
version = "0.1.0"

[package]
name = "pkg-all"
version = "0.1.0"

[dependencies]
pkg-lib = { version = "0.1.0", path = "./pkg-lib" }
subcrate-d = { workspace = true, path = "../workspace/subcrate_d" }
subcrate-e = { workspace = true, path = "../workspace/subcrate_e" }
subcrate-f = { workspace = true, path = "../workspace/subcrate_f" }

[dependencies.pkg-bin]
version = "0.1.0"
path = "./pkg-bin"

[workspace.dependencies]
subcrate-d = { version = "0.1.0", path = "./workspace/subcrate_d" }
subcrate-e = { version = "0.1.0", path = "./workspace/subcrate_e" }
subcrate-f = { version = "0.1.0", path = "./workspace/subcrate_f" }
13 changes: 10 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import {findPackages, checkPackages, sortPackages} from '../src/package'
import {githubHandle, lastCommitDate} from '../src/github'
import {semver} from '../src/utils'
import {join} from 'path'
import {exec} from '@actions/exec'
const pkg_dir = __dirname

test('find packages', async () => {
const packages = await findPackages(pkg_dir)

expect(Object.keys(packages).length).toBe(6)
expect(Object.keys(packages).length).toBe(9)

const pkg_all = packages['pkg-all']
const pkg_sys = packages['pkg-sys']
const pkg_lib = packages['pkg-lib']
const pkg_bin = packages['pkg-bin']
const subcrate_e = packages['subcrate-e']

expect(pkg_all.path).toBe(pkg_dir)
expect(pkg_all.version).toBe('0.1.0')
expect(Object.keys(pkg_all.dependencies).length).toBe(2)
expect(Object.keys(pkg_all.dependencies).length).toBe(5)

expect(pkg_sys.path).toBe(join(pkg_dir, 'pkg-sys'))
expect(pkg_sys.version).toBe('0.1.0')
Expand All @@ -31,6 +31,10 @@ test('find packages', async () => {
expect(pkg_bin.path).toBe(join(pkg_dir, 'pkg-bin'))
expect(pkg_bin.version).toBe('0.1.0')
expect(Object.keys(pkg_bin.dependencies).length).toBe(3)

expect(subcrate_e.path).toBe(join(pkg_dir, 'workspace/subcrate_e'))
expect(subcrate_e.version).toBe('0.1.0')
expect(Object.keys(subcrate_e.dependencies).length).toBe(1)
})

test('check packages', async () => {
Expand All @@ -46,6 +50,9 @@ test('sort packages', async () => {
'pkg-sys',
'pkg-lib',
'pkg-build',
'subcrate-d',
'subcrate-f',
'subcrate-e',
'pkg-dev',
'pkg-bin',
'pkg-all'
Expand Down
3 changes: 3 additions & 0 deletions __tests__/pkg-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ lazy_static = "1.0"
version = "0.1.0"
path = "../pkg-sys"

[dev-dependencies]
lazy_static = "1.0"

# test that local cyclic dev-deps are allowed using paths
[dev-dependencies.pkg-dev]
path = "../pkg-dev"
12 changes: 12 additions & 0 deletions __tests__/pkg-skip/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "pkg-skip"
version = "0.1.0"
publish = false

[dependencies]
pkg-lib = { version = "0.1.0", path = "../pkg-lib" }
clap = "^2"

[dev-dependencies.pkg-dev]
version = "0.1.0"
path = "../pkg-dev"
1 change: 1 addition & 0 deletions __tests__/pkg-skip/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
6 changes: 6 additions & 0 deletions __tests__/workspace/subcrate_d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "subcrate-d"
version = { workspace = true }

[dev-dependencies.subcrate-f]
path = "../subcrate_f"
10 changes: 10 additions & 0 deletions __tests__/workspace/subcrate_d/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub const TEST_VALUE: u8 = 5u8;

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
10 changes: 10 additions & 0 deletions __tests__/workspace/subcrate_e/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "subcrate-e"
version = { workspace = true }

[dependencies.subcrate-d]
workspace = true
path = "../subcrate_d"

[dev-dependencies.subcrate-f]
path = "../subcrate_f"
11 changes: 11 additions & 0 deletions __tests__/workspace/subcrate_e/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub use fuel_dummy_test_subcrate_d::TEST_VALUE as OTHER_TEST_VALUE;

#[cfg(test)]
mod tests {
pub use fuel_dummy_test_subcrate_f::TEST_VALUE;
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
9 changes: 9 additions & 0 deletions __tests__/workspace/subcrate_f/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "subcrate-f"
version = { workspace = true }

[dependencies]
lazy_static = "1.0"

[dev-dependencies]
lazy_static = "1.0"
10 changes: 10 additions & 0 deletions __tests__/workspace/subcrate_f/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub const TEST_VALUE: u8 = 5u8;

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
Loading

0 comments on commit 050b71d

Please sign in to comment.