Skip to content

Deploying Azure Functions from a Monorepo with Shared Packages

Below are instructions on how to deploy an Azure Function when the project is stored as a monorepo and relies on shared packages.

To deploy a function to Azure Functions it needs to be built with npm so that all the node modules are in a single file with no symlinks. The script below installs all packages first using npm and builds any shared packages (the list of share packages needs to be updated on line 42). It then builds the backend using pnpm, including the shared packages.

The node modules folder for the backend is deleted before the modules are re-installed and re-built using npm.

The Azure Functions action is run which copies the entire backend directory to Azure.

azure-functions-deploy.yml
name: PRODUCTION - Deploy Node.js project to Azure Function App
on: workflow_dispatch
# CONFIGURATION
# For help, go to https://github.com/Azure/Actions
#
# 1. Set up the following secrets in your repository:
# AZURE_FUNCTIONAPP_PUBLISH_PROFILE
#
# 2. Change these variables for your configuration:
#
# See https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-github-actions?tabs=windows%2Cjavascript&pivots=method-template#parameters
#
env:
AZURE_FUNCTIONAPP_NAME: "name" # set this to your function app name on Azure
AZURE_FUNCTIONAPP_SLOT_NAME: "main" # set this to your function app name on Azure
AZURE_FUNCTIONAPP_PACKAGE_PATH: "./apps/backend" # set this to the path to your function app project, defaults to the repository root
NODE_VERSION: "20.x" # set this to the node version to use (e.g. '8.x', '10.x', '12.x')
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build - Shared packages
run: pnpm build -F # Update with any backend packages that need to be built first
- name: Install dependencies with Core built
run: pnpm install
- name: Build
run: pnpm build -F backend # Update if the backend package is not called backend
- name: "Resolve Project Dependencies Using Npm"
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
rm -rf node_modules
ls
sed -i '/eslint-config/,/tsconfig/d' package.json
npm install --install-links
npm run build --if-present
popd
- name: "Run Azure Functions Action"
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE_PROD }}
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples