Skip to content
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

Dynamic label creation from path #708

Open
mwarkentin opened this issue Nov 24, 2023 · 2 comments
Open

Dynamic label creation from path #708

mwarkentin opened this issue Nov 24, 2023 · 2 comments
Labels
feature request New feature or request to improve the current logic

Comments

@mwarkentin
Copy link

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.

@mwarkentin mwarkentin added feature request New feature or request to improve the current logic needs triage labels Nov 24, 2023
@MaksimZhukov
Copy link
Contributor

MaksimZhukov commented Nov 24, 2023

Hello @mwarkentin! Thank you!
We will consider adding this feature and will contact you as soon as we have any updates!

@elfaraorigo
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

No branches or pull requests

3 participants