Skip to content

Apply Test Labels #249188

Apply Test Labels

Apply Test Labels #249188

Workflow file for this run

name: Apply Test Labels
on:
workflow_run:
workflows: ["astyle", "JSON Validation", "General build matrix"]
types: [completed]
jobs:
labeling:
if: >-
github.repository == 'CleverRaven/Cataclysm-DDA' &&
github.event.workflow_run.event == 'pull_request' &&
(github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')
runs-on: ubuntu-latest
steps:
- name: setLabel
id: setLabel
run: |
if [[ "${GITHUB_EVENT_WORKFLOW_RUN_NAME}" == "astyle" ]]; then
echo "label=astyled" >> $GITHUB_OUTPUT
fi
if [[ "${GITHUB_EVENT_WORKFLOW_RUN_NAME}" == "JSON Validation" ]]; then
echo "label=json-styled" >> $GITHUB_OUTPUT
fi
if [[ "${GITHUB_EVENT_WORKFLOW_RUN_NAME}" == "General build matrix" ]]; then
echo "label=BasicBuildPassed" >> $GITHUB_OUTPUT
fi
if [[ "${GITHUB_EVENT_WORKFLOW_RUN_NAME}" == "IWYU (include-what-you-use)" ]]; then
echo "label=IWYUPassed" >> $GITHUB_OUTPUT
fi
if [[ "${GITHUB_EVENT_WORKFLOW_RUN_NAME}" == "build-clang-tidy" ]]; then
echo "label=ClangPassed" >> $GITHUB_OUTPUT
fi
env:
GITHUB_EVENT_WORKFLOW_RUN_NAME: ${{ github.event.workflow_run.name }}
- name: Download success artifact from basic build
if: ${{ github.event.workflow_run.name == 'General build matrix' }}
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # v3.1.4
with:
workflow: ${{ github.event.workflow_run.name }}
run_id: ${{ github.event.workflow_run.id }}
name: basic-build
allow_forks: false
if_no_artifact_found: warn
- name: set-basic-build-success
id: set-basic-build-success
run: |
if [[ -f basic-build ]]; then
echo "basic-build-success=$( cat basic-build )" >> $GITHUB_OUTPUT
else
echo "basic-build-success=false" >> $GITHUB_OUTPUT
fi
- name: Download pr id artifact
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # v3.1.4
with:
workflow: ${{ github.event.workflow_run.name }}
run_id: ${{ github.event.workflow_run.id }}
name: pull_request_id
allow_forks: false
if_no_artifact_found: warn
- name: set-pr-id
id: set-pr-id
run: |
if [[ -f pull_request_id ]]; then
echo "pr-id=$( cat pull_request_id )" >> $GITHUB_OUTPUT
else
echo "pr-id=" >> $GITHUB_OUTPUT
fi
- name: set-label
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.conclusion != 'skipped' || steps.set-basic-build-success.outputs.basic-build-success == 'true' }}
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
if ('${{ steps.set-pr-id.outputs.pr-id }}'.trim().length == 0) {
console.log("The PR ID artifact does not contain a pull request number.")
} else {
github.rest.issues.addLabels({
issue_number: ${{ steps.set-pr-id.outputs.pr-id }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['${{ steps.setLabel.outputs.label }}']
})
}
- name: remove-label
if: ${{ github.event.workflow_run.conclusion == 'failure' && steps.set-basic-build-success.outputs.basic-build-success != 'true' }}
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
if ('${{ steps.set-pr-id.outputs.pr-id }}'.trim().length == 0) {
console.log("The PR ID artifact does not contain a pull request number.")
} else {
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
issue_number: ${{ steps.set-pr-id.outputs.pr-id }},
owner: context.repo.owner,
repo: context.repo.repo,
});
const labelName = '${{ steps.setLabel.outputs.label }}';
if (labels.some(l => l.name === labelName)) {
await github.rest.issues.removeLabel({
issue_number: ${{ steps.set-pr-id.outputs.pr-id }},
owner: context.repo.owner,
repo: context.repo.repo,
name: labelName
});
} else {
console.log(`Label "${labelName}" not present on PR, skipping removal.`);
}
}