Skip to content

Commit 47ce02a

Browse files
authored
Remove path parts from component label suffixes (#38622)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description To generate labels for all components, including those with paths longer than 50 characters: In the root Makefile, a phony target is created to generate the .github/component_labels file, which contains the component paths and their corresponding labels (shortened paths for those exceeding 50 characters by removing repeated patterns in the string). The file is space-delimited. In the build-and-test workflow, under the checks job, a step is added to verify that the .github/component_labels file exists. The scripts used in the workflows are adjusted to use the .github/component_labels file as a reference for mappings between component paths and their labels. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #38527
1 parent 2a3b229 commit 47ce02a

10 files changed

+395
-27
lines changed

.chloggen/shorten-labels.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: workflow
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Remove path parts from component label suffixes
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [38527]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

.github/component_labels.txt

+316
Large diffs are not rendered by default.

.github/workflows/build-and-test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ jobs:
220220
run: |
221221
make gendistributions
222222
git diff -s --exit-code || (echo 'Generated code is out of date, please run "make gendistributions" and commit the changes in this PR.' && exit 1)
223+
- name: Gen labels
224+
run: |
225+
make genlabels
226+
git diff -s --exit-code || (echo '.github/component_labels.txt is out of date, please run "make genlabels" and commit the changes in this PR.' && exit 1)
223227
- name: CodeGen
224228
run: |
225229
make generate

.github/workflows/scripts/add-codeowners-to-pr.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ main () {
9090
REVIEWERS+=$(echo -n "${OWNER}" | sed -E 's/@(.+)/"\1"/')
9191
done
9292

93-
# Convert the CODEOWNERS entry to a label
94-
COMPONENT_NAME=$(echo -n "${COMPONENT}" | sed -E 's%^(.+)/(.+)\1%\1/\2%')
93+
LABEL_NAME="$(awk -v path="${COMPONENT}" '$1 == path {print $2}' .github/component_labels.txt)"
9594

96-
if (( "${#COMPONENT_NAME}" > 50 )); then
97-
echo "'${COMPONENT_NAME}' exceeds GitHub's 50-character limit on labels, skipping adding label"
95+
if (( "${#LABEL_NAME}" > 50 )); then
96+
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit on labels, skipping adding label"
9897
continue
9998
fi
10099

101100
if [[ -n "${LABELS}" ]]; then
102101
LABELS+=","
103102
fi
104-
LABELS+="${COMPONENT_NAME}"
103+
LABELS+="${LABEL_NAME}"
105104
done
106105
done
107106

.github/workflows/scripts/add-labels.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ for LABEL_REQ in ${LABELS}; do
5858
continue
5959
fi
6060

61-
# Grep exits with status code 1 if there are no matches,
62-
# so we manually set RESULT to 0 if nothing is found.
63-
RESULT=$(grep -c "${LABEL}" .github/CODEOWNERS || true)
61+
SHORT_LABEL=$(awk -v path="${LABEL}" '$1 == path || $2 == path {print $2}' .github/component_labels.txt)
6462

65-
if [[ ${RESULT} = 0 ]]; then
66-
echo "\"${LABEL}\" doesn't correspond to a component, skipping."
63+
if [[ -z "${SHORT_LABEL}" ]]; then
64+
echo "\"${SHORT_LABEL}\" doesn't correspond to a component, skipping."
6765
continue
6866
fi
6967

7068
if [[ ${SHOULD_ADD} = true ]]; then
71-
gh issue edit "${ISSUE}" --add-label "${LABEL}"
69+
gh issue edit "${ISSUE}" --add-label "${SHORT_LABEL}"
7270

7371
# Labels added by a GitHub Actions workflow don't trigger other workflows
7472
# by design, so we have to manually ping code owners here.

.github/workflows/scripts/generate-component-labels.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ COLORS["testbed"]="#336600"
2323

2424
FALLBACK_COLOR="#999966"
2525

26-
CUR_DIRECTORY=$(dirname "$0")
27-
COMPONENTS=$(sh "${CUR_DIRECTORY}/get-components.sh")
28-
29-
for COMPONENT in ${COMPONENTS}; do
30-
TYPE=$(echo "${COMPONENT}" | cut -f1 -d '/' )
31-
LABEL_NAME=$(echo "${COMPONENT}" | sed -E 's%^(.+)/(.+)\1%\1/\2%')
26+
COMPONENTS=$(awk '/^[^#]/ { print $2 }' .github/component_labels.txt)
3227

28+
for LABEL_NAME in ${COMPONENTS}; do
29+
TYPE=$(echo "${LABEL_NAME}" | cut -f1 -d '/' )
30+
3331
if (( "${#LABEL_NAME}" > 50 )); then
3432
echo "'${LABEL_NAME}' exceeds GitHubs 50-character limit on labels, skipping"
3533
continue

.github/workflows/scripts/mark-issues-as-stale.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ for ISSUE in ${ISSUES}; do
4545
LABELS=$(gh issue view "${ISSUE}" --json labels --jq '.labels.[].name')
4646

4747
for LABEL in ${LABELS}; do
48-
COMPONENT="${LABEL}"
48+
COMPONENT=$(awk -v path="${LABEL}" '$1 == path || $2 == path {print $1}' .github/component_labels.txt)
4949
OWNERS=$(COMPONENT=${LABEL} bash "${CUR_DIRECTORY}/get-codeowners.sh")
5050

5151
if [[ -z "${OWNERS}" ]]; then

.github/workflows/scripts/ping-codeowners-issues.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [[ -z "${COMPONENT:-}" || -z "${ISSUE:-}" ]]; then
1313
fi
1414

1515
CUR_DIRECTORY=$(dirname "$0")
16-
16+
COMPONENT=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $1}' .github/component_labels.txt)
1717
OWNERS=$(COMPONENT="${COMPONENT}" bash "${CUR_DIRECTORY}/get-codeowners.sh")
1818

1919
if [[ -z "${OWNERS}" ]]; then

.github/workflows/scripts/ping-codeowners-on-new-issue.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ if [[ -n "${TITLE_COMPONENT}" && ! ("${TITLE_COMPONENT}" =~ " ") ]]; then
3333
if [[ -n "${CODEOWNERS}" ]]; then
3434
PING_LINES+="- ${TITLE_COMPONENT}: ${CODEOWNERS}\n"
3535
PINGED_COMPONENTS["${TITLE_COMPONENT}"]=1
36-
37-
if (( "${#TITLE_COMPONENT}" <= 50 )); then
38-
LABELS+="${TITLE_COMPONENT}"
36+
LABEL_NAME=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt)
37+
if (( "${#LABEL_NAME}" <= 50 )); then
38+
LABELS+="${LABEL_NAME}"
3939
else
40-
echo "'${TITLE_COMPONENT}' exceeds GitHub's 50-character limit, skipping adding a label"
40+
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit, skipping adding a label"
4141
fi
4242
fi
4343
fi
@@ -55,16 +55,16 @@ for COMPONENT in ${BODY_COMPONENTS}; do
5555

