File: resolve-asset-conflict.ps1

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (79 lines) | stat: -rw-r--r-- 2,842 bytes parent folder | download | duplicates (2)
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
#Requires -Version 6.0
#Requires -PSEdition Core

<#
.SYNOPSIS
Within an assets.json file that has in a conflicted state (specifically on asset tag), merge the two tags that are conflicting and leave the assets.json in a commitable state.

.DESCRIPTION
USAGE: resolve-asset-conflict.ps1 path/to/target_assets_json

Parses the assets.json file and determines which tags are in conflict. If there are no conflicts, the script exits.

1. Parse the tags (base and target) from conflicting assets.json.
2. Update the assets.json with the base tag, but remember the target tag.
3. merge-proxy-tags.ps1 $AssetsJson base_tag target_tag

This script requires that test-proxy or azure.sdk.tools.testproxy should be on the PATH.

.PARAMETER AssetsJson
The script uses a target assets.json to understand what tags are in conflict. This is the only required parameter.
#>

param(
  [Parameter(Position=0)]
  [string] $AssetsJson
)

. (Join-Path $PSScriptRoot ".." ".." "onboarding" "common-asset-functions.ps1")
. (Join-Path $PSScriptRoot ".." ".." ".." "scripts" "Helpers" "git-helpers.ps1")

$TestProxy = Resolve-Proxy

if (!(Test-Path $AssetsJson)) {
  Write-Error "AssetsJson file does not exist: $AssetsJson"
  exit 1
}

# normally we we would Resolve-Path the $AssetsJson, but the git show command only works with relative paths, so we'll just keep that here.
if (-not $AssetsJson.EndsWith("assets.json")) {
  Write-Error "This script can only resolve conflicts within an assets.json. The file provided is not an assets.json: $AssetsJson"
  exit 1
}

$conflictingAssets = [ConflictedFile]::new($AssetsJson)

if (-not $conflictingAssets.IsConflicted) {
  Write-Host "No conflicts found in $AssetsJson, nothing to resolve, so there is no second tag to merge. Exiting"
  exit 0
}

# this is very dumb, but will properly work!
try {
  $BaseAssets = $conflictingAssets.Left() | ConvertFrom-Json
}
catch {
  Write-Error "Failed to convert previous version to valid JSON format."
  exit 1
}

try {
  $TargetAssets = $conflictingAssets.Right() | ConvertFrom-Json
}
catch {
  Write-Error "Failed to convert target assets.json version to valid JSON format."
  exit 1
}

Write-Host "Replacing conflicted assets.json with base branch version." -ForegroundColor Green
Set-Content -Path $AssetsJson -Value $conflictingAssets.Left()

$ScriptPath = Join-Path $PSScriptRoot ".." "tag-merge" "merge-proxy-tags.ps1"
& $ScriptPath $AssetsJson $BaseAssets.Tag $TargetAssets.Tag

if ($lastexitcode -eq 0) {
   Write-Host "Successfully auto-merged assets tag '$($TargetASsets.Tag)' into tag '$($BaseAssets.Tag)'. Invoke 'test-proxy push -a $AssetsJson' and commit the resulting assets.json!" -ForegroundColor Green
}
else {
  Write-Host "Conflicts were discovered, resolve the conflicts and invoke the `"merge-proxy-tags.ps1`" as recommended in the line directly above."
}