Skip to content

Commit e121b44

Browse files
committed
Add prod GitHub Actions for Function App and SWA deploy
Added workflows for production deployment: - func-deploy-prod.yml: Builds and deploys .NET Azure Function App using OIDC and managed identity on main branch changes. - swa-deploy-prod.yml: Builds and deploys .NET Static Web App, including config copy, using deployment token on main branch changes.
1 parent e67c75b commit e121b44

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Function App - PROD - Build and Deploy (OIDC)
2+
3+
# CONFIGURATION
4+
#
5+
# This workflow can be used to deploy your .NET project to a function app on any hosting plan, except for Container Apps (which uses functions-container-action).
6+
#
7+
# For an overview of using GitHub workflows with Azure Functions, see https://learn.microsoft.com/azure/azure-functions/functions-how-to-github-actions
8+
#
9+
# 1. Configure a federated identity credential to your GitHub branch on an Azure user-assigned managed identity.
10+
# For instructions, follow the README at https://github.com/Azure/functions-action#use-oidc-recommended
11+
#
12+
# 2. Add the following values from the managed identity to your repo's variables:
13+
# AZURE_CLIENT_ID
14+
# AZURE_TENANT_ID
15+
# AZURE_SUBSCRIPTION_ID
16+
# For instructions on creating repo variables, see https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#defining-configuration-variables-for-multiple-workflows
17+
#
18+
# 3. Ensure your workflow is triggered by your desired event. By default, it is triggered when a push is made to main, and it can be manually run.
19+
# For guidance on event triggers, see https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow#using-events-to-trigger-workflows
20+
21+
on:
22+
push:
23+
branches: [ main ]
24+
paths:
25+
- MW-GC.EventManager.API/**
26+
- MW-GC.EventManager.Shared/**
27+
workflow_dispatch:
28+
29+
env:
30+
AZURE_FUNCTIONAPP_NAME: ${{ vars.FUNCTION_APP_NAME }}
31+
AZURE_FUNCTIONAPP_PROJECT_PATH: ${{ vars.FUNCTION_PROJECT_NAME }}
32+
DOTNET_VERSION: '10.0.x'
33+
BUILD_ARTIFACT_NAME: ${{ vars.FUNCTION_PROJECT_NAME }}
34+
35+
jobs:
36+
build:
37+
runs-on: ubuntu-latest # Assumes your target function app is Linux-based
38+
permissions:
39+
id-token: write # Required for OIDC
40+
contents: read # Required for actions/checkout
41+
defaults:
42+
run:
43+
shell: bash
44+
working-directory: ${{ env.AZURE_FUNCTIONAPP_PROJECT_PATH }}
45+
steps:
46+
- name: 'Checkout repository'
47+
uses: actions/checkout@v6
48+
49+
- name: 'Set up .NET version: ${{ env.DOTNET_VERSION }}'
50+
uses: actions/setup-dotnet@v5
51+
with:
52+
dotnet-version: ${{ env.DOTNET_VERSION }}
53+
54+
# Perform additional steps such as running tests, if needed
55+
56+
- name: 'Build and prepare .NET project for deployment'
57+
run: dotnet publish --configuration Release --output ./output
58+
59+
- name: Upload artifact for the deployment job
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: ${{ env.BUILD_ARTIFACT_NAME }}
63+
path: ${{ env.AZURE_FUNCTIONAPP_PROJECT_PATH }}/output
64+
include-hidden-files: true # Required for .NET projects
65+
66+
deploy:
67+
environment:
68+
name: func-prod
69+
url: https://mwgeventmanager.azurewebsites.net
70+
runs-on: ubuntu-latest # Assumes your target function app is Linux-based
71+
needs: build
72+
permissions:
73+
id-token: write # Required for OIDC
74+
steps:
75+
- name: 'Download artifact from build job'
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: ${{ env.BUILD_ARTIFACT_NAME }}
79+
path: ./downloaded-artifact
80+
81+
- name: 'Log in to Azure with AZ CLI'
82+
uses: azure/login@v2
83+
with:
84+
client-id: ${{ vars.AZURE_CLIENT_ID }}
85+
tenant-id: ${{ vars.AZURE_TENANT_ID }}
86+
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
87+
88+
- name: 'Run the Azure Functions action'
89+
uses: Azure/functions-action@v1
90+
id: deploy-to-function-app
91+
with:
92+
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
93+
package: ./downloaded-artifact
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Static Web App - PROD - Build and Deploy (Token)
2+
permissions:
3+
contents: read
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
- MW-GC.EventManager.Web/**
11+
- MW-GC.EventManager.Shared/**
12+
13+
jobs:
14+
build_and_deploy_job:
15+
runs-on: ubuntu-latest
16+
environment:
17+
name: swa-prod
18+
url: https://polite-ocean-0555a8a0f.7.azurestaticapps.net
19+
name: Build and Deploy Job
20+
steps:
21+
- uses: actions/checkout@v6
22+
with:
23+
submodules: true
24+
lfs: false
25+
26+
- name: Setup .NET 10.0
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: 10.0.x
30+
31+
- name: Install Workloads
32+
run: dotnet workload restore
33+
34+
- name: Restore
35+
run: dotnet restore
36+
37+
- name: .NET Publish
38+
run: dotnet publish ${{ vars.SWA_PROJECT_NAME }} -c Release -o ${{ vars.SWA_PROJECT_NAME }}/publish -p:VersionSuffix=prod
39+
40+
- name: Copy staticwebapp.config.json to Publish Folder
41+
run: cp ${{ vars.SWA_PROJECT_NAME }}/staticwebapp.config.json ${{ vars.SWA_PROJECT_NAME }}/publish/wwwroot/staticwebapp.config.json
42+
43+
- name: Build And Deploy (Prod)
44+
id: builddeploy_prod
45+
uses: Azure/static-web-apps-deploy@v1
46+
with:
47+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
48+
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
49+
action: "upload"
50+
app_location: "${{ vars.SWA_PROJECT_NAME }}/publish/wwwroot"
51+
skip_api_build: true
52+
skip_app_build: true

0 commit comments

Comments
 (0)