Last active
June 12, 2019 18:35
-
-
Save Arcanemagus/d068e3f990ca4b38fa69a1425e3a76fd to your computer and use it in GitHub Desktop.
Commit staged changes and publish to APM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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