-
Notifications
You must be signed in to change notification settings - Fork 255
88 lines (73 loc) · 2.94 KB
/
generate-templates.yml
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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