Skip to content

Commit

Permalink
Enter repo root (#32169)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkb7 authored Dec 13, 2024
1 parent 37fbbc8 commit 786bce8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tasks/winbuildscripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ function Exit-BuildRoot() {
Pop-Location -StackName AgentBuildRoot
}

<#
.SYNOPSIS
Sets the current directory to the root of the repository.
#>
function Enter-RepoRoot() {
# Expected PSScriptRoot: datadog-agent\tasks\winbuildscripts\
Push-Location "$PSScriptRoot\..\.." -ErrorAction Stop -StackName AgentRepoRoot | Out-Null
}

<#
.SYNOPSIS
Leaves the repository root directory and returns to the original working directory.
#>
function Exit-RepoRoot() {
Pop-Location -StackName AgentRepoRoot
}

<#
.SYNOPSIS
Expands the Go module cache from an archive file.
Expand Down Expand Up @@ -209,6 +226,8 @@ function Invoke-BuildScript {

if ($BuildOutOfSource) {
Enter-BuildRoot
} else {
Enter-RepoRoot
}

Expand-ModCache -modcache modcache
Expand All @@ -234,9 +253,11 @@ function Invoke-BuildScript {
# This finally block is executed regardless of whether the try block completes successfully, throws an exception,
# or uses `exit` to terminate the script.

# Restore the original working directory
if ($BuildOutOfSource) {
# Restore the original working directory
Exit-BuildRoot
} else {
Exit-RepoRoot
}
}
}

0 comments on commit 786bce8

Please sign in to comment.