Created
March 3, 2021 11:00
-
-
Save philMarius/5d37ba9dcd028b55489159e3d7c59fe5 to your computer and use it in GitHub Desktop.
CI/CD workflow for blog: Azure Functions Environment Separation with Linux Apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run CI and CD | |
on: | |
push: | |
branches: | |
- develop | |
- master | |
- release/** | |
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@master | |
- name: Setup Python ${{ env.PYTHON_VERSION }} Environment | |
uses: actions/setup-python@v1 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: | |
Set environment to use | |
# Check the branch and set function name if master, release, or develop | |
# Sets publish profile to correct profile for function as well | |
# We use GHA `$GITHUB_ENV` to set local env vars to be used (see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable) | |
# Match on prefix for release/** : https://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value | |
run: | | |
if [ "${{github.ref}}" == "refs/heads/master" ]; then | |
echo "AZURE_FUNCTIONAPP_NAME=prod-collector" >> $GITHUB_ENV | |
echo "PUBLISH_PROFILE_NAME=PROD_AZURE_FUNCTIONAPP_PUBLISH_PROFILE" >> $GITHUB_ENV | |
elif [ "${{github.ref}}" == "refs/heads/develop" ]; then | |
echo "AZURE_FUNCTIONAPP_NAME=dev-collector" >> $GITHUB_ENV | |
echo "PUBLISH_PROFILE_NAME=DEV_AZURE_FUNCTIONAPP_PUBLISH_PROFILE" >> $GITHUB_ENV | |
elif [[ "${{github.ref}}" == refs/heads/release/* ]]; then | |
echo "AZURE_FUNCTIONAPP_NAME=stg-collector" >> $GITHUB_ENV | |
echo "PUBLISH_PROFILE_NAME=STG_AZURE_FUNCTIONAPP_PUBLISH_PROFILE" >> $GITHUB_ENV | |
else | |
echo "The branch ${{ github.ref }} cannot do this..." | |
exit 1 | |
python -m pip install --upgrade pip | |
pip install flake8 pytest | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
popd | |
- name: Run Tests | |
run: | | |
pytest | |
- name: Run Audit | |
run: | | |
safety check -r requirements.txt | |
- name: Run Black | |
uses: jpetrucciani/black-check@master | |
with: | |
path: "." | |
- 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[env.PUBLISH_PROFILE_NAME] }} | |
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples fi | |
- name: Install Dependencies | |
shell: bash | |
run: | | |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' | |
python -m pip install --upgrade pip | |
pip install flake8 pytest | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
popd | |
- name: Run Tests | |
run: | | |
pytest | |
- name: Run Audit | |
run: | | |
safety check -r requirements.txt | |
- name: Run Black | |
uses: jpetrucciani/black-check@master | |
with: | |
path: "." | |
- 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[env.PUBLISH_PROFILE_NAME] }} | |
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment