-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
checkAndPush.ps1
77 lines (65 loc) · 2.15 KB
/
checkAndPush.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<#
.SYNOPSIS
Update manifest, commit and push.
.DESCRIPTION
Use as vscode task:
1. Open manifest in editor
1. Press CTRL+SHIFT+B or CTRL+F9 (IntelliJ)
1. Be surprised
.PARAMETER Manifest
Full Path to manifest. (vscode ${file})
.PARAMETER Force
Force parameter will be passed to checkver.
.PARAMETER Hashes
checkhashes.ps1 script will be executed instead of checkver.ps1
#>
param(
[Alias('App')]
[String[]] $Manifest,
[Alias('ForceUpdate')]
[Switch] $Force,
[Switch] $Hashes
)
begin {
. "$PSScriptRoot\Helpers.ps1"
if ($Force) { $arg = '-ForceUpdate' } else { $arg = '-Update' }
}
process {
foreach ($man in $Manifest) {
# TODO: Yaml
# if (-not ($man.EndsWith('.yml'))) {
# $man += '.yml'
# }
if (-not ($man.EndsWith('.json'))) {
$man += '.json'
}
$man = Resolve-Path $man
$folder = Split-Path $man -Parent
$file = Split-Path $man -Leaf
$noExt = ($file -split '\.')[0]
$cmd = 'checkver'
if ($Force) { scoop cache rm $noExt }
if ($Hashes) { $cmd = 'checkhashes' }
Invoke-Expression -Command "$PSScriptRoot\$cmd.ps1 '$noExt' '$folder' $arg"
$updated = @(git status -s)
if (($updated -match "$noExt").Count -gt 0) {
# TODO: Yaml
# $manifest = Get-Content $man -Raw -Encoding UTF8 | ConvertFrom-Yaml -Ordered
[psobject] $manifest = Get-Content $man -Raw -Encoding UTF8 | ConvertFrom-Json
$message = "$noExt`: Bumped to $($manifest.version)"
if ($Hashes) { $message = "${noExt}: Fixed hashes" }
Write-Host 'Commiting' -ForegroundColor Green
git commit --message $message --only "*$file"
$exit = $LASTEXITCODE
if ($exit -gt 0) {
Write-Host 'Pre-commit hook failed.' -ForegroundColor Red
exit $exit
}
Write-Host 'Pushing' -ForegroundColor Green
git push
Write-Host 'DONE' -ForegroundColor Yellow
} else {
Write-Host 'No Changes' -ForegroundColor Yellow
}
}
}