Reading labels from env
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.
@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
@sarina link is broken, fyi
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