Deploy to environment #564
Workflow file for this run
This file contains hidden or 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: Deploy to environment | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| type: environment | |
| description: "Choose an environment to deploy to" | |
| required: true | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.inputs.environment }} | |
| env: | |
| IMAGE_NAME: aca-app | |
| jobs: | |
| set-env: | |
| name: Determine environment | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| environment: ${{ steps.var.outputs.environment }} | |
| release: ${{ steps.var.outputs.release }} | |
| image-name: ${{ steps.var.outputs.image-name }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
| - id: var | |
| run: | | |
| INPUT=${{ github.event.inputs.environment }} | |
| ENVIRONMENT=${INPUT:-"development"} | |
| RELEASE=${ENVIRONMENT,,}-`date +%Y-%m-%d`.${{ github.run_number }} | |
| echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT | |
| echo "release=${RELEASE}" >> $GITHUB_OUTPUT | |
| echo "image-name=${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT | |
| validate-packages: | |
| runs-on: windows-latest | |
| name: Package Validation | |
| permissions: | |
| contents: read | |
| needs: [ set-env ] | |
| steps: | |
| - name: Validate Packages | |
| uses: DFE-Digital/rsd-github-actions/.github/actions/validate-packages@5d9289aaafc5d0a591dab9d93a93be27381fc5e5 # v1.1.3 | |
| with: | |
| environment: ${{ needs.set-env.outputs.environment }} | |
| build-import: | |
| name: Build & Import | |
| runs-on: ubuntu-24.04 | |
| needs: [ set-env, validate-packages ] | |
| environment: ${{ needs.set-env.outputs.environment }} | |
| strategy: | |
| matrix: | |
| stage: [ | |
| "final", | |
| "initcontainer" | |
| ] | |
| include: | |
| - stage: "final" | |
| tag-prefix: "" | |
| - stage: "initcontainer" | |
| tag-prefix: "init-" | |
| permissions: | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| steps: | |
| - uses: DFE-Digital/deploy-azure-container-apps-action/.github/actions/build@8e72e403f05ff9da09668207eef1d79e1ce9d1a7 # v5.2.1 | |
| with: | |
| image-name: ${{ needs.set-env.outputs.image-name }} | |
| build-args: CI=true | |
| build-target: ${{ matrix.stage }} | |
| tag-prefix: ${{ matrix.tag-prefix }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: DFE-Digital/deploy-azure-container-apps-action/.github/actions/import@8e72e403f05ff9da09668207eef1d79e1ce9d1a7 # v5.2.1 | |
| with: | |
| image-name: ${{ needs.set-env.outputs.image-name }} | |
| tag-prefix: ${{ matrix.tag-prefix }} | |
| azure-acr-name: ${{ secrets.ACR_NAME }} | |
| azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
| azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| azure-acr-client-id: ${{ secrets.ACR_CLIENT_ID }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| env: | |
| AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID || '' }} | |
| AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION_ID || '' }} | |
| AZURE_ACR_CLIENT_ID: ${{ secrets.ACR_CLIENT_ID || '' }} | |
| deploy: | |
| name: Deploy to ${{ needs.set-env.outputs.environment }} | |
| needs: [ set-env, build-import ] | |
| runs-on: ubuntu-24.04 | |
| environment: ${{ needs.set-env.outputs.environment }} | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: DFE-Digital/deploy-azure-container-apps-action/.github/actions/deploy@8e72e403f05ff9da09668207eef1d79e1ce9d1a7 # v5.2.1 | |
| with: | |
| image-name: ${{ needs.set-env.outputs.image-name }} | |
| annotate-release: 'yes' | |
| azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
| azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| azure-acr-name: ${{ secrets.ACR_NAME }} | |
| azure-aca-client-id: ${{ secrets.ACA_CLIENT_ID }} | |
| azure-aca-name: ${{ secrets.ACA_CONTAINERAPP_NAME }} | |
| azure-aca-resource-group: ${{ secrets.ACA_RESOURCE_GROUP }} | |
| env: | |
| AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID || '' }} | |
| AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION_ID || '' }} | |
| AZURE_ACA_CLIENT_ID: ${{ secrets.ACA_CLIENT_ID || '' }} | |
| deploy-worker: | |
| name: Deploy to ${{ needs.set-env.outputs.environment }} | |
| needs: [ set-env, build-import ] | |
| runs-on: ubuntu-24.04 | |
| environment: ${{ needs.set-env.outputs.environment }} | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: DFE-Digital/deploy-azure-container-apps-action/.github/actions/deploy@8e72e403f05ff9da09668207eef1d79e1ce9d1a7 # v5.2.1 | |
| with: | |
| image-name: ${{ needs.set-env.outputs.image-name }} | |
| annotate-release: 'yes' | |
| azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
| azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| azure-acr-name: ${{ secrets.ACR_NAME }} | |
| azure-aca-client-id: ${{ secrets.ACA_CLIENT_ID }} | |
| azure-aca-name: ${{ secrets.ACA_CONTAINERAPP_NAME }}-worker | |
| azure-aca-resource-group: ${{ secrets.ACA_RESOURCE_GROUP }} | |
| env: | |
| AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID || '' }} | |
| AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION_ID || '' }} | |
| AZURE_ACA_CLIENT_ID: ${{ secrets.ACA_CLIENT_ID || '' }} | |
| create-tag: | |
| name: Tag and release | |
| needs: [ deploy, set-env ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Create tag | |
| run: | | |
| git tag ${{ needs.set-env.outputs.release }} | |
| git push origin ${{ needs.set-env.outputs.release }} | |
| - name: Create release | |
| uses: "actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea" # v7 | |
| with: | |
| github-token: "${{ secrets.GITHUB_TOKEN }}" | |
| script: | | |
| try { | |
| await github.rest.repos.createRelease({ | |
| draft: ${{ needs.set-env.outputs.environment == 'test' }}, | |
| generate_release_notes: true, | |
| name: "${{ needs.set-env.outputs.release }}", | |
| owner: context.repo.owner, | |
| prerelease: ${{ needs.set-env.outputs.environment == 'test' }}, | |
| repo: context.repo.repo, | |
| tag_name: "${{ needs.set-env.outputs.release }}", | |
| }); | |
| } catch (error) { | |
| core.setFailed(error.message); | |
| } | |
| cypress-tests: | |
| name: Run Cypress tests | |
| if: needs.set-env.outputs.environment == 'test' || needs.set-env.outputs.environment == 'development' | |
| needs: [ deploy, set-env ] | |
| uses: ./.github/workflows/cypress-tests.yml | |
| with: | |
| environment: ${{ needs.set-env.outputs.environment }} | |
| secrets: | |
| API_KEY: ${{ secrets.API_KEY }} | |
| URL: ${{ secrets.URL }} | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |