summaryrefslogtreecommitdiff
path: root/Tools/VersionTools.targets
blob: 574b1d9064e5241ac9f76042f1662a49a32590d6 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <UsingTask TaskName="LocalUpdatePublishedVersions" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
  <UsingTask TaskName="ReadGitConfigFile" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
  <UsingTask TaskName="SubmitPullRequest" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
  <UsingTask TaskName="UpdateDependencies" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
  <UsingTask TaskName="UpdatePublishedVersions" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
  <UsingTask TaskName="UpdateToRemoteDependencies" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
  <UsingTask TaskName="VerifyDependencies" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />

  <PropertyGroup>
    <!-- Cache of build info files retrieved from versions repository. -->
    <BuildInfoCacheDir>$(ToolsDir)BuildInfoCache/</BuildInfoCacheDir>
  </PropertyGroup>

  <ItemGroup Condition="'$(ShippedNuGetPackageGlobPath)'!=''">
    <ShippedNuGetPackage Include="$(ShippedNuGetPackageGlobPath)" />
  </ItemGroup>

  <ItemGroup Condition="'$(NotifyGitHubUsers)'!=''">
    <NotifyGitHubUsers Include="$(NotifyGitHubUsers)" />
  </ItemGroup>

  <Target Name="CreateDefaultDependencyInfos"
          DependsOnTargets="CreateDefaultSubmoduleUpdateSteps">
    <ItemGroup>
      <!-- For backward compatibility, Include XmlUpdateSteps as Xml-type updaters. -->
      <UpdateStep Include="@(XmlUpdateStep)">
        <UpdaterType>Xml</UpdaterType>
      </UpdateStep>

      <!-- For backward compatibility, create DependencyInfos for DependencyBuildInfos. -->
      <DependencyInfo Include="@(DependencyBuildInfo)">
        <DependencyType>Build</DependencyType>
      </DependencyInfo>

      <!--
        For submodule updaters with no matching custom DependencyInfo, create default ones.
        The metadata names match up.
      -->
      <DependencyInfo Include="@(UpdateStep)"
                      Condition="'%(UpdateStep.UpdaterType)' == 'Submodule from latest'">
        <DependencyType>Submodule</DependencyType>
      </DependencyInfo>
    </ItemGroup>
  </Target>

  <!--
    Read a .gitmodules file and generate updaters based on the contents, if GitModulesPath provided.
    
    If a submodule has 'branch = ...' configured with a target remote branch to update to and
    'versionToolsAutoUpdate = true', this target creates an updater for it.
    
    To restrict this target to only create updaters for a specific submodule, set the
    'TargetSubmodule' property to the name/path of the submodule.
  -->
  <Target Name="CreateDefaultSubmoduleUpdateSteps"
          Condition="'$(CreateDefaultSubmoduleUpdateSteps)' == 'true'">
    <ReadGitConfigFile File="$(GitModulesPath)">
      <Output TaskParameter="SubmoduleConfiguration" ItemName="SubmoduleConfiguration" />
    </ReadGitConfigFile>

    <ItemGroup>
      <_UpgradableSubmodule Include="@(SubmoduleConfiguration)"
                            Condition="'%(SubmoduleConfiguration.Branch)' != '' AND
                                       '%(SubmoduleConfiguration.VersionToolsAutoUpdate)' != 'false'" />

      <_NotTargetSubmodule Include="@(_UpgradableSubmodule)"
                           Exclude="$(TargetSubmodule)"
                           Condition="'$(TargetSubmodule)' != ''"/>

      <SubmoduleToUpdate Include="@(_UpgradableSubmodule)"
                         Exclude="@(_NotTargetSubmodule)" />
    </ItemGroup>

    <!--
      Notify the user if TargetSubmodule is invalid, but allow the build to continue if there are no
      upgradable submodules at all.
    -->
    <Error Text="No upgradable submodule '$(TargetSubmodule)' found. Options: @(_UpgradableSubmodule)"
           Condition="'@(SubmoduleToUpdate)' == '' AND '$(TargetSubmodule)' != ''" />

    <ItemGroup>
      <UpdateStep Include="@(SubmoduleToUpdate)">
        <UpdaterType>Submodule from latest</UpdaterType>
        <Path>$(ProjectDir)%(Path)</Path>
        <Ref>refs/heads/%(Branch)</Ref>
        <Repository>%(Url)</Repository>
      </UpdateStep>
    </ItemGroup>
  </Target>

  <Target Name="UpdatePublishedVersions">
    <UpdatePublishedVersions ShippedNuGetPackage="@(ShippedNuGetPackage)"
                             VersionsRepoPath="$(VersionsRepoPath)"
                             GitHubAuthToken="$(GitHubAuthToken)"
                             GitHubUser="$(GitHubUser)"
                             GitHubEmail="$(GitHubEmail)"
                             VersionsRepo="$(VersionsRepo)"
                             VersionsRepoOwner="$(VersionsRepoOwner)" />
  </Target>

  <Target Name="LocalUpdatePublishedVersions">
    <LocalUpdatePublishedVersions ShippedNuGetPackage="@(ShippedNuGetPackage)"
                                  VersionsRepoLocalBaseDir="$(VersionsRepoLocalBaseDir)"
                                  VersionsRepoPath="$(VersionsRepoPath)" />
  </Target>

  <Target Name="UpdateDependencies"
          DependsOnTargets="CreateDefaultDependencyInfos">
    <UpdateDependencies DependencyInfo="@(DependencyInfo)"
                        ProjectJsonFiles="@(ProjectJsonFiles)"
                        UpdateStep="@(UpdateStep)"
                        BuildInfoCacheDir="$(BuildInfoCacheDir)"
                        GitHubAuthToken="$(GitHubAuthToken)"
                        GitHubUser="$(GitHubUser)" />
  </Target>

  <Target Name="VerifyDependencies"
          DependsOnTargets="CreateDefaultDependencyInfos"
          Condition="'$(SkipVerifyPackageVersions)'!='true'">
    <!-- Add message so it's clear what's happening when building with verbosity:minimal. For example, "sync -p". -->
    <Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Verifying all auto-upgradeable dependencies..." />

    <VerifyDependencies DependencyInfo="@(DependencyInfo)"
                        ProjectJsonFiles="@(ProjectJsonFiles)"
                        UpdateStep="@(UpdateStep)"
                        BuildInfoCacheDir="$(BuildInfoCacheDir)" />

    <Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Verifying all auto-upgradeable dependencies... Done." />
  </Target>

  <!--
    Update to the latest dependencies available remotely. A "UpdateDependencies" call uses the local
    source of truth, but this looks up the latest truth on the remote. For example, this uses the
    latest dotnet/versions remote commit for build-infos, and it uses the project's GitHub
    repository to find the latest commit for a submodule.

    If using the remote causes any updates, the local source of truth is modified to match it.
  -->
  <Target Name="UpdateToRemoteDependencies"
          DependsOnTargets="CreateDefaultDependencyInfos">
    <UpdateToRemoteDependencies DependencyInfo="@(DependencyInfo)"
                                ProjectJsonFiles="@(ProjectJsonFiles)"
                                UpdateStep="@(UpdateStep)"
                                CurrentRefXmlPath="$(CurrentRefXmlPath)"
                                GitHubAuthToken="$(GitHubAuthToken)"
                                GitHubUser="$(GitHubUser)">
      <Output TaskParameter="MadeChanges" PropertyName="MadeChanges"/>
      <Output TaskParameter="SuggestedCommitMessage" PropertyName="CommitMessage"/>
    </UpdateToRemoteDependencies>
  </Target>

  <Target Name="SubmitPullRequestIfChanged"
          Condition="'$(MadeChanges)' == 'true'">
    <PropertyGroup>
      <PullRequestServiceType Condition="'$(PullRequestServiceType)' == ''">GitHub</PullRequestServiceType>
      <MaintainersCanModifyPullRequest Condition="'$(MaintainersCanModifyPullRequest)' == ''">true</MaintainersCanModifyPullRequest>
      <TrackDiscardedCommits Condition="'$(TrackDiscardedCommits)' == ''">true</TrackDiscardedCommits>
    </PropertyGroup>

    <!-- If GitHub service, set up backward-compatible properties. -->
    <PropertyGroup Condition="'$(PullRequestServiceType)' == 'GitHub'">
      <PullRequestAuthToken Condition="'$(PullRequestAuthToken)' == ''">$(GitHubAuthToken)</PullRequestAuthToken>
      <PullRequestUser Condition="'$(PullRequestUser)' == ''">$(GitHubUser)</PullRequestUser>
      <PullRequestAuthor Condition="'$(PullRequestAuthor)' == ''">$(GitHubAuthor)</PullRequestAuthor>
      <PullRequestEmail Condition="'$(PullRequestEmail)' == ''">$(GitHubEmail)</PullRequestEmail>
    </PropertyGroup>

    <SubmitPullRequest PullRequestServiceType="$(PullRequestServiceType)"
                       PullRequestAuthToken="$(PullRequestAuthToken)"
                       PullRequestUser="$(PullRequestUser)"
                       PullRequestAuthor="$(PullRequestAuthor)"
                       PullRequestEmail="$(PullRequestEmail)"
                       VstsInstanceName="$(VstsInstanceName)"
                       VstsApiVersionOverride="$(VstsApiVersionOverride)"
                       ProjectRepoOwner="$(ProjectRepoOwner)"
                       ProjectRepoName="$(ProjectRepoName)"
                       ProjectRepoBranch="$(ProjectRepoBranch)"
                       CommitMessage="$(CommitMessage)"
                       Title="$(PullRequestTitle)"
                       Body="$(PullRequestBody)"
                       NotifyGitHubUsers="@(NotifyGitHubUsers)"
                       AlwaysCreateNewPullRequest="$(AlwaysCreateNewPullRequest)"
                       MaintainersCanModifyPullRequest="$(MaintainersCanModifyPullRequest)"
                       TrackDiscardedCommits="$(TrackDiscardedCommits)" />
  </Target>

  <!-- Create a git-like alias for UpdateToRemoteDependencies. -->
  <Target Name="PullSubmodules" DependsOnTargets="UpdateToRemoteDependencies" />

  <!--
    Calls both targets needed to produce an auto-upgrade pull request (to the remote state).

    The name would more accurately be 'UpdateToRemoteDependenciesAndSubmitPullRequest'. The
    incorrect current name is preserved for backward compatibility, and predates
    'UpdateToRemoteDependencies'. It's recommended to call msbuild with targets
    'UpdateToRemoteDependencies;SubmitPullRequestIfChanged' when adding a new auto-PR usage so the
    target names are clearer.
  -->
  <Target Name="UpdateDependenciesAndSubmitPullRequest">
    <Message Importance="High" Text="Calling targets 'UpdateToRemoteDependencies;SubmitPullRequestIfChanged'" />
    <CallTarget Targets="UpdateToRemoteDependencies;SubmitPullRequestIfChanged" />
  </Target>
</Project>