-
Notifications
You must be signed in to change notification settings - Fork 327
159 lines (153 loc) · 9.56 KB
/
translatev2.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Translation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
branches: [ v2 ]
paths:
- '**.yaml'
- '**.yml'
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
translate:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
# Get list of files that have been changed in the push
- id: files
uses: masesgroup/retrieve-changed-files@v2
# Set variables that indicate whether XLSX files have been modified, which would indicate that
- name: Set variables
id: variables
run: |
echo "v1_output_folder=v2/checklists" >> $GITHUB_OUTPUT
echo "clv2_file_list=('./v2/checklists/alz.yaml' './v2/checklists/waf.yaml' './v2/checklists/app_delivery.yaml')" >> $GITHUB_OUTPUT
# this action has been triggered by an automated action
- id: automationresult
name: Verify whether this action is a result of another action
run: |
for input_file in ${{ steps.files.outputs.all }}; do
if [[ "$input_file" == *"xlsx" ]]; then
echo "Modification to XLSX file $input_file detected, this seems to be the output of an automated PR"
echo "excel_file_changed=yes" >> $GITHUB_OUTPUT
else
echo "$input_file is not an XLSX file"
fi
done
# Find out the impacted checklists
- id: climpact
if: ${{ steps.automationresult.outputs.excel_file_changed != 'yes' }}
name: Verify whether the modified files have an impact on the defined v2 checklists
run: |
# Install Python dependencies to run the checklist CLI
pip install -r ./scripts/requirements.txt
# The list of impacted checklists will be passed as an array
impacted_cl_files=()
done_something=no
clv2_file_list=${{ steps.variables.outputs.clv2_file_list }}
echo "Checking impact of changes in files ${{ steps.files.outputs.all }} to the following ${#clv2_file_list[@]} v2 checklists: ${clv2_file_list[@]}..."
for cl_file in "${clv2_file_list[@]}"; do
echo "Processing v2 checklist '${cl_file}'..."
cl_name=$(echo $cl_file | cut -d/ -f4 | cut -d. -f1)
cl_reco_files=$(python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --checklist-file ./v2/checklists/alz.yaml --only-filenames)
cl_reco_files_count=$(echo "$cl_reco_files" | wc -l)
echo "$cl_reco_files_count reco files found referenced in the checklist $cl_file"
for input_file in ${{ steps.files.outputs.all }}; do
echo "- Processing changed file '$input_file'..."
if [[ "$cl_reco_files" == *"$input_file"* ]]; then
echo " * Modification to file '$input_file' detected, which seems to be a reco leveraged by the checklist $cl_name in $cl_file"
impacted_cl_files+="$cl_file"
done_something=yes
else
echo " * '$input_file' has no impact to the checklist $cl_name in $cl_file"
fi
done
done
echo "impacted_cl_files=$impacted_cl_files" >> $GITHUB_OUTPUT
echo "done_something=$done_something" >> $GITHUB_OUTPUT
# Process the impacted checklists and generate v1 versions
- name: Generate v1 JSON checklists and translate them
id: clv1
if: ${{ steps.climpact.outputs.done_something == 'yes' }}
env:
AZURE_TRANSLATOR_SUBSCRIPTION_KEY: ${{ secrets.AZURE_TRANSLATOR_SUBSCRIPTION_KEY }}
AZURE_TRANSLATOR_ENDPOINT: ${{ secrets.AZURE_TRANSLATOR_ENDPOINT }}
AZURE_TRANSLATOR_REGION: ${{ secrets.AZURE_TRANSLATOR_REGION }}
run: |
# First we put the GH variable into a local one. Doing a loop against the GH variable directly doesn't work.
cl_v2_files=${{ steps.climpact.outputs.impacted_cl_files }}
# We will pass the list of generated v1 checklists as an array
cl_v1_files=()
echo "Generating v1 checklists for the following v2 files: $cl_v2_files..."
# We run now through the list of impacted checklists
for cl_file in "${cl_v2_files[@]}"; do
cl_name=$(echo $cl_file | cut -d/ -f4 | cut -d. -f1)
cl_v1_file="./${{ steps.variables.outputs.v1_output_folder }}/${cl_name}_checklist.en.json"
cl_v1_files+="$cl_v1_file"
# Generate v1 JSON for the checklist
echo "Generating v1 JSON for checklist $cl_name in $cl_file into $cl_v1_file..."
python3 ./scripts/cl.py export-checklist --input-folder ./v2/recos --service-dictionary ./scripts/service_dictionary.json --checklist-file $cl_file --output-file $cl_v1_file --verbose
# Sort modified file
# python3 ./scripts/sort_checklist.py --input-file $input_file
# Update the timestamp in the modified file
# python3 ./scripts/timestamp_checklist.py --input-file $input_file
# Translate the checklist
echo "Translating $cl_v1_file (this can take a few minutes)..."
python3 ./scripts/translate.py --input-file $cl_v1_file
done
echo "cl_v1_files=$cl_v1_files" >> $GITHUB_OUTPUT
# Generate macro-free spreadsheets and Azure Monitor workbooks
- name: Setup python
if: ${{ steps.climpact.outputs.done_something == 'yes' }}
uses: actions/setup-python@v2
with:
python-version: 3.8 #install the python needed
- name: Install dependencies
if: ${{ steps.climpact.outputs.done_something == 'yes' }}
run: |
python -m pip install --upgrade pip
pip install requests openpyxl
# Create Excel spreadsheets
- name: Execute excel python script # run file
if: ${{ steps.climpact.outputs.done_something == 'yes' }}
run: |
# First we put the GH variable into a local one. Doing a loop against the GH variable directly doesn't work.
cl_v1_files="${{ steps.clv1.outputs.cl_v1_files }}"
# For each file we will generate a macro-free Excel file
for cl_file in "${cl_v1_files[@]}"; do
echo "Generating macro-free Excel file for $cl_file..."
python3 ./scripts/update_excel_openpyxl.py --checklist-file="$cl_v1_file" --find-all --excel-file="./spreadsheet/macrofree/review_checklist_empty.xlsx" --output-name-is-input-name --output-path="./spreadsheet/macrofree/" --verbose
done
# Create Azure Monitor workbooks
# Note that workbook creation might not work with some of the v1 checklists generated from v2, since categories and subcategories might be missing.
# The workbook creation script should instead pick service names instead of categories for the tabs.
- name: Execute workbook python script # run file
if: ${{ steps.climpact.outputs.done_something == 'yes' }}
run: |
# First we put the GH variable into a local one. Doing a loop against the GH variable directly doesn't work.
cl_v1_files="${{ steps.clv1.outputs.cl_v1_files }}"
# For each file we will generate a macro-free Excel file
for cl_file in "${cl_v1_files[@]}"; do
# Create workbooks for the modified file, both with and without reco counters
echo "Generating workbooks for the v1 checklist file: $cl_file..."
python3 ./scripts/workbook_create.py --checklist-file="$cl_file" --output-path="./workbooks/" --blocks-path="./workbooks/blocks/"
python3 ./scripts/workbook_create.py --checklist-file="$cl_file" --output-path="./workbooks/" --blocks-path="./workbooks/blocks/" --counters
# Extra static commands to generate a network-specific ALZ workbook
# python3 ./scripts/workbook_create.py --checklist-file ./checklists/alz_checklist.en.json --output-path ./workbooks --blocks-path ./workbooks/blocks --create-arm-template --category=network --query-size medium
# python3 ./scripts/workbook_create.py --checklist-file ./checklists/alz_checklist.en.json --output-file ./workbooks/alz_checklist.en_network_counters.json --blocks-path ./workbooks/blocks --create-arm-template --category=network --query-size tiny --counters
# python3 ./scripts/workbook_create.py --checklist-file ./checklists/alz_checklist.en.json --output-file ./workbooks/alz_checklist.en_network_tabcounters.json --blocks-path ./workbooks/blocks --create-arm-template --category=network --query-size tiny --tab-counters
# App delivery
# python3 ./scripts/workbook_create.py --checklist-file ./checklists/network_appdelivery_checklist.en.json --output-file ./workbooks/appdelivery_checklist.en_network_workbook.json --blocks-path ./workbooks/blocks --create-arm-template --category=network --query-size tiny
# python3 ./scripts/workbook_create.py --checklist-file ./checklists/network_appdelivery_checklist.en.json --output-file ./workbooks/appdelivery_checklist.en_network_counters_workbook.json --blocks-path ./workbooks/blocks --create-arm-template --category=network --query-size tiny --counters
done
# Create the PR if any change was made
- name: Create pull request
uses: peter-evans/create-pull-request@v6
if: ${{ steps.climpact.outputs.done_something == 'yes' }}
with:
title: 'Automated actions after change to ${{ steps.files.outputs.all }}'
body: 'Processed changed files ${{ steps.files.outputs.all }}'
labels: 'automated'
token: ${{ secrets.WORKFLOW_PAT }}