Skip to content

Commit

Permalink
Instead of manually parsing the Cargo.toml use the cargo metadata com…
Browse files Browse the repository at this point in the history
…mand. It supports { workspace = true } syntax.
  • Loading branch information
xgreenx committed Jan 11, 2023
1 parent 6c200f9 commit 037fe86
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 120 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 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`

## Unimplemented features

Expand Down
11 changes: 11 additions & 0 deletions __tests__/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ members = [
'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 @@ -45,6 +49,9 @@ test('sort packages', async () => {
expect(sorted).toEqual([
'pkg-sys',
'pkg-lib',
'subcrate-d',
'subcrate-f',
'subcrate-e',
'pkg-build',
'pkg-dev',
'pkg-bin',
Expand Down
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);
}
}
5 changes: 5 additions & 0 deletions __tests__/workspace/subcrate_f/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "subcrate-f"
version = { workspace = true }

[dependencies]
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);
}
}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@actions/glob": "^0.3.0",
"@actions/http-client": "^2.0.1",
"@iarna/toml": "^2.2.5",
"child_process": "^1.0.2",
"semver": "^7.3.7"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 037fe86

Please sign in to comment.