|
1 | | -# Variables for first repository |
2 | | -$repoUrl1 = 'https://github.com/Azure/azure-functions-java-additions.git' |
3 | | -$branchName1 = 'dev' |
4 | | -$repoName1 = 'azure-functions-java-additions' |
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [string]$AdditionsRepoUrl = 'https://github.com/Azure/azure-functions-java-additions.git', |
| 4 | + [string]$AdditionsBranch = 'dev' |
| 5 | +) |
5 | 6 |
|
6 | | -# Clone the first repository |
7 | | -git clone $repoUrl1 |
| 7 | +$ErrorActionPreference = 'Stop' |
8 | 8 |
|
9 | | -# Change directory to the cloned repository |
10 | | -Set-Location $repoName1 |
| 9 | +$repoName = 'azure-functions-java-additions' |
| 10 | +$workerRoot = $PSScriptRoot |
| 11 | +$cloneDir = Join-Path $workerRoot $repoName |
| 12 | +$mvnBuildScript = Join-Path $workerRoot 'mvnBuildAdditions.bat' |
11 | 13 |
|
12 | | -# Checkout the desired branch |
13 | | -git checkout $branchName1 |
| 14 | +Write-Host "Installing $repoName from $AdditionsRepoUrl (branch: $AdditionsBranch)" |
| 15 | +Write-Host "Clone destination: $cloneDir" |
14 | 16 |
|
15 | | -# Detect OS and execute build accordingly |
16 | | -if ($IsWindows) { |
17 | | - # Run the batch script (mvnBuild.bat) |
18 | | - & "..\mvnBuildAdditions.bat" |
19 | | -} else { |
20 | | - # Extract and explicitly invoke the mvn command from mvnBuild.bat |
21 | | - $mvnCommand = Get-Content "../mvnBuildAdditions.bat" | Where-Object { $_ -match '^mvn\s+' } |
22 | | - if ($null -ne $mvnCommand) { |
23 | | - # Execute the extracted mvn command explicitly as a single line |
24 | | - bash -c "$mvnCommand" |
25 | | - } else { |
26 | | - Write-Error "No mvn command found in mvnBuild.bat." |
| 17 | +# Make the clone idempotent for re-runs. |
| 18 | +if (Test-Path $cloneDir) { |
| 19 | + Write-Host "Removing existing $cloneDir" |
| 20 | + Remove-Item -Path $cloneDir -Recurse -Force |
| 21 | +} |
| 22 | + |
| 23 | +Push-Location $workerRoot |
| 24 | +try { |
| 25 | + git clone --branch $AdditionsBranch --single-branch $AdditionsRepoUrl |
| 26 | + if ($LASTEXITCODE -ne 0) { throw "git clone failed for $AdditionsRepoUrl ($AdditionsBranch)" } |
| 27 | + |
| 28 | + Push-Location $repoName |
| 29 | + try { |
| 30 | + if ($IsWindows) { |
| 31 | + # Run the batch script (mvnBuildAdditions.bat) |
| 32 | + & $mvnBuildScript |
| 33 | + if ($LASTEXITCODE -ne 0) { throw "mvnBuildAdditions.bat failed" } |
| 34 | + } else { |
| 35 | + # Extract and explicitly invoke the mvn command from mvnBuildAdditions.bat |
| 36 | + $mvnCommand = Get-Content $mvnBuildScript | Where-Object { $_ -match '^mvn\s+' } |
| 37 | + if ($null -ne $mvnCommand) { |
| 38 | + # Execute the extracted mvn command explicitly as a single line |
| 39 | + bash -c "$mvnCommand" |
| 40 | + if ($LASTEXITCODE -ne 0) { throw "mvn command failed" } |
| 41 | + } else { |
| 42 | + throw "No mvn command found in $mvnBuildScript" |
| 43 | + } |
| 44 | + } |
| 45 | + } finally { |
| 46 | + Pop-Location |
27 | 47 | } |
| 48 | +} finally { |
| 49 | + Pop-Location |
28 | 50 | } |
0 commit comments