Skip to content

Add OIDC deployment workflow #7

Add OIDC deployment workflow

Add OIDC deployment workflow #7

Workflow file for this run

name: Build and Deploy to Azure Functions
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
AZURE_FUNCTIONAPP_NAME: 'auditsphere-api'
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
NODE_VERSION: '20.x'
# Required for OIDC authentication
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Generate Prisma Client
run: npm run db:generate
- name: Build TypeScript
run: npm run build
- name: Run tests
run: npm test
continue-on-error: true
- name: Upload build artifact
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: function-app
path: |
dist/
node_modules/
host.json
package.json
prisma/
retention-days: 1
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment:
name: production
url: ${{ steps.deploy.outputs.webapp-url }}
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: function-app
path: .
# OIDC Authentication (recommended - no secrets to rotate)
- name: Azure Login via OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy to Azure Functions
id: deploy
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
# No publish-profile needed with OIDC