Skip to content

Instantly share code, notes, and snippets.

@Arcanemagus
Last active June 12, 2019 18:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arcanemagus/d068e3f990ca4b38fa69a1425e3a76fd to your computer and use it in GitHub Desktop.
Save Arcanemagus/d068e3f990ca4b38fa69a1425e3a76fd to your computer and use it in GitHub Desktop.
Commit staged changes and publish to APM
Param(
[Parameter(Position=0, Mandatory)]
[String]
$version = ""
)
Function Exec
{
[CmdletBinding()]
param (
[Parameter(Position=0, Mandatory=1)]
[scriptblock]$Command,
[Parameter(Position=1, Mandatory=0)]
[string]$ErrorMessage = "Execution of command failed.`n$Command"
)
& $Command
if ($LastExitCode -ne 0) {
throw "Exec: $ErrorMessage"
}
}
Function Verify-GitStatus
{
$branch = $(Exec { git rev-parse --abbrev-ref HEAD })
If (-Not ($branch -ceq "master")) {
throw "On branch '$branch' instead of 'master'!"
}
$status = $(Exec { git status --porcelain })
If ($status) {
$matches = [regex]::matches([system.string]::join("`n", $status), '^[ ?][^ ] .+$')
foreach ($match in $matches) {
throw "File not ready for commit found:`n$match"
}
} else {
throw "No changes since last commit, please stage release files."
}
}
Verify-GitStatus
Exec { git commit --gpg-sign --message="Prepare $version release" }
Exec { git tag --sign --message="$version" "$version" }
Exec { git push --follow-tags }
Exec { apm publish --tag "$version" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment