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

Reading labels from env #132

Open
valentinge opened this issue Dec 20, 2020 · 3 comments
Open

Reading labels from env #132

valentinge opened this issue Dec 20, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@valentinge
Copy link

valentinge commented Dec 20, 2020

Good day,
thank you for your action. It's working like a charm but I'm struggling to achieve something that seemed quite simple on the surface: adding labels dynamically based on the PR's specific attributes.

What you want to add

I would like to be able to input more than one label dynamically using an environment variable. Something similar to the following:

...
      - name: Add labels
        uses: actions-ecosystem/action-add-labels@v1
        with:
          github_token: ${{ github.token }}
          labels: ${{ env.FILTERED_LABELS }}
...

Why this is needed

This feature will allow me to add and remove labels from an array based on conditional logic ran before the step that uses your action. Right now, the labels that I add are based on the content of a folder and are the names of the sub-folders.

PS: I looked at your source code and I saw that you're splitting the input by \n and then you're adding the result as labels. This seemed very simple to replicate in my input but I failed numerous times. The code that, I think, was closest to the solution was the following:

for i in "${folders[@]}"
do
  if [[ "$branch_name" == *"$i"* ]]; then
    filtered_labels+="$i\\n"
  fi
done

echo "FILTERED_LABELS=$( echo $filtered_labels)" >> $GITHUB_ENV

where the output was folderone\nfoldertwo\n and the result was the addition of one label folderone\nfoldertwo\n.

Thank you again for your awesome job.

@sarina
Copy link
Contributor

sarina commented Apr 21, 2022

@valentinge I just used this action to dynamically add labels based on comments from users. You may be able to use the run context to inject your labels into the $GITHUB_ENV and then use those lists in other steps (I'm not exactly sure what you're trying to do). Take a look: https://github.com/openedx/build-test-release-wg/blob/main/.github/workflows/label-on-comment.yml

@Ismoh
Copy link

Ismoh commented Jul 4, 2022

@sarina link is broken, fyi

@sarina
Copy link
Contributor

sarina commented Jul 6, 2022

Ah thanks, yes we did some refactoring into a reusable workflow. it's now here: https://github.com/openedx/.github/blob/master/.github/workflows/add-remove-label-on-comment.yml

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

No branches or pull requests

3 participants