Label invalid database PRs #499
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
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@v4 | |
- name: Download artifact | |
uses: dawidd6/action-download-artifact@v3 | |
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@v7 | |
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@v7 | |
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; | |
} | |
} |