Azure Functions Intermediate

Deploying with GitHub Actions

Deploying a function app should be repeatable and safe: build once in CI, sign in to Azure without stored passwords, deploy a package, and be able to roll back.

From commit to production
  1. StartPush to mainGitHub Actions starts the workflow.
  2. Step 2Build and testdotnet test and dotnet publish run in CI.
  3. Step 3Sign in with OIDCNo stored secret; a short-lived token is used.
  4. Step 4Deploy packageThe app runs from the uploaded package.
  5. EndVerify or swapCheck the staging slot, then swap.

Every release is built once, tested and traceable.

A GitHub Actions workflow

Use OpenID Connect (federated credentials) so GitHub signs in to Azure without a stored client secret.

YAML
name: Deploy functions
on:
  push:
    branches: [main]
permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.0.x'
      - run: dotnet test --configuration Release
      - run: dotnet publish src/Shop.Functions --configuration Release --output ./publish
      - uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
      - uses: Azure/functions-action@v1
        with:
          app-name: shop-func
          package: ./publish

How the code gets there

  • Zip deployment uploads a package of the published output. Running from the package (WEBSITE_RUN_FROM_PACKAGE) mounts it read-only, which makes deployments atomic and start-up faster.
  • Flex Consumption deploys a package to a storage container that the app runs from; the action and Core Tools handle that for you.
  • func azure functionapp publish is fine for experiments, but production deploys should come from CI so every release is tested and traceable.

Infrastructure as code

Create the function app, plan, Storage account, Application Insights, identity and role assignments with Bicep or Terraform, so every environment is the same and changes are reviewed.

Keep environment-specific values (queue names, schedules, URLs) in app settings set by the template, not in code.

Releasing safely

  • On plans that support them, deploy to a staging slot, warm it up, then swap it into production; swap back to roll back.
  • Mark settings that must not move during a swap as slot settings.
  • Changing app settings restarts the app, so change them in a deployment, not by hand during busy hours.
  • Keep the previous package so you can redeploy it if a release goes wrong.

Interview question

How do you deploy an Azure Function app from GitHub without storing Azure credentials?

I set up a federated credential on an Entra ID app registration or user-assigned managed identity that trusts the GitHub repository and branch. The workflow requests an OIDC token with id-token: write, signs in with azure/login using only the client, tenant and subscription ids, and deploys the published package with Azure/functions-action. No secret or password is stored.

Your progress is saved only in this browser.

Want the full details? Read the official Microsoft documentation for this topic.