[STRATCONN-3623] - Adds github actions workflow to label PRs #5
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: | |
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/compute-labels.js') | |
await script({github, context, core}) | |
- 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 } = process.env | |
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); | |
} |