Added initial Pester test and limited repo clone to specific directories #25
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: Azure IPAM Testing | ||
# permissions: | ||
# id-token: write | ||
# contents: read | ||
run-name: Azure IPAM Deployment & Testing | ||
on: | ||
push: | ||
branches: [ github-actions ] | ||
pull_request: | ||
branches: [ main ] | ||
env: | ||
IPAM_UI_ID: ipam-ui-${{ github.run_id }}-${{ github.run_attempt }} | ||
IPAM_ENGINE_ID: ipam-engine-${{ github.run_id }}-${{ github.run_attempt }} | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
ipamURL: ${{ steps.pwshScript.outputs.ipamURL }} | ||
ipamUIAppId: ${{ steps.pwshScript.outputs.ipamUIAppId }} | ||
ipamEngineAppId: ${{ steps.pwshScript.outputs.ipamEngineAppId }} | ||
ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} | ||
ipamResourceGroup: ${{ steps.pwshScript.outputs.ipamResourceGroup }} | ||
steps: | ||
- run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." | ||
- name: Install Deployment Prerequisites | ||
shell: pwsh | ||
run: | | ||
Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
Install-Module Az, Microsoft.Graph -AllowClobber -Force | ||
# - name: "Azure Login" | ||
# uses: azure/login@v1 | ||
# with: | ||
# client-id: ${{ secrets.AZURE_CLIENT_ID }} | ||
# subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
# tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
# enable-AzPSSession: true | ||
- name: "Azure Login" | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
enable-AzPSSession: true | ||
- name: Checkout Azure IPAM Code | ||
uses: actions/checkout@v3 | ||
with: | ||
sparse-checkout: | | ||
deploy | ||
- name: Deploy Azure IPAM | ||
working-directory: "deploy" | ||
id: "pwshScript" | ||
shell: pwsh | ||
run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID | ||
- name: "Output PowerShell Value 'ipamSuffix'" | ||
run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" | ||
- name: "Upload Logs" | ||
working-directory: "logs" | ||
shell: pwsh | ||
run: | | ||
$dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() | ||
$archiveName = "ipam-${dateStamp}.zip" | ||
Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName | ||
$storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" | ||
$context = $storage.Context | ||
$uploadDetails = @{ | ||
File = "/tmp/$archiveName" | ||
Container = "deploy-logs" | ||
Blob = $archiveName | ||
Context = $context | ||
StandardBlobTier = "Hot" | ||
} | ||
Set-AzStorageBlobContent @uploadDetails | ||
- run: echo "${{ github.job }} status is ${{ job.status }}." | ||
sleep: | ||
runs-on: ubuntu-latest | ||
needs: deploy | ||
steps: | ||
- name: "Test Sleepy Time" | ||
run: | | ||
echo "Time: $(date +'%T')" | ||
echo "Sleeping for 30 seconds" | ||
sleep 30 | ||
echo "Time: $(date +'%T')" | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: [ deploy, sleep ] | ||
steps: | ||
- name: Install Testing Prerequisites | ||
shell: pwsh | ||
run: | | ||
Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
Install-Module Az, Pester -AllowClobber -Force | ||
- name: "Azure Login" | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
enable-AzPSSession: true | ||
- name: Checkout Azure IPAM Code | ||
uses: actions/checkout@v3 | ||
with: | ||
sparse-checkout: | | ||
tests | ||
- name: Test Azure IPAM via Pester | ||
working-directory: "tests" | ||
env: | ||
IPAM_URL: ${{ needs.deploy.outputs.ipamURL }} | ||
IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }} | ||
shell: pwsh | ||
run: | | ||
Import-Module Pester -PassThru | ||
Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
needs: [ deploy, sleep, test ] | ||
steps: | ||
- name: Install Deployment Prerequisites | ||
shell: pwsh | ||
run: | | ||
Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
Install-Module Az -AllowClobber -Force | ||
- name: "Azure Login" | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
enable-AzPSSession: true | ||
- name : "Cleanup Azure IPAM Deployment" | ||
shell: pwsh | ||
run: | | ||
Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force | ||
Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} | Remove-AzADApplication | ||
Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} | Remove-AzADApplication |