|
| 1 | +name: Deploy Backend Integration to Azure |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - 'backend-integration/**' |
| 10 | + |
| 11 | +# GitHub Actions workflow to deploy to Azure using azd |
| 12 | +# To configure required secrets for connecting to Azure, simply run `azd pipeline config` |
| 13 | + |
| 14 | +# Set up permissions for deploying with secretless Azure federated credentials |
| 15 | +# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication |
| 16 | +permissions: |
| 17 | + id-token: write |
| 18 | + contents: read |
| 19 | + |
| 20 | +# Use concurrency to ensure that only a single job or workflow using the same concurrency group will run at a time |
| 21 | +concurrency: |
| 22 | + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' |
| 23 | + cancel-in-progress: true # Cancel previously queued jobs and run the latest |
| 24 | + |
| 25 | + |
| 26 | +jobs: |
| 27 | + self-hosted-status: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 5 |
| 30 | + outputs: |
| 31 | + runner-status: ${{ steps.runnerstatus.outputs.status }} |
| 32 | + steps: |
| 33 | + - name: Check runner status |
| 34 | + id: runnerstatus |
| 35 | + uses: SatelCreative/[email protected] |
| 36 | + with: |
| 37 | + github-runner-token: ${{ secrets.SELF_HOSTED_RUNNER_TOKEN }} #Should have access to manage runner |
| 38 | + org-name: SatelCreative |
| 39 | + build: |
| 40 | + needs: [self-hosted-status] |
| 41 | + timeout-minutes: 10 |
| 42 | + runs-on: ${{ contains(needs.self-hosted-status.outputs.runner-status, 'online') && 'self-hosted' || 'ubuntu-latest' }} |
| 43 | + environment: dev |
| 44 | + env: |
| 45 | + AZURE_CLIENT_ID: ${{ vars.BACKEND_INTEGRATION_CLIENT_ID }} |
| 46 | + AZURE_TENANT_ID: ${{ vars.BACKEND_INTEGRATION_TENANT_ID }} |
| 47 | + AZURE_SUBSCRIPTION_ID: ${{ vars.BACKEND_INTEGRATION_SUBSCRIPTION_ID }} |
| 48 | + AZURE_CREDENTIALS: ${{ secrets.BACKEND_INTEGRATION_CREDENTIALS }} |
| 49 | + steps: |
| 50 | + - name: Checkout |
| 51 | + uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Install azd |
| 54 | + |
| 55 | + |
| 56 | + - name: Log in with Azure (Federated Credentials) |
| 57 | + if: ${{ env.AZURE_CLIENT_ID != '' }} |
| 58 | + run: | |
| 59 | + azd auth login \ |
| 60 | + --client-id "$AZURE_CLIENT_ID" \ |
| 61 | + --federated-credential-provider "github" \ |
| 62 | + --tenant-id "$AZURE_TENANT_ID" |
| 63 | +
|
| 64 | +
|
| 65 | + - name: Log in with Azure (Client Credentials) |
| 66 | + if: ${{ env.AZURE_CREDENTIALS != '' }} |
| 67 | + run: | |
| 68 | + $info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable; |
| 69 | + Write-Host "::add-mask::$($info.clientSecret)" |
| 70 | +
|
| 71 | + azd auth login \ |
| 72 | + --client-id "$($info.clientId)" \ |
| 73 | + --client-secret "$($info.clientSecret)" \ |
| 74 | + --tenant-id "$($info.tenantId)" |
| 75 | +
|
| 76 | + env: |
| 77 | + AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }} |
| 78 | + |
| 79 | + # Commented out to preserve existing application settings |
| 80 | + # Uncomment when infrastructure changes are needed |
| 81 | + #- name: Provision Infrastructure |
| 82 | + # run: | |
| 83 | + # cd backend-integration |
| 84 | + # azd provision --no-prompt |
| 85 | + # env: |
| 86 | + # AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} |
| 87 | + # AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} |
| 88 | + # AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} |
| 89 | + |
| 90 | + - name: Deploy Application |
| 91 | + run: |
| 92 | + | |
| 93 | + cd backend-integration |
| 94 | + azd deploy --no-prompt |
| 95 | + env: |
| 96 | + AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} |
| 97 | + AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} |
| 98 | + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} |
| 99 | + |
0 commit comments