@Grab(group = 'com.github.zafarkhaja', module = 'java-semver', version = '0.9.0')
import com.github.zafarkhaja.semver.Version
def executeOnShell(String command, Closure closure = null) {
executeOnShell(command, new File(System.properties.'user.dir'), closure)
}
def executeOnShell(String command, File workingDir, Closure closure = null) {
println command
def processBuilder = new ProcessBuilder(['sh', '-c', command])
.directory(workingDir)
if (closure) {
processBuilder.redirectErrorStream(true)
} else {
processBuilder.inheritIO()
}
def process = processBuilder.start()
if (closure) {
process.inputStream.eachLine closure
}
process.waitFor()
if (process.exitValue() > 0) {
System.exit(process.exitValue())
}
}
void ask(String prompt, String defaultValue = 'Y', Closure cl) {
def promptValue = System.console().readLine(prompt + ' ').trim()
if (promptValue.empty) {
promptValue = defaultValue
}
if (promptValue.toUpperCase() == 'Y') {
cl.call()
}
}
executeOnShell 'git pull'
ask('Publish library to crates.io?: [Y]') {
executeOnShell 'cargo publish --allow-dirty'
}
def nextVer = Version.valueOf(releaseVer).incrementPatchVersion()
ask("Bump version to $nextVer?: [Y]") {
executeOnShell "sed -i -e 's/version = \"${releaseVer}\"/version = \"${nextVer}\"/' Cargo.toml"
executeOnShell "sed -i -e 's/documentation = \"https:\\/\\/docs\\.rs\\/pact-plugin-driver\\/${releaseVer}\\/pact-plugin-driver\\/\"/documentation = \"https:\\/\\/docs\\.rs\\/pact-plugin-driver\\/${nextVer}\\/pact-plugin-driver\\/\"/' Cargo.toml"
executeOnShell("cargo update")
executeOnShell("git add Cargo.toml")
executeOnShell("git add Cargo.lock")
executeOnShell("git diff --cached")
ask("Commit and push this change?: [Y]") {
executeOnShell("git commit -m 'chore: bump version to $nextVer [skip ci]'")
executeOnShell("git push")
}
}