Skip to content

Commit

Permalink
Auto detect and add extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kairu-ms committed Nov 12, 2024
1 parent 7f9bc29 commit a0fec21
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .githooks/pre-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ $mergeBase = git merge-base HEAD upstream/main
# get the current branch name
$currentBranch = git branch --show-current

# detect all extension folder names changed under src/
$changedFiles = git diff --name-only $mergeBase $currentBranch
$changedExtensions = $changedFiles |
Where-Object { $_ -like "src/*" } |
ForEach-Object {
$parts = $_ -split '/'
if ($parts.Length -gt 1) { $parts[1] }
} |
Select-Object -Unique

if ($changedExtensions) {
Write-Host "Changed extensions: $($changedExtensions -join ', ')" -ForegroundColor Green

# Add each changed extension using azdev extension add
foreach ($extension in $changedExtensions) {
Write-Host "Adding extension: $extension"
azdev extension add $extension
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to add extension $extension" -ForegroundColor Red
exit 1
}
}
}

# Run command azdev lint
Write-Host "Running azdev lint..." -ForegroundColor Green
azdev linter --repo ./ --src $currentBranch --tgt $mergeBase
Expand Down
19 changes: 19 additions & 0 deletions .githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ MERGE_BASE=$(git merge-base HEAD upstream/main)
# get the current branch name
currentBranch=$(git branch --show-current)

# Detect changed extensions
printf "\033[0;32mDetecting changed extensions...\033[0m\n"
changedFiles=$(git diff --name-only $MERGE_BASE $currentBranch)
changedExtensions=$(echo "$changedFiles" | grep "^src/" | cut -d'/' -f2 | sort -u)

if [ ! -z "$changedExtensions" ]; then
printf "\033[0;32mChanged extensions: %s\033[0m\n" "$(echo $changedExtensions | tr '\n' ', ')"

# Add each changed extension using azdev extension add
for extension in $changedExtensions; do
printf "\033[0;32mAdding extension: %s\033[0m\n" "$extension"
azdev extension add "$extension"
if [ $? -ne 0 ]; then
printf "\033[0;31mError: Failed to add extension %s\033[0m\n" "$extension"
exit 1
fi
done
fi

# Run command azdev lint
printf "\033[0;32mRunning azdev lint...\033[0m\n"
azdev linter --repo ./ --src $currentBranch --tgt $MERGE_BASE
Expand Down

0 comments on commit a0fec21

Please sign in to comment.