From f545ac6acaaf738ce261c8bb7d655c55ae7fffcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Fri, 23 Aug 2024 09:56:25 +0700 Subject: [PATCH] test --- .github/workflows/checkAuditRequired.yml | 47 +++++++++++------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/.github/workflows/checkAuditRequired.yml b/.github/workflows/checkAuditRequired.yml index aaa3e8cc3..b0696860a 100644 --- a/.github/workflows/checkAuditRequired.yml +++ b/.github/workflows/checkAuditRequired.yml @@ -86,42 +86,39 @@ jobs: GITHUB_TOKEN: ${{ secrets.GIT_ACTIONS_BOT_PAT_CLASSIC }} run: | + set -x # Enable debug mode - echo "A" - ##### get all labels that are assigned to this PR - assigned_labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name') + echo "Fetching currently assigned labels..." + # Fetch all labels assigned to this PR and store them in a variable + assigned_labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels | map(.name) | .[]') + echo "Assigned labels: $assigned_labels" # Debugging output - echo "B" - ##### check if 'AuditRequired' is assigned - audit_required_assigned=$(echo "$assigned_labels" | grep -c "AuditRequired") - echo "AuditRequired assigned: $audit_required_assigned" # Debugging output - - echo "C" - ##### check if 'AuditNotRequired' is assigned - echo "$assigned_labels" - echo "C1" - echo "$(echo "AuditRequired" | grep -c "AuditNotRequired")" - echo "C2" - echo "$(echo "$assigned_labels" | grep -c "AuditNotRequired")" - echo "C3" + # Initialize counters for labels of interest + audit_required_assigned=0 audit_not_required_assigned=0 - echo "C4" - audit_not_required_assigned=$(echo "$assigned_labels" | grep -c "AuditNotRequired") - echo "C5" - echo "AuditNotRequired assigned: $audit_not_required_assigned" # Debugging output - echo "D" - ##### make sure that exactly one of the two labels is assigned + # Loop through assigned labels and count occurrences of the specific labels + for label in $assigned_labels; do + if [[ "$label" == "AuditRequired" ]]; then + ((audit_required_assigned++)) + elif [[ "$label" == "AuditNotRequired" ]]; then + ((audit_not_required_assigned++)) + fi + done + + echo "AuditRequired assigned: $audit_required_assigned" + echo "AuditNotRequired assigned: $audit_not_required_assigned" + + # Calculate total labels assigned that are of interest total_labels_assigned=$((audit_required_assigned + audit_not_required_assigned)) - echo "Total labels assigned: $total_labels_assigned" # Debugging output + echo "Total labels assigned: $total_labels_assigned" - echo "E" + # Check that exactly one of the two labels is assigned if [[ "$total_labels_assigned" -ne 1 ]]; then echo -e "\033[31mError: Exactly one of the two labels should be assigned but found $total_labels_assigned assigned labels.\033[0m" exit 1 else echo -e "\033[32mVerified that exactly one label is assigned.\033[0m" echo -e "\033[32mAll good :)\033[0m" - fi