From 1d8a26652cef6d2b214d6ac2e60b0ca4b9d2d1f8 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 28 Jun 2024 14:36:08 -0500 Subject: [PATCH 01/10] Add workflow to enforce labels on PRs --- .github/workflows/label-checker.yaml | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/label-checker.yaml diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml new file mode 100644 index 000000000000..1203b936ee18 --- /dev/null +++ b/.github/workflows/label-checker.yaml @@ -0,0 +1,54 @@ +name: Check PR Labels + +on: + pull_request: + types: [opened, labeled, unlabeled, synchronize] + +jobs: + check-label: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' + + - name: Install yq + run: | + pip install yq + + - name: Get required labels from release.yml + id: get-required-labels + run: | + labels=$(yq e '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml | tr '\n' ' ') + echo "required_labels=$labels" >> $GITHUB_OUTPUT + + - name: Get PR labels + id: get-pr-labels + run: | + labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") + echo "labels=$labels" >> $GITHUB_OUTPUT + + - name: Check for specific labels + id: check-label + run: | + required_labels=(${{ steps.get-required-labels.outputs.required_labels }}) + found=false + for label in "${required_labels[@]}"; do + if echo "${{ steps.get-pr-labels.outputs.labels }}" | grep -q "$label"; then + found=true + break + fi + done + echo "label_exists=$found" >> $GITHUB_OUTPUT + + - name: Fail if no required labels are found + if: steps.check-label.outputs.label_exists == 'false' + run: | + echo "None of the required labels are applied to the PR." + exit 1 \ No newline at end of file From ef04f06734cd06df6966df7719a210892db91f75 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 28 Jun 2024 15:16:05 -0500 Subject: [PATCH 02/10] Attempt to fix issues --- .github/workflows/label-checker.yaml | 95 +++++++++++++++------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml index 1203b936ee18..6b75c79a784c 100644 --- a/.github/workflows/label-checker.yaml +++ b/.github/workflows/label-checker.yaml @@ -9,46 +9,55 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - cache: 'pip' - - - name: Install yq - run: | - pip install yq - - - name: Get required labels from release.yml - id: get-required-labels - run: | - labels=$(yq e '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml | tr '\n' ' ') - echo "required_labels=$labels" >> $GITHUB_OUTPUT - - - name: Get PR labels - id: get-pr-labels - run: | - labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") - echo "labels=$labels" >> $GITHUB_OUTPUT - - - name: Check for specific labels - id: check-label - run: | - required_labels=(${{ steps.get-required-labels.outputs.required_labels }}) - found=false - for label in "${required_labels[@]}"; do - if echo "${{ steps.get-pr-labels.outputs.labels }}" | grep -q "$label"; then - found=true - break - fi - done - echo "label_exists=$found" >> $GITHUB_OUTPUT - - - name: Fail if no required labels are found - if: steps.check-label.outputs.label_exists == 'false' - run: | - echo "None of the required labels are applied to the PR." - exit 1 \ No newline at end of file + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install yq + run: | + pip install yq + + - name: Get required labels from release.yml + id: get-required-labels + run: | + labels=$(yq e '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml | tr '\n' ' ') + echo "required_labels=$labels" >> $GITHUB_OUTPUT + + - name: Get PR labels + id: get-pr-labels + run: | + labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") + echo "labels=$labels" >> $GITHUB_OUTPUT + + - name: Check for specific labels + id: check-label + run: | + required_labels="${{ steps.get-required-labels.outputs.required_labels }}" + pr_labels="${{ steps.get-pr-labels.outputs.labels }}" + + # Convert newline-separated strings into arrays + readarray -t required_labels_array <<< "$required_labels" + readarray -t pr_labels_array <<< "$pr_labels" + + found=false + for required_label in "${required_labels_array[@]}"; do + for pr_label in "${pr_labels_array[@]}"; do + if [[ "$required_label" == "$pr_label" ]]; then + found=true + break 2 + fi + done + done + + echo "label_exists=$found" >> $GITHUB_OUTPUT + + - name: Fail if no required labels are found + if: steps.check-label.outputs.label_exists == 'false' + run: | + echo "None of the required labels are applied to the PR." + exit 1 From 30be8da00b687808df254176e7a4bcefcc5352b7 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 28 Jun 2024 15:57:00 -0500 Subject: [PATCH 03/10] Try contructing lists differently --- .github/workflows/label-checker.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml index 6b75c79a784c..8879d57dd63b 100644 --- a/.github/workflows/label-checker.yaml +++ b/.github/workflows/label-checker.yaml @@ -25,13 +25,19 @@ jobs: - name: Get required labels from release.yml id: get-required-labels run: | - labels=$(yq e '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml | tr '\n' ' ') + labels=() + for label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do + labels+=("$label") + done echo "required_labels=$labels" >> $GITHUB_OUTPUT - name: Get PR labels id: get-pr-labels run: | - labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") + labels=() + for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH" | tr '\n' ' '); do + labels+=("$label") + done echo "labels=$labels" >> $GITHUB_OUTPUT - name: Check for specific labels @@ -40,10 +46,6 @@ jobs: required_labels="${{ steps.get-required-labels.outputs.required_labels }}" pr_labels="${{ steps.get-pr-labels.outputs.labels }}" - # Convert newline-separated strings into arrays - readarray -t required_labels_array <<< "$required_labels" - readarray -t pr_labels_array <<< "$pr_labels" - found=false for required_label in "${required_labels_array[@]}"; do for pr_label in "${pr_labels_array[@]}"; do From bfb9ca3c8269ad9cc81e44bc2c533241fb2cd09b Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 28 Jun 2024 16:02:57 -0500 Subject: [PATCH 04/10] Add echo --- .github/workflows/label-checker.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml index 8879d57dd63b..bc57c981a975 100644 --- a/.github/workflows/label-checker.yaml +++ b/.github/workflows/label-checker.yaml @@ -29,15 +29,17 @@ jobs: for label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do labels+=("$label") done + echo "Required labels: $labels" echo "required_labels=$labels" >> $GITHUB_OUTPUT - name: Get PR labels id: get-pr-labels run: | labels=() - for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH" | tr '\n' ' '); do + for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do labels+=("$label") done + echo "PR labels: $labels" echo "labels=$labels" >> $GITHUB_OUTPUT - name: Check for specific labels From fcc00e9b9a326d21ab10e0135c491800c2537491 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 28 Jun 2024 16:09:11 -0500 Subject: [PATCH 05/10] arrays are hard --- .github/workflows/label-checker.yaml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml index bc57c981a975..2f59370bc1f7 100644 --- a/.github/workflows/label-checker.yaml +++ b/.github/workflows/label-checker.yaml @@ -29,8 +29,11 @@ jobs: for label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do labels+=("$label") done - echo "Required labels: $labels" - echo "required_labels=$labels" >> $GITHUB_OUTPUT + + labels_string=$(IFS=, ; echo "${labels[*]}") + + echo "Required labels: $labels_string" + echo "required_labels=$labels_string" >> $GITHUB_OUTPUT - name: Get PR labels id: get-pr-labels @@ -39,8 +42,11 @@ jobs: for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do labels+=("$label") done - echo "PR labels: $labels" - echo "labels=$labels" >> $GITHUB_OUTPUT + + labels_string=$(IFS=, ; echo "${labels[*]}") + + echo "PR labels: $labels_string" + echo "labels=$labels_string" >> $GITHUB_OUTPUT - name: Check for specific labels id: check-label @@ -48,6 +54,9 @@ jobs: required_labels="${{ steps.get-required-labels.outputs.required_labels }}" pr_labels="${{ steps.get-pr-labels.outputs.labels }}" + IFS=',' read -r -a required_labels_array <<< "$required_labels" + IFS=',' read -r -a pr_labels_array <<< "$pr_labels" + found=false for required_label in "${required_labels_array[@]}"; do for pr_label in "${pr_labels_array[@]}"; do From d86f06b6e0ac8b8aa1be6c93fd24974fe80c5eec Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 28 Jun 2024 16:15:45 -0500 Subject: [PATCH 06/10] Do it all in one step --- .github/workflows/label-checker.yaml | 34 +++++----------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml index 2f59370bc1f7..6c1af8efaf3a 100644 --- a/.github/workflows/label-checker.yaml +++ b/.github/workflows/label-checker.yaml @@ -22,41 +22,19 @@ jobs: run: | pip install yq - - name: Get required labels from release.yml - id: get-required-labels + - name: Check for specific labels + id: check-label run: | - labels=() + required_labels=() for label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do - labels+=("$label") + required_labels+=("$label") done - labels_string=$(IFS=, ; echo "${labels[*]}") - - echo "Required labels: $labels_string" - echo "required_labels=$labels_string" >> $GITHUB_OUTPUT - - - name: Get PR labels - id: get-pr-labels - run: | - labels=() + pr_labels=() for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do - labels+=("$label") + pr_labels+=("$label") done - labels_string=$(IFS=, ; echo "${labels[*]}") - - echo "PR labels: $labels_string" - echo "labels=$labels_string" >> $GITHUB_OUTPUT - - - name: Check for specific labels - id: check-label - run: | - required_labels="${{ steps.get-required-labels.outputs.required_labels }}" - pr_labels="${{ steps.get-pr-labels.outputs.labels }}" - - IFS=',' read -r -a required_labels_array <<< "$required_labels" - IFS=',' read -r -a pr_labels_array <<< "$pr_labels" - found=false for required_label in "${required_labels_array[@]}"; do for pr_label in "${pr_labels_array[@]}"; do From aca801fa0eb742062120b1fa10e6a9bcb4d76220 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Mon, 8 Jul 2024 09:29:30 -0500 Subject: [PATCH 07/10] Move changes to existing workflow --- .github/workflows/label-check.yml | 60 +++++++++++++++------------- .github/workflows/label-checker.yaml | 54 ------------------------- 2 files changed, 32 insertions(+), 82 deletions(-) delete mode 100644 .github/workflows/label-checker.yaml diff --git a/.github/workflows/label-check.yml b/.github/workflows/label-check.yml index ad45d157bc54..06e8571ec188 100644 --- a/.github/workflows/label-check.yml +++ b/.github/workflows/label-check.yml @@ -12,32 +12,36 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check for required labels - id: label-check - run: | - LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") - REQUIRED_LABELS=("docs" "integrations" "fix" "enhancement" "feature" "maintenance") - LABEL_FOUND=false - - for label in "${REQUIRED_LABELS[@]}"; do - if echo "$LABELS" | grep -q "$label"; then - LABEL_FOUND=true - break - fi - done - - if [ "$LABEL_FOUND" = false ]; then - echo "##[error]This pull request must have one of the following labels to help with sorting for release notes:" - echo " - docs" - echo " - maintenance" - echo " - deprecation" - echo " - integrations" - echo " - fix" - echo " - enhancement" - echo " - feature" - exit 1 - fi + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install yq + run: | + pip install yq - - name: Fail the PR if no required label is found - if: steps.label-check.outputs.LABEL_FOUND == 'false' - run: exit 1 + - name: Check for specific labels + id: check-label + run: | + found=false + for required_label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do + for pr_label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do + if [[ "$required_label" == "$pr_label" ]]; then + found=true + break 2 + fi + done + done + + echo "label_exists=$found" >> $GITHUB_OUTPUT + + - name: Fail if no required labels are found + if: steps.check-label.outputs.label_exists == 'false' + run: | + echo "None of the required labels are applied to the PR." + exit 1 diff --git a/.github/workflows/label-checker.yaml b/.github/workflows/label-checker.yaml deleted file mode 100644 index 6c1af8efaf3a..000000000000 --- a/.github/workflows/label-checker.yaml +++ /dev/null @@ -1,54 +0,0 @@ -name: Check PR Labels - -on: - pull_request: - types: [opened, labeled, unlabeled, synchronize] - -jobs: - check-label: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.12" - cache: "pip" - - - name: Install yq - run: | - pip install yq - - - name: Check for specific labels - id: check-label - run: | - required_labels=() - for label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do - required_labels+=("$label") - done - - pr_labels=() - for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do - pr_labels+=("$label") - done - - found=false - for required_label in "${required_labels_array[@]}"; do - for pr_label in "${pr_labels_array[@]}"; do - if [[ "$required_label" == "$pr_label" ]]; then - found=true - break 2 - fi - done - done - - echo "label_exists=$found" >> $GITHUB_OUTPUT - - - name: Fail if no required labels are found - if: steps.check-label.outputs.label_exists == 'false' - run: | - echo "None of the required labels are applied to the PR." - exit 1 From 1e027ab1b37ade658495871449ef4868724f5185 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Mon, 8 Jul 2024 10:15:45 -0500 Subject: [PATCH 08/10] Include exclude labels --- .github/workflows/label-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-check.yml b/.github/workflows/label-check.yml index 06e8571ec188..b9fc7d912506 100644 --- a/.github/workflows/label-check.yml +++ b/.github/workflows/label-check.yml @@ -29,7 +29,7 @@ jobs: id: check-label run: | found=false - for required_label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do + for required_label in $(yq -r '(.changelog.categories[] | select(.title != "Uncategorized") | .labels[]), (.changelog.exclude.labels[])' .github/release.yml); do for pr_label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do if [[ "$required_label" == "$pr_label" ]]; then found=true From a2973242031fb61c2fcff5c12fed2d4b703d1072 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Mon, 8 Jul 2024 10:17:55 -0500 Subject: [PATCH 09/10] Add more triggers --- .github/workflows/label-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-check.yml b/.github/workflows/label-check.yml index b9fc7d912506..f7a36e685506 100644 --- a/.github/workflows/label-check.yml +++ b/.github/workflows/label-check.yml @@ -5,7 +5,7 @@ name: Ensure PR Label on: pull_request: - types: [opened, edited, labeled, unlabeled] + types: [opened, edited, labeled, unlabeled, synchronize, reopened] jobs: ensure-label: From 7a16bbd63e00841e8e76b2e92391277a5aa3798b Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Mon, 8 Jul 2024 10:19:32 -0500 Subject: [PATCH 10/10] pick d7e9f93df4 Adds check to ensure only know view paths can be passed Rename step --- .github/workflows/label-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-check.yml b/.github/workflows/label-check.yml index f7a36e685506..4cfbf6c2b1cf 100644 --- a/.github/workflows/label-check.yml +++ b/.github/workflows/label-check.yml @@ -25,7 +25,7 @@ jobs: run: | pip install yq - - name: Check for specific labels + - name: Ensure a required label is present id: check-label run: | found=false