Use GitHub Actions to define a workflow to automatically build and deploy code to your function app in Azure Functions.
In GitHub Actions, a workflow is an automated process that you define in your GitHub repository. This process tells GitHub how to build and deploy your function app project on GitHub.
A workflow is defined by a YAML (.yml) file in the /.github/workflows/ path in your repository. This definition contains the various steps and parameters that make up the workflow.
For an Azure Functions workflow, the file has three sections:
Section
Tasks
Authentication
Download a publish profile. Create a GitHub secret.
The recommended way to authenticate with Azure Functions for GitHub Actions is by using a publish profile. You can also authenticate with a service principal. To learn more, see this GitHub Actions repository.
After saving your publish profile credential as a GitHub secret, you'll use this secret within your workflow to authenticate with Azure.
Download your publish profile
To download the publishing profile of your function app:
Select the function app's Overview page, and then select Get publish profile.
Java uses the actions/setup-java action.
The following example shows the part of the workflow that sets up the environment:
- name: Setup Java 1.8.x
uses: actions/setup-java@v1
with:
# If your pom.xml <maven.compiler.source> version is not in 1.8.x
# Please change the Java version to match the version in pom.xml <maven.compiler.source>
java-version: '1.8.x'
JavaScript (Node.js) uses the actions/setup-node action.
The following example shows the part of the workflow that sets up the environment:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
- name: 'Resolve Project Dependencies Using Dotnet'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
env:
POM_XML_DIRECTORY: '.' # set this to the directory which contains pom.xml file
- name: 'Restore Project Dependencies Using Mvn'
shell: bash
run: |
pushd './${{ env.POM_XML_DIRECTORY }}'
mvn clean package
mvn azure-functions:package
popd
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
- name: 'Resolve Project Dependencies Using Npm'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
- name: 'Resolve Project Dependencies Using Pip'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
Deploy the function app
Use the Azure/functions-action action to deploy your code to a function app. This action has three parameters:
Parameter
Explanation
app-name
(Mandatory) The name of your function app.
slot-name
(Optional) The name of the deployment slot you want to deploy to. The slot must already be defined in your function app.
publish-profile
(Optional) The name of the GitHub secret for your publish profile.
The following example uses version 1 of the functions-action and a publish profile for authentication
Set up a .NET Linux workflow that uses a publish profile.
name: Deploy DotNet project to function app with a Linux environment
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your application's name
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '2.2.402' # set this to the dotnet version to use
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 'Resolve Project Dependencies Using Dotnet'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
Set up a .NET Windows workflow that uses a publish profile.
name: Deploy DotNet project to function app with a Windows environment
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your application's name
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '2.2.402' # set this to the dotnet version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 'Resolve Project Dependencies Using Dotnet'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
Set up a Java Linux workflow that uses a publish profile.
name: Deploy Java project to function app
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your function app name on Azure
POM_XML_DIRECTORY: '.' # set this to the directory which contains pom.xml file
POM_FUNCTIONAPP_NAME: your-app-name # set this to the function app name in your local development environment
JAVA_VERSION: '1.8.x' # set this to the java version to use
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup Java Sdk ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
- name: 'Restore Project Dependencies Using Mvn'
shell: bash
run: |
pushd './${{ env.POM_XML_DIRECTORY }}'
mvn clean package
mvn azure-functions:package
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: './${{ env.POM_XML_DIRECTORY }}/target/azure-functions/${{ env.POM_FUNCTIONAPP_NAME }}'
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
Set up a Java Windows workflow that uses a publish profile.
name: Deploy Java project to function app
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your function app name on Azure
POM_XML_DIRECTORY: '.' # set this to the directory which contains pom.xml file
POM_FUNCTIONAPP_NAME: your-app-name # set this to the function app name in your local development environment
JAVA_VERSION: '1.8.x' # set this to the Java version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup Java Sdk ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
- name: 'Restore Project Dependencies Using Mvn'
shell: pwsh
run: |
pushd './${{ env.POM_XML_DIRECTORY }}'
mvn clean package
mvn azure-functions:package
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: './${{ env.POM_XML_DIRECTORY }}/target/azure-functions/${{ env.POM_FUNCTIONAPP_NAME }}'
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
Set up a Node.JS Linux workflow that uses a publish profile.
name: Deploy Node.js project to function app
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your application's name
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '14.x' # set this to the node version to use (supports 8.x, 10.x, 12.x, 14.x)
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'Resolve Project Dependencies Using Npm'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
Set up a Node.JS Windows workflow that uses a publish profile.
name: Deploy Node.js project to function app
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your application's name
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '14.x' # set this to the node version to use (supports 8.x, 10.x, 12.x, 14.x)
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'Resolve Project Dependencies Using Npm'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
Set up a Python Linux workflow that uses a publish profile.
name: Deploy Python project to function app
on:
[push]
env:
AZURE_FUNCTIONAPP_NAME: your-app-name # set this to your application's name
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.7' # set this to the Python version to use (supports 3.6, 3.7, 3.8)
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub action'
uses: actions/checkout@v2
- name: Setup Python ${{ env.PYTHON_VERSION }} Environment
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 'Resolve Project Dependencies Using Pip'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
- name: 'Run Azure Functions action'
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}