Deploy to Azure Static Web Apps #13
This file contains hidden or 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: Deploy to Azure Static Web Apps | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| required: true | |
| default: 'develop' | |
| type: choice | |
| options: | |
| - production | |
| - staging | |
| - develop | |
| - testing | |
| jobs: | |
| set-github-environment: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| environment: ${{ steps.set-env.outputs.target_env }} | |
| steps: | |
| - name: Set Environment | |
| id: set-env | |
| run: | | |
| case "${{ inputs.environment }}" in | |
| testing) echo "target_env=Testing" >> $GITHUB_OUTPUT ;; | |
| develop) echo "target_env=dev" >> $GITHUB_OUTPUT ;; | |
| staging) echo "target_env=stage" >> $GITHUB_OUTPUT ;; | |
| production) echo "target_env=prod" >> $GITHUB_OUTPUT ;; | |
| esac | |
| build-and-deploy: | |
| needs: set-github-environment | |
| runs-on: ubuntu-latest | |
| environment: ${{ needs.set-github-environment.outputs.environment }} | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.event.inputs.environment }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '24' | |
| - name: Install Dependencies | |
| run: npm install | |
| - name: Ingest Environment Variables | |
| run: | | |
| touch .env | |
| echo '${{ vars.ENV_CONFIG }}' | jq -r 'to_entries | map("\(.key)=\(.value)") | .[]' > .env | |
| echo CI=false >> .env | |
| - name: Build Project | |
| run: npm run generate | |
| - name: Copy WebApp Config | |
| run: cp staticwebapp.config.json .output/public/staticwebapp.config.json | |
| - name: Deploy to Azure Static Web Apps | |
| id: deploy | |
| uses: Azure/static-web-apps-deploy@v1 | |
| with: | |
| azure_static_web_apps_api_token: ${{ secrets.AZURE_DEPLOYMENT_TOKEN }} | |
| action: "upload" | |
| app_location: ".output/public" # App source code path | |
| api_location: "" # Api source code path - optional | |
| output_location: "" # Built app content directory - optional | |
| skip_app_build: true | |
| production_branch: ${{ inputs.environment }} |