Skip to content

Remove path parts from component label suffixes #38622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/shorten-labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: workflow

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove path parts from component label suffixes

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [38527]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
316 changes: 316 additions & 0 deletions .github/component_labels.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ jobs:
run: |
make gendistributions
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)
- name: Gen labels
run: |
make genlabels
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)
- name: CodeGen
run: |
make generate
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/scripts/add-codeowners-to-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,17 @@ main () {
REVIEWERS+=$(echo -n "${OWNER}" | sed -E 's/@(.+)/"\1"/')
done

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

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

if [[ -n "${LABELS}" ]]; then
LABELS+=","
fi
LABELS+="${COMPONENT_NAME}"
LABELS+="${LABEL_NAME}"
done
done

Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/scripts/add-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ for LABEL_REQ in ${LABELS}; do
continue
fi

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

if [[ ${RESULT} = 0 ]]; then
echo "\"${LABEL}\" doesn't correspond to a component, skipping."
if [[ -z "${SHORT_LABEL}" ]]; then
echo "\"${SHORT_LABEL}\" doesn't correspond to a component, skipping."
continue
fi

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

# Labels added by a GitHub Actions workflow don't trigger other workflows
# by design, so we have to manually ping code owners here.
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/scripts/generate-component-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ COLORS["testbed"]="#336600"

FALLBACK_COLOR="#999966"

CUR_DIRECTORY=$(dirname "$0")
COMPONENTS=$(sh "${CUR_DIRECTORY}/get-components.sh")

for COMPONENT in ${COMPONENTS}; do
TYPE=$(echo "${COMPONENT}" | cut -f1 -d '/' )
LABEL_NAME=$(echo "${COMPONENT}" | sed -E 's%^(.+)/(.+)\1%\1/\2%')
COMPONENTS=$(awk '/^[^#]/ { print $2 }' .github/component_labels.txt)

for LABEL_NAME in ${COMPONENTS}; do
TYPE=$(echo "${LABEL_NAME}" | cut -f1 -d '/' )

if (( "${#LABEL_NAME}" > 50 )); then
echo "'${LABEL_NAME}' exceeds GitHubs 50-character limit on labels, skipping"
continue
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/mark-issues-as-stale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ for ISSUE in ${ISSUES}; do
LABELS=$(gh issue view "${ISSUE}" --json labels --jq '.labels.[].name')

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

if [[ -z "${OWNERS}" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/ping-codeowners-issues.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [[ -z "${COMPONENT:-}" || -z "${ISSUE:-}" ]]; then
fi

CUR_DIRECTORY=$(dirname "$0")

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

if [[ -z "${OWNERS}" ]]; then
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/scripts/ping-codeowners-on-new-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ if [[ -n "${TITLE_COMPONENT}" && ! ("${TITLE_COMPONENT}" =~ " ") ]]; then
if [[ -n "${CODEOWNERS}" ]]; then
PING_LINES+="- ${TITLE_COMPONENT}: ${CODEOWNERS}\n"
PINGED_COMPONENTS["${TITLE_COMPONENT}"]=1

if (( "${#TITLE_COMPONENT}" <= 50 )); then
LABELS+="${TITLE_COMPONENT}"
LABEL_NAME=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt)
if (( "${#LABEL_NAME}" <= 50 )); then
LABELS+="${LABEL_NAME}"
else
echo "'${TITLE_COMPONENT}' exceeds GitHub's 50-character limit, skipping adding a label"
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit, skipping adding a label"
fi
fi
fi
Expand All @@ -55,16 +55,16 @@ for COMPONENT in ${BODY_COMPONENTS}; do

PING_LINES+="- ${COMPONENT}: ${CODEOWNERS}\n"
PINGED_COMPONENTS["${COMPONENT}"]=1

if (( "${#COMPONENT}" > 50 )); then
echo "'${COMPONENT}' exceeds GitHub's 50-character limit on labels, skipping adding a label"
LABEL_NAME=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt)
if (( "${#LABEL_NAME}" > 50 )); then
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit on labels, skipping adding a label"
continue
fi

if [[ -n "${LABELS}" ]]; then
LABELS+=","
fi
LABELS+="${COMPONENT}"
LABELS+="${LABEL_NAME}"
fi
done

Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ stability-tests: otelcontribcol
@echo Stability tests are disabled until we have a stable performance environment.
@echo To enable the tests replace this echo by $(MAKE) -C testbed run-stability-tests

.PHONY: genlabels
genlabels:
@echo "Generating path-to-label mappings..."
@echo "# This file is auto-generated. Do not edit manually." > .github/component_labels.txt
@grep -E '^[A-Za-z0-9/]' .github/CODEOWNERS | \
awk '{ print $$1 }' | \
sed -E 's%(.+)/$$%\1%' | \
while read -r COMPONENT; do \
LABEL_NAME=$$(printf '%s\n' "$${COMPONENT}" | sed -E 's%^(.+)/(.+)\1%\1/\2%'); \
if (( $${#LABEL_NAME} > 50 )); then \
OIFS=$${IFS}; \
IFS='/'; \
for SEGMENT in $${COMPONENT}; do \
r="/$${SEGMENT}\$$"; \
if [[ "$${COMPONENT}" =~ $${r} ]]; then \
break; \
fi; \
LABEL_NAME=$$(echo "$${LABEL_NAME}" | sed -E "s%^(.+)$${SEGMENT}\$$%\1%"); \
done; \
IFS=$${OIFS}; \
fi; \
echo "$${COMPONENT} $${LABEL_NAME}" >> .github/component_labels.txt; \
done
@echo "Labels generated and saved to .github/component_labels.txt"

.PHONY: gogci
gogci:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="gci"
Expand Down Expand Up @@ -348,6 +373,7 @@ gendistributions: $(GITHUBGEN)

.PHONY: update-codeowners
update-codeowners: generate gengithub
$(MAKE) genlabels

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