Pull Requests Status Labels #36
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: Pull Requests Status Labels | |
on: | |
workflow_run: | |
workflows: ['Lints'] | |
types: | |
- completed | |
jobs: | |
label: | |
name: Add jobs labels | |
runs-on: ubuntu-latest | |
if: > | |
${{ github.event.workflow_run.event == 'pull_request' }} | |
steps: | |
- name: 'Download artifact' | |
uses: actions/[email protected] | |
with: | |
script: | | |
var artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{ github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "pr" | |
})[0]; | |
var download = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); | |
- run: unzip pr.zip | |
- name: 'Set labels' | |
uses: actions/[email protected] | |
with: | |
script: | | |
var fs = require('fs'); | |
var issue_number = Number(fs.readFileSync('./NR')); | |
var jobs = await github.actions.listJobsForWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{ github.event.workflow_run.id }}, | |
}) | |
var labels = { | |
failure: [], | |
success: [] | |
} | |
for (const job of jobs.data.jobs) { | |
var match = job.name.match(/\(([^)]+)\)/) | |
var label = match && match[1] | |
if (label) { labels[job.conclusion].push(label) } | |
} | |
if (labels.failure.length > 0) { | |
await github.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
labels: labels.failure | |
}).catch((e) => { | |
console.error(`Cannot add labels ${labels}: ${e.message}`) | |
}) | |
} | |
for (const label of labels.success) { | |
await github.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
name: label | |
}).catch((e) => { | |
console.error(`Cannot remove label ${label}: ${e.message}`) | |
}) | |
} |