name: Pull request labels
on:
pull_request_target:
types: [labeled, unlabeled, synchronize]
jobs:
check-labels:
name: 'check labels'
runs-on: ubuntu-latest
steps:
- name: Check if version label is present
id: version
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const versionLabels = [
'Action: no bump',
'Action: beta bump',
'Action: patch bump',
'Action: minor bump',
'Action: major bump',
];
const { data: labels } = await github.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
per_page: 100,
});
const versionLabelsPresent = labels
.filter(label => versionLabels.includes(label.name))
if (versionLabelsPresent.length === 1) {
console.log(`::set-output name=versionLabel::${versionLabelsPresent[0].name}`)
return;
}
console.log(`::debug ::${versionLabelsPresent.length} matching labels`);
throw new Error(`Should have one and only one of ${versionLabels.join(', ')} labels`);