Skip to content

Release to Production #241

Release to Production

Release to Production #241

name: Release to Production
on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: "0 3 * * 5" # Every Friday at 3am
permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout
concurrency: # This is required to prevent multiple runs of the same workflow from running at the same time.
group: ${{ github.workflow }}
jobs:
dotnet-web-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/dotnet-web-ci@main
with:
dotnet-project: "servers-integration-webapi"
dotnet-version: 9.0.x
src-folder: "src"
majorMinorVersion: "1.1"
publish-nuget-packages:
environment: NuGet
runs-on: ubuntu-latest
needs: [dotnet-web-ci]
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/publish-nuget-packages@main
with:
artifact-name: "nuget-packages"
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
bicep-build-and-apply-dev:
environment: Development
runs-on: ubuntu-latest
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bicep-build-and-apply
with:
environmentName: dev
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
AZURE_DEPLOY_SCRIPT_IDENTITY: ${{ secrets.AZURE_DEPLOY_SCRIPT_IDENTITY }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- id: bicep-output
shell: pwsh
run: |
$config = (Get-Content params/dev.json | ConvertFrom-Json)
$deploymentOutput = (az deployment sub show --name "portal-servers-integration-$($config.parameters.environment.value)-$($config.parameters.instance.value)" `
--subscription ${{ vars.AZURE_SUBSCRIPTION_ID }}) | ConvertFrom-Json
echo "web_app_name=$($deploymentOutput.properties.outputs.webAppName.value)" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
echo "web_app_resource_group_name=rg-portal-servers-integration-$($config.parameters.environment.value)-$($config.parameters.location.value)-$($config.parameters.instance.value)" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
outputs:
web_app_name: ${{ steps.bicep-output.outputs.web_app_name }}
web_app_resource_group_name: ${{ steps.bicep-output.outputs.web_app_resource_group_name }}
app-service-deploy-dev:
environment: Development
runs-on: ubuntu-latest
needs: [dotnet-web-ci, bicep-build-and-apply-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/deploy-app-service@main
with:
web-artifact-name: "servers-integration-webapi"
web-app-name: ${{ needs.bicep-build-and-apply-dev.outputs.web_app_name }}
resource-group-name: ${{ needs.bicep-build-and-apply-dev.outputs.web_app_resource_group_name }}
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
bicep-build-and-apply-prd:
environment: Production
runs-on: ubuntu-latest
needs: [app-service-deploy-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bicep-build-and-apply
with:
environmentName: prd
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
AZURE_DEPLOY_SCRIPT_IDENTITY: ${{ secrets.AZURE_DEPLOY_SCRIPT_IDENTITY }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- id: bicep-output
shell: pwsh
run: |
$config = (Get-Content params/prd.json | ConvertFrom-Json)
$deploymentOutput = (az deployment sub show --name "portal-servers-integration-$($config.parameters.environment.value)-$($config.parameters.instance.value)" `
--subscription ${{ vars.AZURE_SUBSCRIPTION_ID }}) | ConvertFrom-Json
echo "web_app_name=$($deploymentOutput.properties.outputs.webAppName.value)" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
echo "web_app_resource_group_name=rg-portal-servers-integration-$($config.parameters.environment.value)-$($config.parameters.location.value)-$($config.parameters.instance.value)" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
outputs:
web_app_name: ${{ steps.bicep-output.outputs.web_app_name }}
web_app_resource_group_name: ${{ steps.bicep-output.outputs.web_app_resource_group_name }}
app-service-deploy-prd:
environment: Production
runs-on: ubuntu-latest
needs: [bicep-build-and-apply-prd]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/deploy-app-service@main
with:
web-artifact-name: "servers-integration-webapi"
web-app-name: ${{ needs.bicep-build-and-apply-prd.outputs.web_app_name }}
resource-group-name: ${{ needs.bicep-build-and-apply-prd.outputs.web_app_resource_group_name }}
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}