Skip to content

Generate Templates

Generate Templates #21

# Workflow for generating (arm/bicep/etc) templates for each alert
name: Generate Templates
on:
# Runs on pushes targeting the default branch
push:
branches:
- main
paths:
- 'services/**/alerts.yaml'
- 'tooling/generate-templates/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch: {}
permissions:
contents: write
pull-requests: write
jobs:
generate-templates:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
submodules: recursive
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12' # install the python version needed
- name: Install Python Packages and Requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: tooling/generate-templates
- name: Generate Templates
id: generate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout -b github-action-generate-templates
# Generate templates for alerts
echo "Generating templates for alerts..."
python tooling/generate-templates/generate-templates.py --path services --output services --template_path tooling/generate-templates/templates
# Check if there are any changes in the services directory
git add services
# Check if there are any changes to commit
if [[ `git status --porcelain` ]]; then
git commit -m "[GitHub Action - Generate Templates] Generate templates for alerts"
# Push changes to the current branch
git push --set-upstream origin github-action-generate-templates --force
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head 'github-action-generate-templates' \
--base 'main' \
--json title \
--jq 'length')
if ((prs > 0)); then
echo "skippr=true" >> "$GITHUB_OUTPUT"
fi
else
echo "skippr=true" >> "$GITHUB_OUTPUT"
fi
# Diasble PR creation for now since it is not supported in the Azure repo
# - name: Create pull request
# if: '!steps.generate.outputs.skippr'
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# # Create a pull request
# echo "Creating a pull request..."
# gh pr --repo ${{ github.repository }} create --title "[GitHub Action - Generate Templates] Generate templates for alerts" --body "This PR was automatically generated by the workflow." --base main --head github-action-generate-templates