[Sendgrid[ - fixing variable parsing to handle text between "" and '' #2542
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow labels PRs based on the files that were changed. It uses a custom script to this | |
# instead of actions/labeler as few of the tags are more than just file changes. | |
name: Label PRs | |
on: | |
pull_request_target: | |
types: [opened, synchronize, reopened] | |
jobs: | |
pr-labeler: | |
runs-on: ubuntu-20.04 | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Compute Labels | |
id: compute-labels | |
uses: actions/github-script@v7 | |
with: | |
# Required for the script to access team membership information. | |
# Scope: members:read and contentes:read permission on the organization. | |
github-token: ${{ secrets.GH_PAT_MEMBER_AND_PULL_REQUEST_READONLY }} | |
script: | | |
const script = require('./scripts/github-action/compute-labels.js') | |
await script({github, context, core}) | |
# Separating apply labels to separate step to avoid using PAT token auth. | |
- name: Apply Labels | |
uses: actions/github-script@v7 | |
env: | |
labelsToAdd: '${{ steps.compute-labels.outputs.add }}' | |
labelsToRemove: '${{ steps.compute-labels.outputs.remove }}' | |
with: | |
script: | | |
const { labelsToAdd, labelsToRemove, DRY_RUN } = process.env | |
if(Boolean(DRY_RUN)){ | |
core.info(`Would have added labels: ${labelsToAdd}`) | |
core.info(`Would have removed labels: ${labelsToRemove}`) | |
return | |
} | |
if(labelsToAdd.length > 0) { | |
await github.rest.issues.addLabels({ | |
issue_number: context.payload.pull_request.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: labelsToAdd.split(',') | |
}); | |
} | |
if(labelsToRemove.length > 0) { | |
const requests = labelsToRemove.split(',').map(label => { | |
return github.rest.issues.removeLabel({ | |
issue_number: context.payload.pull_request.number, | |
name: label, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
}); | |
await Promise.all(requests); | |
} |