From f9a39030d19e524f4442dbe42d866bf6a882d291 Mon Sep 17 00:00:00 2001 From: Nicolas Lykke Iversen Date: Mon, 15 Jul 2024 10:05:17 +0200 Subject: [PATCH 1/6] feat: add environment to website URL output --- .github/workflows/deploy.yml | 2 +- .github/workflows/pr-validation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ac3ad2a..ddb49b9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -84,7 +84,7 @@ jobs: deploymentMode: Complete failOnStdErr: false - name: Website URL - run: 'echo "Website URL 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' + run: 'echo "Website URL (${{ inputs.environment }}) 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' needs: [validate] deploy-application: diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 887ba52..a14537a 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -64,7 +64,7 @@ jobs: deploymentMode: Complete failOnStdErr: false - name: Website URL - run: 'echo "Website URL 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' + run: 'echo "Website URL (test) 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' deploy-application: name: Deploy application From c04d4c991606020fd7d57d23dee212be7a5a1630 Mon Sep 17 00:00:00 2001 From: Nicolas Lykke Iversen Date: Mon, 15 Jul 2024 10:10:50 +0200 Subject: [PATCH 2/6] feat: add pr-closed workflow --- .github/workflows/pr-closed | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/pr-closed diff --git a/.github/workflows/pr-closed b/.github/workflows/pr-closed new file mode 100644 index 0000000..05e68fa --- /dev/null +++ b/.github/workflows/pr-closed @@ -0,0 +1,37 @@ +name: Todo App PR Closed + +concurrency: + group: ${{ github.event.number }} + cancel-in-progress: false + +on: + pull_request: + branches: + - main + types: [closed] + +permissions: + id-token: write + contents: read + +env: + resourceGroupName: pr_${{ github.event.number }} + +jobs: + remove: + name: Remove PR resources + runs-on: ubuntu-latest + steps: + - name: Azure Login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - uses: azure/cli@v2 + name: Delete resource group + with: + inlineScript: | + az group delete \ + --name ${{ env.resourceGroupName }} \ + --yes \ No newline at end of file From 657ef8318aa8050691a8d05437246c3810d2e9f5 Mon Sep 17 00:00:00 2001 From: Nicolas Lykke Iversen Date: Mon, 15 Jul 2024 10:14:45 +0200 Subject: [PATCH 3/6] ci: add job dependencies --- .github/workflows/main.yml | 10 +++++----- .github/workflows/{pr-closed => pr-closed.yml} | 0 .github/workflows/pr-validation.yml | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) rename .github/workflows/{pr-closed => pr-closed.yml} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2be966a..ea6c7ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,14 +18,14 @@ permissions: # https://learn.microsoft.com/en-us/training/modules/manage-end-end-deployment-scenarios-using-bicep-github-actions/3-configure-applications-virtual-machines jobs: - build: - name: Build - uses: ./.github/workflows/build.yml - lint: name: Lint uses: ./.github/workflows/lint.yml + build: + name: Build + uses: ./.github/workflows/build.yml + deploy-test: name: Deploy [test] uses: ./.github/workflows/deploy.yml @@ -36,7 +36,7 @@ jobs: AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - needs: [build, lint] + needs: [lint, build] deploy-production: name: Deploy [production] diff --git a/.github/workflows/pr-closed b/.github/workflows/pr-closed.yml similarity index 100% rename from .github/workflows/pr-closed rename to .github/workflows/pr-closed.yml diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index a14537a..645fd91 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -20,14 +20,14 @@ env: # https://learn.microsoft.com/en-us/training/modules/automate-azure-infrastructure-change-reviews-using-bicep-github/6-exercise-create-ephemeral-environments-pull-requests jobs: - build: - name: Build - uses: ./.github/workflows/build.yml - lint: name: Lint uses: ./.github/workflows/lint.yml + build: + name: Build + uses: ./.github/workflows/build.yml + deploy: name: Deploy runs-on: ubuntu-latest @@ -65,6 +65,7 @@ jobs: failOnStdErr: false - name: Website URL run: 'echo "Website URL (test) 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' + needs: [lint, build] deploy-application: name: Deploy application From 5b5891822810c13213a7fc20ce61b0007f6935cf Mon Sep 17 00:00:00 2001 From: Nicolas Lykke Iversen Date: Mon, 15 Jul 2024 10:36:15 +0200 Subject: [PATCH 4/6] format: update descriptions --- .github/workflows/build.yml | 2 +- .github/workflows/deploy-app.yml | 4 ++-- .github/workflows/deploy.yml | 28 ++++++++++++++-------------- .github/workflows/lint.yml | 4 ++-- .github/workflows/main.yml | 20 ++++++++++---------- .github/workflows/pr-closed.yml | 10 +++++----- .github/workflows/pr-validation.yml | 26 +++++++++++++------------- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6cfaf55..947d2f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: workflow_call: jobs: - build-application: + build-app: name: Build application runs-on: ubuntu-latest steps: diff --git a/.github/workflows/deploy-app.yml b/.github/workflows/deploy-app.yml index b75da69..be77f95 100644 --- a/.github/workflows/deploy-app.yml +++ b/.github/workflows/deploy-app.yml @@ -18,7 +18,7 @@ on: required: true jobs: - deploy-application: + deploy-app: name: Deploy application runs-on: ubuntu-latest environment: ${{ inputs.environment }} @@ -27,7 +27,7 @@ jobs: uses: actions/download-artifact@v4 with: name: application - - name: Azure Login + - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ddb49b9..3d9d6e9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,20 +18,20 @@ on: required: true jobs: - validate: - name: Validate + validate-infra: + name: Validate infrastructure runs-on: ubuntu-latest environment: ${{ inputs.environment }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Azure Login + - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - name: Preflight validation + - name: Run preflight validation uses: azure/arm-deploy@v2 with: deploymentName: ${{ github.run_number }} @@ -55,8 +55,8 @@ jobs: failOnStdErr: false if: inputs.environment == 'production' - deploy: - name: Deploy + deploy-infra: + name: Deploy infrastructure runs-on: ubuntu-latest environment: ${{ inputs.environment }} outputs: @@ -65,13 +65,13 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Azure Login + - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - name: Deploy + - name: Deploy infrastructure uses: azure/arm-deploy@v2 id: deploy with: @@ -85,22 +85,22 @@ jobs: failOnStdErr: false - name: Website URL run: 'echo "Website URL (${{ inputs.environment }}) 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' - needs: [validate] + needs: [validate-infra] - deploy-application: + deploy-app: name: Deploy application uses: ./.github/workflows/deploy-app.yml with: environment: ${{ inputs.environment }} - appServiceAppName: ${{ needs.deploy.outputs.appServiceAppName }} + appServiceAppName: ${{ needs.deploy-infra.outputs.appServiceAppName }} secrets: AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - needs: [deploy] + needs: [deploy-infra] # smoke-test: - # name: Smoke tests + # name: Run smoke tests # runs-on: ubuntu-latest # steps: # - uses: actions/checkout@v4 @@ -113,4 +113,4 @@ jobs: # -Container $container ` # -CI # shell: pwsh - # needs: [deploy, deploy-application] + # needs: [deploy-infra, deploy-app] diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 40e03ea..0084029 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,11 +1,11 @@ -name: Lint +name: Lint infrastructure on: workflow_call: jobs: lint: - name: Lint + name: Lint infrastructure runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea6c7ee..60c8236 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,16 +18,16 @@ permissions: # https://learn.microsoft.com/en-us/training/modules/manage-end-end-deployment-scenarios-using-bicep-github-actions/3-configure-applications-virtual-machines jobs: - lint: - name: Lint + lint-infra: + name: Lint infrastructure uses: ./.github/workflows/lint.yml - build: - name: Build + build-app: + name: Build application uses: ./.github/workflows/build.yml - deploy-test: - name: Deploy [test] + deploy-infra-test: + name: Deploy infrastructure [test] uses: ./.github/workflows/deploy.yml with: environment: test @@ -36,10 +36,10 @@ jobs: AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - needs: [lint, build] + needs: [lint-infra, build-app] - deploy-production: - name: Deploy [production] + deploy-infra-prod: + name: Deploy infrastructure [prod] uses: ./.github/workflows/deploy.yml with: environment: production @@ -48,4 +48,4 @@ jobs: AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - needs: [deploy-test] + needs: [deploy-infra-test] diff --git a/.github/workflows/pr-closed.yml b/.github/workflows/pr-closed.yml index 05e68fa..bb780af 100644 --- a/.github/workflows/pr-closed.yml +++ b/.github/workflows/pr-closed.yml @@ -18,18 +18,18 @@ env: resourceGroupName: pr_${{ github.event.number }} jobs: - remove: - name: Remove PR resources + delete-infra: + name: Delete infrastructure runs-on: ubuntu-latest steps: - - name: Azure Login + - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - uses: azure/cli@v2 - name: Delete resource group + - name: Delete infrastructure + uses: azure/cli@v2 with: inlineScript: | az group delete \ diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 645fd91..5e573c9 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -20,16 +20,16 @@ env: # https://learn.microsoft.com/en-us/training/modules/automate-azure-infrastructure-change-reviews-using-bicep-github/6-exercise-create-ephemeral-environments-pull-requests jobs: - lint: - name: Lint + lint-infra: + name: Lint infrastructure uses: ./.github/workflows/lint.yml - build: - name: Build + build-app: + name: Build application uses: ./.github/workflows/build.yml - deploy: - name: Deploy + deploy-infra: + name: Deploy infrastructure runs-on: ubuntu-latest environment: test outputs: @@ -38,7 +38,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Azure Login + - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} @@ -53,10 +53,10 @@ jobs: --location ${{ env.resourceGroupLocation }} - uses: azure/arm-deploy@v2 id: deploy - name: Deploy + name: Deploy infrastructure with: deploymentName: ${{ github.run_number }} - scope: resourceGroup + scope: resourcegroup resourceGroupName: ${{ env.resourceGroupName }} template: ./deploy/main.bicep parameters: > @@ -65,16 +65,16 @@ jobs: failOnStdErr: false - name: Website URL run: 'echo "Website URL (test) 🚀: https://${{ steps.deploy.outputs.appServiceAppHostName }}" >> "${GITHUB_STEP_SUMMARY}"' - needs: [lint, build] + needs: [lint-infra, build-app] - deploy-application: + deploy-app: name: Deploy application uses: ./.github/workflows/deploy-app.yml with: environment: test - appServiceAppName: ${{ needs.deploy.outputs.appServiceAppName }} + appServiceAppName: ${{ needs.deploy-infra.outputs.appServiceAppName }} secrets: AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - needs: [deploy] \ No newline at end of file + needs: [deploy-infra] \ No newline at end of file From 738fa91ad6d9cd9a558c16dd644333cd32a16ceb Mon Sep 17 00:00:00 2001 From: Nicolas Lykke Iversen Date: Mon, 15 Jul 2024 10:39:10 +0200 Subject: [PATCH 5/6] fix: bicep file reference --- .github/workflows/lint.yml | 2 +- .github/workflows/pr-validation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0084029..7f40ebb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,6 +10,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Lint + - name: Lint infrastructure run: | az bicep build --file infra/main.bicep \ No newline at end of file diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 5e573c9..88a5740 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -58,7 +58,7 @@ jobs: deploymentName: ${{ github.run_number }} scope: resourcegroup resourceGroupName: ${{ env.resourceGroupName }} - template: ./deploy/main.bicep + template: ./infra/main.bicep parameters: > environment=test deploymentMode: Complete From d1c7c3ec9a5e426c328f7bddacc94cd8aa37a2a7 Mon Sep 17 00:00:00 2001 From: Nicolas Lykke Iversen Date: Mon, 15 Jul 2024 10:46:18 +0200 Subject: [PATCH 6/6] format: update descriptions --- .github/workflows/build.yml | 2 +- .github/workflows/lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 947d2f8..2676096 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build Application +name: Build on: workflow_call: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7f40ebb..6856976 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Lint infrastructure +name: Lint on: workflow_call: