Publish to Azure #18
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
name: Publish to Azure | |
on: | |
workflow_dispatch: | |
push: | |
# Run when commits are pushed to mainline branch (main or master) | |
# Set this to the mainline branch you are using | |
branches: | |
[ main ] | |
paths: | |
- 'src/services/bot/**' | |
- 'src/services/gameapis/**' | |
- 'src/services/gateway/**' | |
- 'src/services/host/**' | |
- 'src/services/live/**' | |
- 'src/services/ranking/**' | |
- 'src/services/user/**' | |
# GitHub Actions workflow to deploy to Azure using azd | |
# To configure required secrets for connecting to Azure, simply run `azd pipeline config` | |
# check support with multiple environments: https://github.com/Azure/azure-dev/issues/2373 | |
# Workaround: | |
# https://github.com/jasontaylordev/todo-aspnetcore-csharp-sqlite/blob/main/OPTIONAL_FEATURES.md | |
# Set up permissions for deploying with secretless Azure federated credentials | |
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} | |
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: Install azd | |
uses: Azure/[email protected] | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.0.x | |
# issue with azd package: nothing created | |
# - name: Package Application | |
# run: azd package --output-path ./dist/codebreaker.zip --environment NONE --no-prompt | |
# working-directory: ./ | |
# - name: Upload Artifact | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: package | |
# path: ./dist/codebreaker.zip | |
# if-no-files-found: error | |
deploy-test: | |
uses: ./.github/workflows/deploy.yml | |
secrets: inherit | |
needs: [build] | |
with: | |
AZURE_ENV_NAME: codebreakertest | |
# Set the environment variable DOTNET_ENVIRONMENT to "Staging" for all container apps in the containerapp environment | |
set-staging-environmentvariables: | |
runs-on: ubuntu-latest | |
needs: [deploy-test] | |
steps: | |
- name: Azure Login | |
uses: azure/login@v2 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS_TESTENV }} | |
- name: Update DOTNET_ENVIRONMENT for all container apps to Staging | |
uses: azure/cli@v2 | |
with: | |
azcliversion: latest | |
# Stores the container app ids in a variable | |
# Updates the DOTNET_ENVIRONMENT environment variable to Staging for all container apps in the containerapp environment | |
inlineScript: | | |
containerAppIds=$(az containerapp list -g rg-codebreakertest --query "[].id | join(' ', @[])" | tr -d '"') | |
az containerapp update --set-env-vars DOTNET_ENVIRONMENT=Staging --ids $containerAppIds --query [].id | |
deploy-prod: | |
uses: ./.github/workflows/deploy.yml | |
secrets: inherit | |
needs: [deploy-test] | |
with: | |
AZURE_ENV_NAME: codebreakerprod |