Skip to content

ci: add Azure Static Web Apps workflow file #82

ci: add Azure Static Web Apps workflow file

ci: add Azure Static Web Apps workflow file #82

Workflow file for this run

name: Azure Dev
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
env:
# set this to the name of your Azure Resource Group
AZURE_RESOURCE_GROUP_NAME: 'rg-${{ vars.AZURE_ENV_NAME }}'
# set this to the name of your Azure Static Web Apps
AZURE_STTAPP_NAME: 'sttapp-${{ vars.AZURE_ENV_NAME }}-web'
# set this to the name of your Azure App Service
AZURE_WEBAPP_NAME_DOTNET: 'appsvc-${{ vars.AZURE_ENV_NAME }}-dotnet-api'
AZURE_WEBAPP_NAME_JAVA: 'appsvc-${{ vars.AZURE_ENV_NAME }}-java-api'
AZURE_WEBAPP_NAME_PYTHON: 'appsvc-${{ vars.AZURE_ENV_NAME }}-python-api'
# set this to the name of your Azure API Management
AZURE_APIM_NAME: 'apim-${{ vars.AZURE_ENV_NAME }}'
# set this to the SDK versions to use
DOTNET_VERSION: '7.x'
JAVA_VERSION: '17'
PYTHON_VERSION: '3.x'
# set this to the OpenJDK distribution to use
DISTRIBUTION: microsoft
permissions:
contents: read
id-token: write
jobs:
build_and_deploy_aswa:
name: Build and Deploy to ASWA (Frontend)
runs-on : ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Install ASWA CLI
shell: bash
run: |
npm install -g @azure/static-web-apps-cli
- name: Update configuration
shell: pwsh
run: |
$(Get-Content -Path ./web/.env) -replace "{{BASE_URL}}", "https://${{ env.AZURE_APIM_NAME }}.azure-api.net" | `
Out-File ./web/.env -Encoding utf-8 -Force
- name: Create artifacts
shell: bash
run: |
export CI=false
swa build
- name: Login to Azure
uses: Azure/login@v1
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Get SWA token
shell: bash
run: |
swa_token=$(az staticwebapp secrets list \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_STTAPP_NAME }} \
--query "properties.apiKey" -o tsv)
echo "::add-mask::$swa_token"
echo "SWA_TOKEN=$swa_token" >> $GITHUB_ENV
- name: Deploy SWA to Azure
shell: bash
run: |
swa deploy \
-d ${{ env.SWA_TOKEN }} \
--env default
- name: Get ASWA hostname
id: sttapp
shell: bash
run: |
hostname=$(az staticwebapp show \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_STTAPP_NAME }} \
--query "defaultHostname" -o tsv)
echo "hostname=$hostname" >> $GITHUB_OUTPUT
- name: Update APIM Named Value
shell: bash
run: |
hostname=${{ steps.sttapp.outputs.hostname }}
nv=$(az apim nv update \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_APIM_NAME }} \
--named-value-id STTAPP_URL \
--value $hostname)
- name: Check APIM Product with API
id: apimcheck
shell: bash
run: |
hostname=$(echo "${{ steps.sttapp.outputs.hostname }}" | cut -d'.' -f1)
api=$(az apim product api list \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_APIM_NAME }} \
--product-id $hostname \
--query "[?name == 'GitHubIssuesSummary'].name" -o tsv)
if [ "$api" == "" ]; then
checked='false'
else
checked='true'
fi
echo "hostname=$hostname" >> $GITHUB_OUTPUT
echo "checked=$checked" >> $GITHUB_OUTPUT
- name: Update APIM Product with API
if: steps.apimcheck.outputs.checked != 'true'
shell: bash
run: |
hostname=${{ steps.apimcheck.outputs.hostname }}
api=$(az apim product api add \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_APIM_NAME }} \
--product-id $hostname \
--api-id 'GitHubIssuesSummary')
build_and_deploy_appservice:
name: Build and Deploy to App Service (Backend)
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ 'dotnet', 'java', 'python' ]
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Set up .NET version
if: matrix.platform == 'dotnet'
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up Java version
if: matrix.platform == 'java'
uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
cache: 'maven'
- name: Set up Python version
if: matrix.platform == 'python'
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Create artifacts for .NET
if: matrix.platform == 'dotnet'
shell: bash
run: |
dotnet restore issue-api && \
dotnet build issue-api -c Release && \
dotnet publish issue-api -c Release
- name: Create artifacts for Java
if: matrix.platform == 'java'
shell: bash
run: |
mvn -f chat-api/pom.xml clean install
- name: Create artifacts for Python
if: matrix.platform == 'python'
shell: bash
run: |
pushd storage-api
# python -m venv .venv
# source .venv/bin/activate
pip install -r requirements.txt
popd
- name: Login to Azure
uses: Azure/login@v1
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Deploy App to Azure - .NET
if: matrix.platform == 'dotnet'
uses: Azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME_DOTNET }}
package: issue-api/bin/Release/net7.0/publish
- name: Deploy App to Azure - JAVA
if: matrix.platform == 'java'
uses: Azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME_JAVA }}
package: chat-api/target/*.jar
- name: Deploy App to Azure - PYTHON
if: matrix.platform == 'python'
uses: Azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME_PYTHON }}
package: storage-api
- name: Update APIM settings - JAVA
if: matrix.platform == 'java'
shell: bash
run: |
nv=$(az apim nv update \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_APIM_NAME }} \
--named-value-id AOAI_TOKEN \
--value ${{ secrets.AOAI_API_KEY }})
- name: Update app settings - JAVA
if: matrix.platform == 'java'
shell: bash
run: |
appsettings_updated=$(az webapp config appsettings set \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_WEBAPP_NAME_JAVA }} \
--settings AOAI_API_ENDPOINT="${{ vars.AOAI_API_ENDPOINT }}")
# appsettings_updated=$(az webapp config appsettings set \
# -g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
# -n ${{ env.AZURE_WEBAPP_NAME_JAVA }} \
# --settings AOAI_API_VERSION="${{ vars.AOAI_API_VERSION }}")
appsettings_updated=$(az webapp config appsettings set \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_WEBAPP_NAME_JAVA }} \
--settings AOAI_API_DEPLOYMENT_ID="${{ vars.AOAI_API_DEPLOYMENT_ID }}")
appsettings_updated=$(az webapp config appsettings set \
-g ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
-n ${{ env.AZURE_WEBAPP_NAME_JAVA }} \
--settings AOAI_API_KEY="${{ secrets.AOAI_API_KEY }}")