Skip to content

Commit

Permalink
Update resource group name in workflow and script
Browse files Browse the repository at this point in the history
  • Loading branch information
nenad0707 committed Mar 19, 2024
1 parent 69e0ac6 commit 67a397e
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 78 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy Application
on:
workflow_call:
inputs:
resourceGroupName:
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true

jobs:
deploy:
runs-on: ubuntu-latest
environment: Azure
outputs:
appServiceDefaultHostName: ${{ steps.deploy.outputs.appServiceDefaultHostName }}
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: Sign in to Azure
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
id: deploy
name: Deploy azure resources
with:
failOnStdErr: false
deploymentName: ${{ github.run_number }}
resourceGroupName: ${{ inputs.resourceGroupName }}
template: main.bicep
parameters: main.parameters.json
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: lint

on:
workflow_call:

jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Lint code
run: |
az bicep build --file main.bicep
35 changes: 35 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Preview Deployment
on:
workflow_call:
inputs:
resourceGroupName:
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: Sign in to Azure
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
name: Run what-if
with:
scope: resourcegroup
failOnStdErr: false
resourceGroupName: ${{ inputs.resourceGroupName }}
template: main.bicep
parameters: main.parameters.json
additionalArguments: --what-if
22 changes: 22 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Smoke Test Application
on:
workflow_call:
inputs:
appServiceDefaultHostName:
required: true
type: string

jobs:
smoke-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
$container = New-PesterContainer `
-Path 'deploy/Website.Tests.ps1' `
-Data @{ HostName = '${{ inputs.appServiceDefaultHostName }}' }
Invoke-Pester `
-Container $container `
-CI
name: Run smoke tests
shell: pwsh
34 changes: 34 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Validate Deployment
on:
workflow_call:
inputs:
resourceGroupName:
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: Sign in to Azure
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
name: Run preflight validation
with:
deploymentName: ${{ github.run_number }}
resourceGroupName: ${{ inputs.resourceGroupName }}
template: main.bicep
parameters: main.parameters.json
deploymentMode: Validate
106 changes: 30 additions & 76 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,48 @@ on:
push:
branches:
- main
workflow_dispatch:

permissions:
id-token: write
contents: read

env:
AZURE_RESOURCEGROUP_NAME: rg_sb_eastus_89803_1_171079247255
AZURE_RESOURCEGROUP_NAME: rg_sb_eastus_89803_1_171088057588

jobs:
# Lint the Bicep file.
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Bicep linter
run: az bicep build --file main.bicep
uses: ./.github/workflows/lint.yml

validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: Sign in to Azure
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
name: Run preflight validation
with:
deploymentName: ${{ github.run_number }}
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }}
template: main.bicep
parameters: main.parameters.json
deploymentMode: Validate
needs: lint
uses: ./.github/workflows/validate.yml
with:
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME}}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

preview:
runs-on: ubuntu-latest
needs: [lint, validate]
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: Sign in to Azure
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
name: Run what-if
with:
scope: resourcegroup
failOnStdErr: false
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }}
template: main.bicep
parameters: main.parameters.json
additionalArguments: --what-if
needs: validate
uses: ./.github/workflows/preview.yml
with:
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ env.AZURE_SUBSCRIPTION_ID }}

deploy:
runs-on: ubuntu-latest
environment: Azure
needs: preview
outputs:
appServiceDefaultHostName: ${{ steps.deploy.outputs.appServiceDefaultHostName }}
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: Sign in to Azure
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
id: deploy
name: Deploy website
with:
failOnStdErr: false
deploymentName: ${{ github.run_number }}
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }}
template: main.bicep
parameters: main.parameters.json
uses: ./.github/workflows/deploy.yml
with:
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ env.AZURE_SUBSCRIPTION_ID }}

smoke-test:
runs-on: ubuntu-latest
needs: deploy
steps:
- uses: actions/checkout@v3
- run: |
$container = New-PesterContainer `
-Path 'scripts/Website.Tests.ps1' `
-Data @{ HostName = '${{needs.deploy.outputs.appServiceDefaultHostName}}' }
Invoke-Pester `
-Container $container `
-CI `
name: Run smoke tests
shell: pwsh
uses: ./.github/workflows/smoke-test.yml
with:
appServiceDefaultHostName: ${{ needs.deploy.outputs.appServiceDefaultHostName }}
4 changes: 2 additions & 2 deletions scripts/azureScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $context = Get-AzSubscription -SubscriptionName PAYG-Sandboxes
Set-AzContext $context

# Set the default resource group
Set-AzDefault -ResourceGroupName rg_sb_eastus_89803_1_171079247255
Set-AzDefault -ResourceGroupName rg_sb_eastus_89803_1_171088057588
##change resourse group name

# Set the GitHub organization and repository names
Expand All @@ -37,7 +37,7 @@ New-AzADAppFederatedCredential `
-Subject "repo:$($githubOrganizationName)/$($githubRepositoryName):ref:refs/heads/main"

# Get the resource group
$resourceGroup = Get-AzResourceGroup -Name rg_sb_eastus_89803_1_171079247255
$resourceGroup = Get-AzResourceGroup -Name rg_sb_eastus_89803_1_171088057588


# Create a new Azure AD service principal
Expand Down

0 comments on commit 67a397e

Please sign in to comment.