Skip to content

Commit

Permalink
Merge branch 'build-script'
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianLondon committed Sep 8, 2024
2 parents d8739dd + 9d4cd57 commit ab3fbc9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
keywords = ["fixed", "column", "serialization", "parse", "file"]
categories = ["encoding", "parsing"]
readme = "README.md"
documentation = "https://crates.io/crates/fixcol"
publish = true

[workspace]
Expand Down
61 changes: 60 additions & 1 deletion build.nu
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,69 @@ def "main docs" [] {
}
}

def "main test" [] {
def tests [] {
cargo +nightly docs-rs
cargo test --workspace -- --include-ignored
cargo test --workspace --features experimental-write -- --include-ignored
}

def "main test" [] {
tests
}

def "main deploy" [] {
# Confirm version consistency between all sub-crates
let $ws_versions = cargo metadata --format-version 1 | from json | get workspace_members | each {|m| split row '#' | last }
let $version = $ws_versions.0
# assert every element of $ws_versions is equal to $version
if ($ws_versions | any {|v| $v != $version}) {
print 'Conflicting versions of crates to deploy.'
exit 1
}

# assert current version is not published
let $published_versions = http get https://crates.io/api/v1/crates/fixcol | get versions.num
if ($published_versions | any { |v| $v == $version }) {
print $'Version ($version) has already been released on crates.io.'
exit 1
}

# assert current version is mentioned in the change log
if (open CHANGELOG.md | lines | where $it =~ $version | is-empty) {
print $'Version ($version) is not present in CHANGELOG. Please update.'
exit 1
}

# assert that fixcol is referencing the current version of fixcol-derive
let $derive_version = cargo metadata --format-version 1 | from json |
get packages | where $it.name == 'fixcol' | get dependencies.0 |
where $it.name == 'fixcol-derive' | get req.0
if (($derive_version | str substring 1..-1) != $version) {
print $'Fixcol depends on version $(derive_version) of fixcol-derive but ($version) is current.'
exit 1
}

# Run the full suite of tests - equivalent to `./build.nu test`
tests

# Add the version tag to the current commit
if (git -P tag --points-at HEAD | lines | any { |t| $t == $'v($version)' }) == false {
# confirm tag does not exist and create it
let $tagged_versions = git -P tag -l 'v*' | lines | each { |t| str substring 1..-1 }
if ($tagged_versions | any { |t| $t == $version}) {
print $'A git tag for version ($version) already exists.'
exit 1
}

git tag $'v($version)'
git push origin --tags
}

# Publish fixcol-derive then fixcol
cd fixcol-derive
cargo publish
cd -
cargo publish
}

def main [] {}

0 comments on commit ab3fbc9

Please sign in to comment.