|
| 1 | +# This workflow will build a Java project and deploy it to an Azure Functions App on Windows or Linux when a commit is pushed to your default branch. |
| 2 | +# |
| 3 | +# This workflow assumes you have already created the target Azure Functions app. |
| 4 | +# For instructions see https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-java |
| 5 | +# |
| 6 | +# To configure this workflow: |
| 7 | +# 1. Set up the following secrets in your repository: |
| 8 | +# - AZURE_FUNCTIONAPP_PUBLISH_PROFILE |
| 9 | +# 2. Change env variables for your configuration. |
| 10 | +# |
| 11 | +# For more information on: |
| 12 | +# - GitHub Actions for Azure: https://github.com/Azure/Actions |
| 13 | +# - Azure Functions Action: https://github.com/Azure/functions-action |
| 14 | +# - Publish Profile: https://github.com/Azure/functions-action#using-publish-profile-as-deployment-credential-recommended |
| 15 | +# - Azure Service Principal for RBAC: https://github.com/Azure/functions-action#using-azure-service-principal-for-rbac-as-deployment-credential |
| 16 | +# |
| 17 | +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples/tree/master/FunctionApp |
| 18 | + |
| 19 | +name: Deploy Java project to Azure Function App |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + branches: ["main"] |
| 24 | + |
| 25 | +env: |
| 26 | + AZURE_FUNCTIONAPP_NAME: 'your-app-name' # set this to your function app name on Azure |
| 27 | + POM_XML_DIRECTORY: '.' # set this to the directory which contains pom.xml file |
| 28 | + DISTRIBUTION: 'zulu' # set this to the java version to use (e.g. 'zulu', 'temurin', 'microsoft') |
| 29 | + JAVA_VERSION: '8' # set this to the java version to use (e.g. '8', '11', '17') |
| 30 | + |
| 31 | +jobs: |
| 32 | + build-and-deploy: |
| 33 | + runs-on: windows-latest # For Linux, use ubuntu-latest |
| 34 | + environment: dev |
| 35 | + steps: |
| 36 | + - name: 'Checkout GitHub Action' |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + # If you want to use Azure RBAC instead of Publish Profile, then uncomment the task below |
| 40 | + # - name: 'Login via Azure CLI' |
| 41 | + # uses: azure/login@v1 |
| 42 | + # with: |
| 43 | + # creds: ${{ secrets.AZURE_RBAC_CREDENTIALS }} # set up AZURE_RBAC_CREDENTIALS secrets in your repository |
| 44 | + |
| 45 | + - name: Setup Java Sdk ${{ env.JAVA_VERSION }} |
| 46 | + uses: actions/setup-java@v4 |
| 47 | + with: |
| 48 | + distribution: ${{ env.DISTRIBUTION }} |
| 49 | + java-version: ${{ env.JAVA_VERSION }} |
| 50 | + |
| 51 | + - name: 'Restore Project Dependencies Using Mvn' |
| 52 | + shell: pwsh # For Linux, use bash |
| 53 | + run: | |
| 54 | + pushd './${{ env.POM_XML_DIRECTORY }}' |
| 55 | + mvn clean package |
| 56 | + popd |
| 57 | +
|
| 58 | + - name: 'Run Azure Functions Action' |
| 59 | + uses: Azure/functions-action@v1 |
| 60 | + id: fa |
| 61 | + with: |
| 62 | + app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} |
| 63 | + package: '${{ env.POM_XML_DIRECTORY }}' # if there are multiple function apps in same project, then this path will be like './${{ env.POM_XML_DIRECTORY }}/target/azure-functions/${{ env.POM_FUNCTIONAPP_NAME }' |
| 64 | + publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} # Remove publish-profile to use Azure RBAC |
| 65 | + respect-pom-xml: true |
0 commit comments