Skip to content

Label invalid database PRs #267

Label invalid database PRs

Label invalid database PRs #267

name: Label invalid database PRs
on:
workflow_run:
workflows: ["Check derivatives change"]
types:
- completed
permissions:
contents: read
pull-requests: write
jobs:
labelInvalidPRs:
runs-on: ubuntu-latest
name: Add/Remove 'invalid' label from trigger PR
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
name: check_derivatives_change
workflow: check_derivatives_change.yml
run_id: ${{github.event.workflow_run.id }}
- name: Retrieve trigger PR issue number from artifacts
id: changed
run: |
issue_number=`cat issue_number`
echo "issue_number=${issue_number}" >> "${GITHUB_OUTPUT}"
- name: Add 'invalid' label if trigger PR check failed
if: github.event.workflow_run.conclusion == 'failure'
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.changed.outputs.issue_number }},
labels: ['invalid']
})
- name: Remove 'invalid' label if trigger PR check was successful
if: github.event.workflow_run.conclusion == 'success'
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.changed.outputs.issue_number }},
name: 'invalid'
});
} catch (err) {
if (err.status === 404 && err.message === "Label does not exist") {
console.log("Label not found");
} else {
throw err;
}
}