Skip to content

Commit 6df9819

Browse files
committed
Fix duplicate checkout in extensions
1 parent 9858956 commit 6df9819

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

extension/BuildPhpExtension/BuildPhpExtension.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
'Add-Vs',
8282
'Get-ArgumentsFromConfig',
8383
'Get-BuildDirectory',
84+
'Get-CheckoutState',
8485
'Get-Extension',
8586
'Get-ExtensionConfig',
8687
'Get-ExtensionName',
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Function Get-CheckoutState {
2+
<#
3+
.SYNOPSIS
4+
Get whether the current directory already contains the expected repository checkout.
5+
.PARAMETER Repository
6+
Expected owner/repository name.
7+
#>
8+
[OutputType([string])]
9+
param(
10+
[Parameter(Mandatory = $false, Position=0, HelpMessage='Expected owner/repository name.')]
11+
[string] $Repository = ''
12+
)
13+
begin {
14+
}
15+
process {
16+
if([string]::IsNullOrWhiteSpace($Repository)) {
17+
$Repository = $env:GITHUB_REPOSITORY
18+
}
19+
20+
if([string]::IsNullOrWhiteSpace($Repository) -or -not(Test-Path .git)) {
21+
return $false.ToString().ToLowerInvariant()
22+
}
23+
24+
try {
25+
$originUrl = git remote get-url origin 2>$null
26+
if($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($originUrl)) {
27+
return $false.ToString().ToLowerInvariant()
28+
}
29+
30+
return ($originUrl -match "(^|[:/])$([regex]::Escape($Repository))(\.git)?$").ToString().ToLowerInvariant()
31+
} catch {
32+
return $false.ToString().ToLowerInvariant()
33+
}
34+
}
35+
end {
36+
}
37+
}

extension/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ inputs:
5858
runs:
5959
using: composite
6060
steps:
61+
- name: Check checkout state
62+
id: checkout-state
63+
shell: pwsh
64+
run: |
65+
Import-Module ${{ github.action_path }}\BuildPhpExtension -Force
66+
Add-Content -Path $env:GITHUB_OUTPUT -Value "checkout_state=$(Get-CheckoutState -Repository $env:GITHUB_REPOSITORY)" -Encoding utf8
67+
6168
- name: Checkout
69+
if: ${{ steps.checkout-state.outputs.checkout_state == 'false' }}
6270
uses: actions/checkout@v5
6371

6472
- name: Check VS components

0 commit comments

Comments
 (0)