In this post I will demonstrate how to connect multiple functions apps to one repo in Github using branches. I don’t have an excellent example but the idea is that if you have a Python HTTP Function App which is what I mostly code, you can setup different branches inside a repo for different versions of the app. Then, when you push to Github, depending on what branch you are on, Github Actions can push to the appropriate Function App inside Azure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
git init . New-Item -ItemType File -Path . -Name "myfile.txt" | Out-Null git add --all git commit -m 'first' # Don't forget to add the .git on the end or Credential Manager will not tie these together! git remote add origin https://github.com/gerryw1389/example.git git branch -M main #credential manager # git:https://github.com/gerryw1389/example.git # username: your-github-username # password: your-github-Personal-Access-Token git pull origin main --allow-unrelated-histories git push --set-upstream origin main # if you open the repo in vscode, it should work fine now #Next, create a testing branch: git checkout -b testing New-Item -ItemType File -Path . -Name "myfile-test.txt" | Out-Null git add --all git commit -m 'add myfile' git push origin testing git status # on branch testing
Inside the testing branch, add your code of the Function App while referencing Test systems, variables, ect.
Now, just configure Github actions to target a specific push for a specific branch like seen in my examples
- Basically, you will have a Github Action like the following (generated by Azure when you create an Azure Function App connection to Github):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action # More GitHub Actions for Azure: https://github.com/Azure/actions name: Build and deploy Python project to Azure Function App - my-example-http-python-fa on: push: branches: - main workflow_dispatch: env: AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root PYTHON_VERSION: '3.8' # 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 $ Environment uses: actions/setup-python@v1 with: python-version: $ - name: 'Resolve Project Dependencies Using Pip' shell: bash run: | pushd './$' 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 id: fa with: app-name: 'my-example-http-python-fa' slot-name: 'production' package: $ publish-profile: $
- You then clone this and change the
productionlike I did in the example