Skip to content

Commit

Permalink
Enhance cancel workflow (#34)
Browse files Browse the repository at this point in the history
* enhance cancel workflow

* add additional filter
  • Loading branch information
jtracey93 authored Dec 29, 2022
1 parent 7242010 commit 1bba90a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion .github/workflows/cancel-subscription.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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 }}"
Expand Down Expand Up @@ -31,7 +44,8 @@ jobs:
enable-AzPSSession: true
allow-no-subscriptions: true

- name: Cancel Subscription
- name: Cancel Subscription Via PR Close
if: ${{ inputs.manualRun }} == false
id: cancel
uses: azure/powershell@v1
with:
Expand All @@ -49,3 +63,21 @@ jobs:
Update-AzSubscription -SubscriptionId "$($subToCancel.SubscriptionId)" -Action "Cancel"
azPSVersion: "latest"

- name: Cancel Subscription Via Manual Run
if: ${{ inputs.manualRun }} == true
id: cancel
uses: azure/powershell@v1
with:
inlineScript: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az.Subscription -Force
Update-AzConfig -DisplayBreakingChangeWarning $false
$subToCancel = Get-AzSubscription -SubscriptionName "sub-blzv-tests-pr-${{ 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"
azPSVersion: "latest"

0 comments on commit 1bba90a

Please sign in to comment.