5656
PING_LINES+="- ${COMPONENT}: ${CODEOWNERS}\n"
5757
PINGED_COMPONENTS["${COMPONENT}"]=1
58-
59-
if (( "${#COMPONENT}" > 50 )); then
60-
echo "'${COMPONENT}' exceeds GitHub's 50-character limit on labels, skipping adding a label"
58+
LABEL_NAME=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt)
59+
if (( "${#LABEL_NAME}" > 50 )); then
60+
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit on labels, skipping adding a label"
6161
continue
6262
fi
6363

6464
if [[ -n "${LABELS}" ]]; then
6565
LABELS+=","
6666
fi
67-
LABELS+="${COMPONENT}"
67+
LABELS+="${LABEL_NAME}"
6868
fi
6969
done
7070

Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ stability-tests: otelcontribcol
114114
@echo Stability tests are disabled until we have a stable performance environment.
115115
@echo To enable the tests replace this echo by $(MAKE) -C testbed run-stability-tests
116116

117+
.PHONY: genlabels
118+
genlabels:
119+
@echo "Generating path-to-label mappings..."
120+
@echo "# This file is auto-generated. Do not edit manually." > .github/component_labels.txt
121+
@grep -E '^[A-Za-z0-9/]' .github/CODEOWNERS | \
122+
awk '{ print $$1 }' | \
123+
sed -E 's%(.+)/$$%\1%' | \
124+
while read -r COMPONENT; do \
125+
LABEL_NAME=$$(printf '%s\n' "$${COMPONENT}" | sed -E 's%^(.+)/(.+)\1%\1/\2%'); \
126+
if (( $${#LABEL_NAME} > 50 )); then \
127+
OIFS=$${IFS}; \
128+
IFS='/'; \
129+
for SEGMENT in $${COMPONENT}; do \
130+
r="/$${SEGMENT}\$$"; \
131+
if [[ "$${COMPONENT}" =~ $${r} ]]; then \
132+
break; \
133+
fi; \
134+
LABEL_NAME=$$(echo "$${LABEL_NAME}" | sed -E "s%^(.+)$${SEGMENT}\$$%\1%"); \
135+
done; \
136+
IFS=$${OIFS}; \
137+
fi; \
138+
echo "$${COMPONENT} $${LABEL_NAME}" >> .github/component_labels.txt; \
139+
done
140+
@echo "Labels generated and saved to .github/component_labels.txt"
141+
117142
.PHONY: gogci
118143
gogci:
119144
$(MAKE) $(FOR_GROUP_TARGET) TARGET="gci"
@@ -348,6 +373,7 @@ gendistributions: $(GITHUBGEN)
348373

349374
.PHONY: update-codeowners
350375
update-codeowners: generate gengithub
376+
$(MAKE) genlabels
351377

352378
FILENAME?=$(shell git branch --show-current)
353379
.PHONY: chlog-new

0 commit comments

Comments
 (0)