Dynamic label creation from path
Description: We have a directory structure in our repo which looks like this:
k8s
|-> services
|-> analytics
|-> catalog
|-> consul
...
It would be great if I could define a "matcher" pattern that could pull part of the path out, and use that in the label name.
k8s/service/[service]:
- k8s/services/**[service]/*
Justification:
This would give us a way to automatically label services without having to remember to update the labeler.yml file each time we add a new path.
Are you willing to submit a PR? Don't have time right now, just an idea.
Hello @mwarkentin! Thank you! We will consider adding this feature and will contact you as soon as we have any updates!
@mwarkentin we were looking into a similar issue where we wanted labels based on folders
Temporarily solved it like this until some future version of labeler presents a better option
- name: Update labeler.yml
run: |
find infrastructure -type d | grep -v '/\.' | awk -F'/' 'NF>2' | jq -R -s -c 'split("\n")[:-1]' > folders.json
touch ${{ env.yamlfile }}
echo "Add defaults to ${{ env.yamlfile }}"
cat > ${{ env.yamlfile }} << EOF
workflow-change:
- changed-files:
- any-glob-to-any-file: '.github/workflows/*'
EOF
echo "Add dynamic folder labels to ${{ env.yamlfile }}"
jq -r '.[] | select(startswith("infrastructure"))' folders.json | while read folder; do
label="${folder#infrastructure/}"
label="${label//\//-}"
label="${label//production/prd}"
label="${label//staging/stg}"
if [ "${#label}" -gt 63 ]; then
echo "Label is longer than 63 characters: $label"
label="${label:0:63}"
echo "Trimmed label to 63 characters: $label"
else
echo "- $folder -> $label"
fi
echo "- $folder -> $label"
cat >> ${{ env.yamlfile }} << EOF
$label:
- changed-files:
- any-glob-to-any-file: '$folder/*'
EOF
done
echo "Output file"
cat ${{ env.yamlfile }}
shell: bash
- uses: actions/labeler@v5
with:
sync-labels: true
Could probably be cleaned up a bit more, but it does its job for now
This would be great to have! We have central repos that constantly get new applications/folders and being able to dynamically create new labels based on the folder path would be a big boon.