Skip to content

Fix SWA deploy: skip rebuild to preserve VITE_API_BASE, copy staticwe… #19

Fix SWA deploy: skip rebuild to preserve VITE_API_BASE, copy staticwe…

Fix SWA deploy: skip rebuild to preserve VITE_API_BASE, copy staticwe… #19

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build-and-deploy:
name: Build & Deploy to Azure
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# --- Functions ---
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: functions/package-lock.json
- name: Install & build Functions
working-directory: functions
run: |
npm ci
npm run build
- name: Run Functions tests
working-directory: functions
run: npm run test:run
# --- Web ---
- name: Install & build Web
working-directory: web
env:
VITE_API_BASE: https://${{ vars.FUNCTION_APP_NAME }}.azurewebsites.net/api
run: |
npm ci
npx vite build
cp ../staticwebapp.config.json dist/staticwebapp.config.json
# --- Deploy SWA ---
- name: Deploy to Azure Static Web Apps
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.SWA_DEPLOYMENT_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: upload
app_location: web/dist
skip_app_build: true
skip_api_build: true
# --- Deploy Functions ---
- name: Prepare Functions package
working-directory: functions
run: |
npm ci --omit=dev
mkdir -p deploy/dist
cp -r dist/* deploy/dist/
cp host.json deploy/
cp package.json deploy/
cp -r node_modules/ deploy/node_modules/
cd deploy && zip -r ../deploy.zip .
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy Azure Functions
run: |
az functionapp deployment source config-zip \
--resource-group rg-event-vote \
--name ${{ vars.FUNCTION_APP_NAME }} \
--src functions/deploy.zip \
--timeout 120