Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UpdateBuildTools.ps1 « scripts - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f2e4ad3c50e78efffffac8b6dab960f62887ce1 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env pwsh

<#
.SYNOPSIS
    Updates the build tools version and generates a commit message with the list of changes
.PARAMETER RepoRoot
    The directory containing the repo
.PARAMETER GitAuthorName
    The author name to use in the commit message. (Optional)
.PARAMETER GitAuthorEmail
    The author email to use in the commit message. (Optional)
.PARAMETER GitCommitArgs
    Additional arguments to pass into git-commit
.PARAMETER NoCommit
    Make changes without executing git-commit
.PARAMETER Force
    Specified this to make a commit with any changes
#>
[cmdletbinding(SupportsShouldProcess = $true)]
param(
    [string]$RepoRoot,
    [string]$GitAuthorName = $null,
    [string]$GitAuthorEmail = $null,
    [string[]]$GitCommitArgs = @(),
    [switch]$NoCommit,
    [switch]$Force
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 2

if (-not $RepoRoot) {
    $RepoRoot = Resolve-Path "$PSScriptRoot\.."
}

Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force

function Get-KoreBuildVersion {
    $lockFile = "$RepoRoot/korebuild-lock.txt"
    if (!(Test-Path $lockFile)) {
        return ''
    }
    $version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
    if (!$version) {
        Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'"
    }
    $version = $version.TrimStart('version:').Trim()
    return $version
}

Push-Location $RepoRoot
try {
    Assert-Git

    $oldVersion = Get-KoreBuildVersion

    # Executes a command that no-ops. The only thing we really need is the updated version of korebuild-lock.txt
    & "$RepoRoot/build.ps1" -Update '-t:Noop' | Out-Null

    $newVersion = Get-KoreBuildVersion

    if ($oldVersion -eq $newVersion) {
        Write-Host -ForegroundColor Magenta 'No changes to build tools'
        exit 0
    }

    Invoke-Block { git add "$RepoRoot/korebuild-lock.txt" }
    Invoke-Block { git add "$RepoRoot/build/dependencies.props" }

    $shortMessage = "Updating BuildTools from $oldVersion to $newVersion"
    # add this to the commit message to make it possible to filter commit triggers based on message
    $message = "$shortMessage`n`n[auto-updated: buildtools]"

    if (-not $NoCommit -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Create a new commit with these changes?')))) {

        $gitConfigArgs = @()
        if ($GitAuthorName) {
            $gitConfigArgs += '-c', "user.name=$GitAuthorName"
        }

        if ($GitAuthorEmail) {
            $gitConfigArgs += '-c', "user.email=$GitAuthorEmail"
        }

        Invoke-Block { git @gitConfigArgs commit -m $message @GitCommitArgs }
    }
    else {
        # If composing this script with others, return the message that would have been used
        return @{
            message = $message
        }
    }
}
finally {
    Pop-Location
}