Skip to content

Commit 050b71d

Browse files
authored
Use cargo metadata to collect information about packages (#600)
Added support of `{ workspace = true }` syntax.
1 parent 71853c8 commit 050b71d

File tree

14 files changed

+200
-118
lines changed

14 files changed

+200
-118
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
check-repo: ${{ github.event_name == 'push' }}
4545

4646
publish: # publish dependency-free release with only self-contained dist directory
47-
if: github.repository == 'katyo/publish-crates' && github.event_name == 'push' && github.ref_name == 'main'
47+
if: github.event_name == 'push' && github.ref_name == 'main'
4848
runs-on: ubuntu-latest
4949
needs:
5050
- build

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
# Publish Rust crates using GitHub Actions
55

6+
The action is using [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html) with format version
7+
`1` to collect the information about crates and workspace.
8+
69
## Features
710

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

1722
## Unimplemented features
1823

__tests__/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
[workspace]
22
members = [
33
"pkg-sys",
4+
"pkg-skip",
45
"pkg-build",
56
"pkg-lib",
67
"pkg-bin",
78
'pkg-dev',
89
]
910

11+
[workspace.package]
12+
version = "0.1.0"
13+
1014
[package]
1115
name = "pkg-all"
1216
version = "0.1.0"
1317

1418
[dependencies]
1519
pkg-lib = { version = "0.1.0", path = "./pkg-lib" }
20+
subcrate-d = { workspace = true, path = "../workspace/subcrate_d" }
21+
subcrate-e = { workspace = true, path = "../workspace/subcrate_e" }
22+
subcrate-f = { workspace = true, path = "../workspace/subcrate_f" }
1623

1724
[dependencies.pkg-bin]
1825
version = "0.1.0"
1926
path = "./pkg-bin"
27+
28+
[workspace.dependencies]
29+
subcrate-d = { version = "0.1.0", path = "./workspace/subcrate_d" }
30+
subcrate-e = { version = "0.1.0", path = "./workspace/subcrate_e" }
31+
subcrate-f = { version = "0.1.0", path = "./workspace/subcrate_f" }

__tests__/main.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import {findPackages, checkPackages, sortPackages} from '../src/package'
33
import {githubHandle, lastCommitDate} from '../src/github'
44
import {semver} from '../src/utils'
55
import {join} from 'path'
6-
import {exec} from '@actions/exec'
76
const pkg_dir = __dirname
87

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

12-
expect(Object.keys(packages).length).toBe(6)
11+
expect(Object.keys(packages).length).toBe(9)
1312

1413
const pkg_all = packages['pkg-all']
1514
const pkg_sys = packages['pkg-sys']
1615
const pkg_lib = packages['pkg-lib']
1716
const pkg_bin = packages['pkg-bin']
17+
const subcrate_e = packages['subcrate-e']
1818

1919
expect(pkg_all.path).toBe(pkg_dir)
2020
expect(pkg_all.version).toBe('0.1.0')
21-
expect(Object.keys(pkg_all.dependencies).length).toBe(2)
21+
expect(Object.keys(pkg_all.dependencies).length).toBe(5)
2222

2323
expect(pkg_sys.path).toBe(join(pkg_dir, 'pkg-sys'))
2424
expect(pkg_sys.version).toBe('0.1.0')
@@ -31,6 +31,10 @@ test('find packages', async () => {
3131
expect(pkg_bin.path).toBe(join(pkg_dir, 'pkg-bin'))
3232
expect(pkg_bin.version).toBe('0.1.0')
3333
expect(Object.keys(pkg_bin.dependencies).length).toBe(3)
34+
35+
expect(subcrate_e.path).toBe(join(pkg_dir, 'workspace/subcrate_e'))
36+
expect(subcrate_e.version).toBe('0.1.0')
37+
expect(Object.keys(subcrate_e.dependencies).length).toBe(1)
3438
})
3539

3640
test('check packages', async () => {
@@ -46,6 +50,9 @@ test('sort packages', async () => {
4650
'pkg-sys',
4751
'pkg-lib',
4852
'pkg-build',
53+
'subcrate-d',
54+
'subcrate-f',
55+
'subcrate-e',
4956
'pkg-dev',
5057
'pkg-bin',
5158
'pkg-all'

__tests__/pkg-lib/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ lazy_static = "1.0"
99
version = "0.1.0"
1010
path = "../pkg-sys"
1111

12+
[dev-dependencies]
13+
lazy_static = "1.0"
14+
1215
# test that local cyclic dev-deps are allowed using paths
1316
[dev-dependencies.pkg-dev]
1417
path = "../pkg-dev"

__tests__/pkg-skip/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "pkg-skip"
3+
version = "0.1.0"
4+
publish = false
5+
6+
[dependencies]
7+
pkg-lib = { version = "0.1.0", path = "../pkg-lib" }
8+
clap = "^2"
9+
10+
[dev-dependencies.pkg-dev]
11+
version = "0.1.0"
12+
path = "../pkg-dev"

__tests__/pkg-skip/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "subcrate-d"
3+
version = { workspace = true }
4+
5+
[dev-dependencies.subcrate-f]
6+
path = "../subcrate_f"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub const TEST_VALUE: u8 = 5u8;
2+
3+
#[cfg(test)]
4+
mod tests {
5+
#[test]
6+
fn it_works() {
7+
let result = 2 + 2;
8+
assert_eq!(result, 4);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "subcrate-e"
3+
version = { workspace = true }
4+
5+
[dependencies.subcrate-d]
6+
workspace = true
7+
path = "../subcrate_d"
8+
9+
[dev-dependencies.subcrate-f]
10+
path = "../subcrate_f"

0 commit comments

Comments
 (0)