|
| 1 | +name: Deploy to Azure with azd |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - cruft/update |
| 9 | + |
| 10 | +# GitHub Actions workflow to deploy to Azure using azd |
| 11 | +# To configure required secrets for connecting to Azure, simply run `azd pipeline config` |
| 12 | + |
| 13 | +# Set up permissions for deploying with secretless Azure federated credentials |
| 14 | +# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication |
| 15 | +permissions: |
| 16 | + id-token: write |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + uri: ${{ steps.output.outputs.uri }} |
| 24 | + env: |
| 25 | + AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} |
| 26 | + AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} |
| 27 | + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} |
| 28 | + AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }} |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v3 |
| 32 | + |
| 33 | + - name: Install azd |
| 34 | + |
| 35 | + |
| 36 | + - name: Log in with Azure (Federated Credentials) |
| 37 | + if: ${{ env.AZURE_CLIENT_ID != '' }} |
| 38 | + run: | |
| 39 | + azd auth login ` |
| 40 | + --client-id "$Env:AZURE_CLIENT_ID" ` |
| 41 | + --federated-credential-provider "github" ` |
| 42 | + --tenant-id "$Env:AZURE_TENANT_ID" |
| 43 | + shell: pwsh |
| 44 | + |
| 45 | + - name: Log in with Azure (Client Credentials) |
| 46 | + if: ${{ env.AZURE_CREDENTIALS != '' }} |
| 47 | + run: | |
| 48 | + $info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable; |
| 49 | + Write-Host "::add-mask::$($info.clientSecret)" |
| 50 | +
|
| 51 | + azd auth login ` |
| 52 | + --client-id "$($info.clientId)" ` |
| 53 | + --client-secret "$($info.clientSecret)" ` |
| 54 | + --tenant-id "$($info.tenantId)" |
| 55 | + shell: pwsh |
| 56 | + env: |
| 57 | + AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }} |
| 58 | + |
| 59 | + - name: Provision Infrastructure |
| 60 | + run: azd provision --no-prompt |
| 61 | + env: |
| 62 | + AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} |
| 63 | + AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} |
| 64 | + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} |
| 65 | + |
| 66 | + - name: Deploy Application |
| 67 | + run: azd deploy --no-prompt |
| 68 | + env: |
| 69 | + AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} |
| 70 | + AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} |
| 71 | + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} |
| 72 | + |
| 73 | + - name: Output Deployment URI |
| 74 | + id: output |
| 75 | + run: | |
| 76 | + azd env get-values > .env |
| 77 | + source .env |
| 78 | + echo "uri=$BACKEND_URI" >> "$GITHUB_OUTPUT" |
| 79 | +
|
| 80 | + smoketests: |
| 81 | + runs-on: ubuntu-latest |
| 82 | + needs: build |
| 83 | + steps: |
| 84 | + |
| 85 | + - name: Basic smoke test (curl) |
| 86 | + env: |
| 87 | + URI: ${{needs.build.outputs.uri}} |
| 88 | + run: | |
| 89 | + echo "Sleeping 1 minute due to https://github.com/Azure/azure-dev/issues/2669" |
| 90 | + sleep 60 |
| 91 | + curl -sSf $URI |
| 92 | + - name: Checkout |
| 93 | + uses: actions/checkout@v3 |
| 94 | + |
| 95 | + - name: Setup python |
| 96 | + uses: actions/setup-python@v4 |
| 97 | + with: |
| 98 | + python-version: 3.12 |
| 99 | + |
| 100 | + - name: End-to-end smoke tests (playwright) |
| 101 | + env: |
| 102 | + URI: ${{needs.build.outputs.uri}} |
| 103 | + run: | |
| 104 | + python3 -m pip install --upgrade pip |
| 105 | + python3 -m pip install -r requirements-dev.txt |
| 106 | + python3 -m playwright install chromium --with-deps |
| 107 | + python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI |
0 commit comments