Continuous Delivery w/ Composite Actions #39
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
# yaml-language-server: https://json.schemastore.org/github-workflow.json | |
# Continuous Delivery Example (requires manual intervention to deploy to each environment) | |
# Use environments to require manual approvals between jobs | |
# Environments require public repositories or private repositories on GitHub with Enterprise plans | |
name: 'Continuous Delivery w/ Composite Actions' | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
deploymentSlotName: stage | |
location: eastus | |
templateFile: './infra/main.bicep' | |
jobs: | |
# Build Application | |
Build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it | |
- uses: actions/checkout@v3 | |
- name: 'Build Steps Here' | |
run: echo 'Running build steps...' | |
- name: 'Validate Bicep templates' | |
run: az bicep build -f ./infra/main.bicep | |
# Publish the artifacts so they are available by subsequent jobs | |
# Uploading ARM templates to build artifact | |
- name: 'Upload ARM Templates as Artifact' | |
continue-on-error: false | |
uses: actions/upload-artifact@v3 | |
with: | |
name: infra | |
path: infra | |
# Publish the artifacts so they are available by subsequent jobs | |
# Uploading application to build artifact | |
- name: 'Upload Application Build as Artifact' | |
continue-on-error: false | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build | |
path: src | |
# Write to the Summary Log | |
- name: 'Write to the Summary Log' | |
run: | | |
echo '# Build' >> $GITHUB_STEP_SUMMARY | |
echo '### Infrastructure' >> $GITHUB_STEP_SUMMARY | |
echo ':white_check_mark: Add to publish artifact' >> $GITHUB_STEP_SUMMARY | |
echo '### Application' >> $GITHUB_STEP_SUMMARY | |
echo ':white_check_mark: Build source code' >> $GITHUB_STEP_SUMMARY | |
echo ':white_check_mark: Unit tests' >> $GITHUB_STEP_SUMMARY | |
echo ':white_check_mark: Add to publish artifact' >> $GITHUB_STEP_SUMMARY | |
# Deploy to the Development servers | |
DeployDev: | |
name: Development | |
if: github.event_name == 'pull_request' | |
needs: Build | |
runs-on: ubuntu-latest | |
environment: | |
name: Development | |
url: 'https://${{ steps.deploy.outputs.webAppName }}.azurewebsites.net' | |
steps: | |
# Deploy Infrastructure and WebApp | |
- id: deploy | |
uses: msfred/deploy-infra-webapp@main | |
with: | |
azureClientId: ${{ vars.AZURE_CLIENT_ID }} | |
azureSubscriptionId: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
azureTenantId: ${{ vars.AZURE_TENANT_ID }} | |
environmentId: dev | |
location: ${{ env.location }} | |
parametersFile: './infra/main.dev.parameters.json' | |
templateFile: ${{ env.templateFile }} | |
# Deploy to the QA servers | |
DeployQA: | |
name: QA | |
if: github.event.ref == 'refs/heads/main' | |
needs: Build | |
runs-on: ubuntu-latest | |
environment: | |
name: QA | |
url: 'https://${{ steps.deploy.outputs.webAppName }}.azurewebsites.net' | |
steps: | |
# Deploy Infrastructure and WebApp | |
- id: deploy | |
uses: msfred/deploy-infra-webapp@main | |
with: | |
azureClientId: ${{ vars.AZURE_CLIENT_ID }} | |
azureSubscriptionId: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
azureTenantId: ${{ vars.AZURE_TENANT_ID }} | |
environmentId: qa | |
location: ${{ env.location }} | |
parametersFile: './infra/main.qa.parameters.json' | |
templateFile: ${{ env.templateFile }} | |
# Deploy to the Staging servers | |
DeployStage: | |
name: Stage | |
needs: DeployQA | |
runs-on: ubuntu-latest | |
environment: | |
name: Stage | |
url: 'https://${{ steps.deploy.outputs.webAppName }}-${{ env.deploymentSlotName }}.azurewebsites.net' | |
outputs: | |
resourceGroupName: ${{ steps.deploy.outputs.resourceGroupName }} | |
webAppName: ${{ steps.deploy.outputs.webAppName }} | |
steps: | |
# Deploy Infrastructure and WebApp | |
- id: deploy | |
uses: msfred/deploy-infra-webapp@main | |
with: | |
azureClientId: ${{ vars.AZURE_CLIENT_ID }} | |
azureSubscriptionId: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
azureTenantId: ${{ vars.AZURE_TENANT_ID }} | |
deploymentSlotName: ${{ env.deploymentSlotName }} | |
environmentId: prod | |
location: ${{ env.location }} | |
parametersFile: './infra/main.prod.parameters.json' | |
templateFile: ${{ env.templateFile }} | |
# Deploy to the Production servers | |
DeployProduction: | |
name: Production | |
needs: DeployStage | |
runs-on: ubuntu-latest | |
environment: | |
name: Production | |
url: 'https://${{ needs.DeployStage.outputs.webAppName }}.azurewebsites.net' | |
steps: | |
- name: 'Deploy to Production' | |
run: echo 'Deploy Application to Production' | |
# Log in to Azure | |
- uses: azure/login@v1 | |
with: | |
client-id: ${{ vars.AZURE_CLIENT_ID }} | |
tenant-id: ${{ vars.AZURE_TENANT_ID }} | |
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
# Azure CLI command for WebApp Deployment Slot swapping | |
# https://docs.microsoft.com/en-us/cli/azure/webapp/deployment/slot?view=azure-cli-latest | |
- uses: azure/cli@v1 | |
with: | |
inlineScript: | | |
az webapp deployment slot swap -g ${{ needs.DeployStage.outputs.resourceGroupName }} -n ${{ needs.DeployStage.outputs.webAppName }} -s ${{ env.deploymentSlotName }} |