1+ name : Deploy to Azure Static Web Apps
2+ on :
3+ workflow_dispatch :
4+ inputs :
5+ environment :
6+ description : ' Environment to deploy to'
7+ required : true
8+ default : ' development'
9+ type : choice
10+ options :
11+ - production
12+ - staging
13+ - development
14+ - testing
15+ jobs :
16+
17+ set-github-environment :
18+ runs-on : ubuntu-latest
19+ outputs :
20+ environment : ${{ steps.set-env.outputs.target_env }}
21+ steps :
22+ - name : Set Environment
23+ id : set-env
24+ run : |
25+ case "${{ inputs.environment_input }}" in
26+ testing) echo "target_env=Testing" >> $GITHUB_OUTPUT ;;
27+ development) echo "target_env=dev" >> $GITHUB_OUTPUT ;;
28+ staging) echo "target_env=stage" >> $GITHUB_OUTPUT ;;
29+ production) echo "target_env=prod" >> $GITHUB_OUTPUT ;;
30+ esac
31+
32+ build-and-deploy :
33+ needs : set-github-environment
34+ runs-on : ubuntu-latest
35+ environment : ${{ needs.set-github-environment.outputs.environment }}
36+ steps :
37+ - name : Checkout Code
38+ uses : actions/checkout@v3
39+ with :
40+ ref : ${{ github.event.inputs.environment }}
41+ - name : Setup Node.js
42+ uses : actions/setup-node@v3
43+ with :
44+ node-version : ' 20'
45+ - name : Install Dependencies
46+ run : npm install
47+ - name : Ingest Environment Variables
48+ run : |
49+ touch .env
50+ echo '${{ vars.ENV_CONFIG }}' | jq -r 'to_entries | map("\(.key)=\(.value)") | .[]' > .env
51+ echo CI=false >> .env
52+ - name : Build Project
53+ run : npm run generate
54+ - name : Copy WebApp Config
55+ run : cp staticwebapp.config.json .output/public/staticwebapp.config.json
56+
57+ - name : Deploy to Azure Static Web Apps
58+ id : deploy
59+ uses : Azure/static-web-apps-deploy@v1
60+ with :
61+ azure_static_web_apps_api_token : ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
62+ action : " upload"
63+ app_location : " .output/public" # App source code path
64+ api_location : " " # Api source code path - optional
65+ output_location : " " # Built app content directory - optional
66+ skip_app_build : true
0 commit comments