Test workflow - IGNORE #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cancel Subscription on PR Close | |
on: | |
pull_request: | |
types: | |
- closed | |
paths: | |
- "**.bicep" | |
- "tests/pester/**.ps1" | |
workflow_dispatch: | |
inputs: | |
manualRun: | |
description: "Manually Run" | |
required: false | |
default: false | |
type: boolean | |
subName: | |
description: "Subscription Name to Cancel" | |
required: false | |
env: | |
ARM_TENANT_ID: "${{ secrets.ARM_TENANT_ID }}" | |
ARM_CLIENT_ID: "${{ secrets.ARM_CLIENT_ID }}" | |
ARM_CLIENT_SECRET: "${{ secrets.ARM_CLIENT_SECRET }}" | |
GH_PR_NUMBER: "${{ github.event.number }}" | |
jobs: | |
vending: | |
name: Vending Subscription for Tests and Networking Scenarios | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repo | |
id: checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Azure Login | |
id: login | |
uses: azure/login@v1 | |
with: | |
creds: '{"clientId":"${{ env.ARM_CLIENT_ID }}","clientSecret":"${{ env.ARM_CLIENT_SECRET }}","tenantId":"${{ env.ARM_TENANT_ID }}"}' | |
enable-AzPSSession: true | |
allow-no-subscriptions: true | |
- name: Cancel Subscription Via PR Close | |
if: ${{ inputs.manualRun == false }} | |
id: cancel-pr | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
Install-Module Az.Subscription -Force | |
Install-Module Az.Resources -Force | |
Install-Module Az.Accounts -Force | |
Update-AzConfig -DisplayBreakingChangeWarning $false | |
$subToCancel = Get-AzSubscription -SubscriptionName "sub-blzv-tests-pr-${{ env.GH_PR_NUMBER }}" | |
Write-Host "Subscription to Cancel: $($subToCancel.SubscriptionId)" -ForegroundColor Cyan | |
Write-Host "" | |
Write-Host "Moving Subscription to Management Group: bicep-lz-vending-automation-decom..." -ForegroundColor Yellow | |
New-AzManagementGroupSubscription -GroupName "bicep-lz-vending-automation-decom" -SubscriptionId "$($subToCancel.SubscriptionId)" | |
Write-Host "" | |
Write-Host "Cancelling Subscription..." -ForegroundColor Yellow | |
Update-AzSubscription -SubscriptionId "$($subToCancel.SubscriptionId)" -Action "Cancel" | |
- name: Cancel Subscription Via Manual Run | |
if: ${{ inputs.manualRun == true }} | |
id: cancel-manual | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
Install-Module Az.Subscription -Force | |
Install-Module Az.Resources -Force | |
Install-Module Az.Accounts -Force | |
Update-AzConfig -DisplayBreakingChangeWarning $false | |
$subToCancel = Get-AzSubscription -SubscriptionName "${{ github.event.inputs.subName }}" | |
Write-Host "Subscription to Cancel: $($subToCancel.SubscriptionId)" -ForegroundColor Cyan | |
Write-Host "" | |
Write-Host "Moving Subscription to Management Group: bicep-lz-vending-automation-decom..." -ForegroundColor Yellow | |
New-AzManagementGroupSubscription -GroupName "bicep-lz-vending-automation-decom" -SubscriptionId "$($subToCancel.SubscriptionId)" | |
Write-Host "" | |
Write-Host "Cancelling Subscription..." -ForegroundColor Yellow | |
Update-AzSubscription -SubscriptionId "$($subToCancel.SubscriptionId)" -Action "Cancel" |