Skip to content

Commit

Permalink
Merge pull request #9059 from Azure/arm-ttk-slash-command
Browse files Browse the repository at this point in the history
Arm-ttk slash command and customization
  • Loading branch information
v-amolpatil authored Sep 22, 2023
2 parents 5d2b0c5 + a560a74 commit 55e1d81
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 48 deletions.
51 changes: 3 additions & 48 deletions .github/workflows/arm-ttk-validations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,9 @@ jobs:
id: step1
name: Identify Changes in PR
run: |
$diff = git diff --diff-filter=d --name-only HEAD^ HEAD
Write-Host "List of files in PR: $diff"
$hasmainTemplateChanged = $false
$hasCreateUiDefinitionTemplateChanged = $false
$isChangeInSolutionsFolder = [bool]($diff | Where-Object {$_ -like 'Solutions/*'})
if (!$isChangeInSolutionsFolder)
{
Write-Host "Skipping as change is not in Solutions folder!"
exit 0
}
$requiredFiles = @("mainTemplate.json", "createUiDefinition.json")
$filteredFiles = $diff | Where-Object {$_ -match ($requiredFiles -Join "|")}
Write-Host "Filtered Files $filteredFiles"
if ($filteredFiles.Count -gt 0)
{
$mainTemplateValue = $filteredFiles -match "mainTemplate.json"
$createUiValue = $filteredFiles -match "createUiDefinition.json"
if ($mainTemplateValue)
{
$hasmainTemplateChanged = $true
}
if ($createUiValue)
{
$hasCreateUiDefinitionTemplateChanged = $true
}
if ($filteredFiles.Count -eq 1)
{
$packageIndex = $filteredFiles.IndexOf("/Package")
$sName = $filteredFiles.SubString(10, $packageIndex - 10)
}
else
{
$packageIndex = $filteredFiles[0].IndexOf("/Package")
$sName = $filteredFiles[0].SubString(10, $packageIndex - 10)
}
Write-Host "SolutionName: $sName"
}
Write-Output "::set-output name=solutionName::$sName"
Write-Output "::set-output name=mainTemplateChanged::$hasmainTemplateChanged"
Write-Output "::set-output name=createUiChanged::$hasCreateUiDefinitionTemplateChanged"
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module powershell-yaml
./.script/package-automation/arm-ttk-tests.ps1
- uses: docker/build-push-action@v2
id: publishGithubPackage
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/slash-command-armttk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# THIS WORKFLOW WILL RUN WHEN WE ADD SLASH COMMAND LIKE '/arm-ttk', '/ARM-TTK', '/Arm-Ttk', 'armttk' or 'ARMTTK'
name: Slash Command ARM-TTK Tests

on:
issue_comment:
types: [created, edited]

jobs:
run-arm-ttk:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork && github.event.issue.pull_request && contains(fromJson('["/armttk", "/Armttk", "/ARM-TTK", "/ARMTTK", "/arm-ttk", "/ArmTtk"]'), github.event.comment.body) }}
outputs:
solutionName: ${{ steps.step1.outputs.solutionName }}
mainTemplateChanged: ${{ steps.step1.outputs.mainTemplateChanged }}
createUiChanged: ${{ steps.step1.outputs.createUiChanged }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 5
ref: refs/pull/${{ github.event.issue.number }}/head
- shell: pwsh
id: step1
name: Identify Changes in PR
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module powershell-yaml
./.script/package-automation/arm-ttk-tests.ps1
- uses: docker/build-push-action@v2
id: publishGithubPackage
name: Run ARM-TTK
if: ${{ success() && steps.step1.outcome == 'success' && steps.step1.outputs.solutionName != '' && (steps.step1.outputs.mainTemplateChanged == 'true' || steps.step1.outputs.createUiChanged == 'true') }}
env:
SolutionName: ${{ steps.step1.outputs.solutionName }}
mainTemplateChanged: ${{ steps.step1.outputs.mainTemplateChanged }}
createUiChanged: ${{ steps.step1.outputs.createUiChanged }}
with:
context: .
file: ./.github/actions/Dockerfile
push: false
build-args: |
SolutionName
mainTemplateChanged
createUiChanged
57 changes: 57 additions & 0 deletions .script/package-automation/arm-ttk-tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

try {
$diff = git diff --diff-filter=d --name-only HEAD^ HEAD
Write-Host "List of files in PR: $diff"

$hasmainTemplateChanged = $false
$hasCreateUiDefinitionTemplateChanged = $false

$isChangeInSolutionsFolder = [bool]($diff | Where-Object {$_ -like 'Solutions/*'})
if (!$isChangeInSolutionsFolder)
{
Write-Host "Skipping as change is not in Solutions folder!"
exit 0
}

$requiredFiles = @("mainTemplate.json", "createUiDefinition.json")
$filteredFiles = $diff | Where-Object {$_ -match ($requiredFiles -Join "|")}
Write-Host "Filtered Files $filteredFiles"

$sName = ''
$hasmainTemplateChanged = $false
$hasCreateUiDefinitionTemplateChanged = $false

if ($filteredFiles.Count -gt 0)
{
$mainTemplateValue = $filteredFiles -match "mainTemplate.json"
$createUiValue = $filteredFiles -match "createUiDefinition.json"

if ($mainTemplateValue -or $createUiValue)
{
$hasmainTemplateChanged = $true
$hasCreateUiDefinitionTemplateChanged = $true
}

if ($filteredFiles.Count -eq 1)
{
$packageIndex = $filteredFiles.IndexOf("/Package")
$sName = $filteredFiles.SubString(10, $packageIndex - 10)
}
else
{
$packageIndex = $filteredFiles[0].IndexOf("/Package")
$sName = $filteredFiles[0].SubString(10, $packageIndex - 10)
}
}

Write-Host "solutionName $sName, mainTemplateChanged $hasmainTemplateChanged, createUiChanged $hasCreateUiDefinitionTemplateChanged"
Write-Output "solutionName=$sName" >> $env:GITHUB_OUTPUT
Write-Output "mainTemplateChanged=$hasmainTemplateChanged" >> $env:GITHUB_OUTPUT
Write-Output "createUiChanged=$hasCreateUiDefinitionTemplateChanged" >> $env:GITHUB_OUTPUT
}
catch {
Write-Host "Skipping as exception has occured Error Details: $_"
Write-Output "solutionName=''" >> $env:GITHUB_OUTPUT
Write-Output "mainTemplateChanged=$false" >> $env:GITHUB_OUTPUT
Write-Output "createUiChanged=$false" >> $env:GITHUB_OUTPUT
}

0 comments on commit 55e1d81

Please sign in to comment.