Skip to content

Commit

Permalink
added autotag
Browse files Browse the repository at this point in the history
  • Loading branch information
erjosito committed Sep 27, 2024
1 parent 02c4004 commit a77af38
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/autotagv2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Autotag

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
pull_request:
branches: [v2]
paths:
- '**.yml'
- '**.yaml'

jobs:
autotag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: files
uses: masesgroup/retrieve-changed-files@v2
- id: alzimpact
name: Verify whether the modified files have an impact on the ALZ checklist
run: |
alz_files=$(python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --checklist-file ./v2/checklists/alz.yaml --only-filenames)
for input_file in ${{ steps.files.outputs.all }}; do
if [[ echo "$alz_files" | grep "$input_file" == "$input_file" ]]; then
echo "Modification to file $input_file detected, which seems to be a reco leveraged by the ALZ checklist"
echo "alz_impact=yes" >> $GITHUB_OUTPUT
else
echo "$input_file has no ALZ impact"
fi
done
- name: Work with the list of modified files - sort, update timestamp, translate
if: ${{ steps.alzimpact.outputs.alz_impact == 'yes' }}
uses: actions-ecosystem/action-add-labels@v1
id: addalzlabel
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'landingzone'
2 changes: 1 addition & 1 deletion .github/workflows/linterv2.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Lint Code Base
name: Lint v2 recommendations and checklists
on:
# push:
# branches-ignore: [main]
Expand Down
12 changes: 10 additions & 2 deletions scripts/cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
# python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --format yaml --label-selector '{"checklist": "alz"}' --show-labels
# python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --format yaml --source-selector 'aprl'
# python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --format yaml --with-arg
# python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --checklist-file ./v2/checklists/alz.yaml --verbose
# python3 ./scripts/cl.py list-recos --input-folder ./v2/recos --checklist-file ./v2/checklists/alz.yaml --only-filenames
#
# Usage examples for renaming:
# python3 ./scripts/cl.py rename-reco --input-folder ./v2/recos --guid 1b1b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b
Expand Down Expand Up @@ -167,6 +169,8 @@
default=False, help='only return queries with ARG queries (default: False)')
getrecos_parser.add_argument('--checklist-file', dest='getrecos_checklist_file', metavar='CHECKLIST_FILE', action='store',
help='YAML file with a checklist definition that can include label-selectors, service-selectors and WAF-selectors as well as other metadata')
getrecos_parser.add_argument('--only-filenames', dest='getrecos_only_filenames', action='store_true',
default=False, help='only show the reco filenames (default: False)')
# Create the 'update-recos' command
updaterecos_parser = subparsers.add_parser('update-recos', help='Update recommendations from a folder structure containing v2 recos', parents=[base_subparser])
updaterecos_parser.add_argument('--input-folder', dest='updaterecos_input_folder', metavar='INPUT_FOLDER', action='store',
Expand Down Expand Up @@ -489,7 +493,7 @@
if args.getrecos_input_folder:
if args.getrecos_checklist_file:
# Get recos from the checklist file
v2recos = cl_analyze_v2.get_recos_from_checklist( args.getrecos_checklist_file, args.getrecos_input_folder, verbose=args.verbose)
v2recos = cl_analyze_v2.get_recos_from_checklist( args.getrecos_checklist_file, args.getrecos_input_folder, verbose=args.verbose, import_filepaths=True)
else:
# Convert label selectors argument to an object if specified
if args.getrecos_labels:
Expand Down Expand Up @@ -518,7 +522,11 @@
arg=args.getrecos_arg, verbose=args.verbose)
# Print recos
if v2recos:
cl_analyze_v2.print_recos(v2recos, show_labels=args.getrecos_show_labels, show_arg=args.getrecos_show_arg)
if args.getrecos_only_filenames:
for reco in v2recos:
print(reco['filepath'])
else:
cl_analyze_v2.print_recos(v2recos, show_labels=args.getrecos_show_labels, show_arg=args.getrecos_show_arg)
else:
print("ERROR: No v2 objects found satisfying the criteria.")
else:
Expand Down
Binary file modified scripts/modules/__pycache__/cl_analyze_v2.cpython-311.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions scripts/modules/cl_analyze_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,14 @@ def get_checklist_object(checklist_file, verbose=False):
return None

# Return v2 recos that match the selectors included in a checklist file
def get_recos_from_checklist(checklist_file, input_folder, verbose=False):
def get_recos_from_checklist(checklist_file, input_folder, import_filepaths=False, verbose=False):
# Get checklist object and full reco list
checklist_v2 = get_checklist_object(checklist_file, verbose)
if not checklist_v2:
print("ERROR: Checklist file could not be loaded.")
return None
if verbose: print("DEBUG: Loading recos from folder", input_folder)
recos_v2_full = get_recos(input_folder, verbose=False) # Loading all recos, verbose not needed
recos_v2_full = get_recos(input_folder, import_filepaths=import_filepaths, verbose=False) # Loading all recos, verbose not needed
recos_v2 = []
# Selectors can be at the checklist root, in an area, or a subarea
if 'include' in checklist_v2:
Expand Down

0 comments on commit a77af38

Please sign in to comment.