Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add installation of ALZ Powershell module for policy scripts #679

Merged
merged 9 commits into from
Nov 20, 2023
13 changes: 9 additions & 4 deletions .github/scripts/Invoke-PolicyToBicep-China.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ param (
[string]
$rootPath = "./infra-as-code/bicep/modules/policy",
[string]
$alzToolsPath = "$PWD/../Enterprise-Scale/src/Alz.Tools",
[string]
$definitionsRoot = "definitions",
[string]
$lineEnding = "unix",
Expand Down Expand Up @@ -43,8 +41,15 @@ param (
)

# This script relies on a custom set of classes and functions
# defined within the Alz.Tools PowerShell module.
Import-Module $alzToolsPath -ErrorAction Stop
# defined within the [ALZ-PowerShell-Module](https://github.com/Azure/Alz-powershell-module).
if (-not (Get-Module -ListAvailable -Name ALZ)) {
# Module doesn't exist, so install it
Write-Information "====> ALZ module isn't already installed. Installing..." -InformationAction Continue
Install-Module -Name ALZ -Force -Scope CurrentUser -ErrorAction Stop
Write-Information "====> ALZ module now installed." -InformationAction Continue
} else {
Write-Information "====> ALZ module is already installed." -InformationAction Continue
}

# Line Endings function to be used in three functions below
function Update-FileLineEndingType {
Expand Down
11 changes: 11 additions & 0 deletions .github/scripts/Invoke-PolicyToBicep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ param (
$assignmentsTxtFileName = "_policyAssignmentsBicepInput.txt"
)

# This script relies on a custom set of classes and functions
# defined within the [ALZ-PowerShell-Module](https://github.com/Azure/Alz-powershell-module).
if (-not (Get-Module -ListAvailable -Name ALZ)) {
# Module doesn't exist, so install it
Write-Information "====> ALZ module isn't already installed. Installing..." -InformationAction Continue
Install-Module -Name ALZ -Force -Scope CurrentUser -ErrorAction Stop
Write-Information "====> ALZ module now installed." -InformationAction Continue
} else {
Write-Information "====> ALZ module is already installed." -InformationAction Continue
}

# Line Endings function to be used in three functions below
function Update-FileLineEndingType {
[CmdletBinding(SupportsShouldProcess)]
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/update-policy-china.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@ jobs:
-Reset
azPSVersion: "latest"

- name: Install ALZ PowerShell Module
shell: pwsh
run: |
Install-Module -Name 'ALZ' -Force

- name: Update Policy Definition Bicep Input Files
uses: azure/powershell@v1
with:
inlineScript: |
cd ${{ github.workspace }}/${{ github.repository }}
Write-Information "==> Running script..." -InformationAction Continue
.github/scripts/Invoke-PolicyToBicep-China.ps1 `
-alzToolsPath "${{ github.workspace }}/${{ env.remote_repository }}/src/Alz.Tools/"
.github/scripts/Invoke-PolicyToBicep-China.ps1
azPSVersion: "latest"

- name: Check for changes
Expand Down
Loading