Skip to content

Commit

Permalink
git plugin: provide the capability for atomic commits and tags
Browse files Browse the repository at this point in the history
before: all package updates commited to git were stored in a
single commit

after: provide an argument for the git plugin called commitstrategy.
This generates a unique commit message for each package that is
updated and additionally can perform tagged releases
  • Loading branch information
rismoney committed Nov 8, 2017
1 parent 696bf40 commit 24b3ef2
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions AU/Plugins/Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ param(
[string] $Password,

#Force git commit when package is updated but not pushed.
[switch] $Force
[switch] $Force,

[ValidateSet('single', 'atomic', 'atomictag')]
[string]$commitStrategy='single'
)

[array]$packages = if ($Force) { $Info.result.updated } else { $Info.result.pushed }
Expand Down Expand Up @@ -42,16 +45,39 @@ Write-Host "Executing git pull"
git checkout -q master
git pull -q origin master

Write-Host "Adding updated packages to git repository: $( $packages | % Name)"
$packages | % { git add -u $_.Path }
git status

Write-Host "Commiting"
$message = "AU: $($packages.Length) updated - $($packages | % Name)"
$gist_url = $Info.plugin_results.Gist -split '\n' | select -Last 1
git commit -m "$message`n[skip ci] $gist_url" --allow-empty
if ($commitStrategy -like 'atomic*') {
$packages | % {
Write-Host "Adding update package to git repository: $($_.Name)"
git add -u $_.Path
git status

Write-Host "Pushing changes"
git push -q
Write-Host "Commiting $($_.Name)"
$message = "AU: $($_.Name) upgraded from $($_.NuspecVersion) to $($_.RemoteVersion)"
$gist_url = $Info.plugin_results.Gist -split '\n' | select -Last 1
git commit -m "$message`n[skip ci] $gist_url" --allow-empty

if ($commitStrategy -eq 'atomictag') {
$tagcmd = "git tag -a $($_.Name)-$($_.RemoteVersion) -m '$($_.Name)-$($_.RemoteVersion)'"
Invoke-Expression $tagcmd
}
}
}
else {
Write-Host "Adding updated packages to git repository: $( $packages | % Name)"
$packages | % { git add -u $_.Path }
git status

Write-Host "Commiting"
$message = "AU: $($packages.Length) updated - $($packages | % Name)"
$gist_url = $Info.plugin_results.Gist -split '\n' | select -Last 1
git commit -m "$message`n[skip ci] $gist_url" --allow-empty

}
Write-Host "Pushing changes"
git push -q
if ($commitStrategy -eq 'atomictag') {
write-host 'Atomic Tag Push'
git push -q --tags
}
popd

0 comments on commit 24b3ef2

Please sign in to comment.