Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.12.z] adding the PRT result and labels on github comment #1115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
adding the PRT result and labels on github comment
(cherry picked from commit 5b7e0bd)
  • Loading branch information
omkarkhatavkar authored and web-flow committed Mar 18, 2024
commit 5de233b7efaf08fc1b1107d8cb0e98bd36b16565
49 changes: 49 additions & 0 deletions .github/workflows/prt_labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Remove the PRT label, for the new commit

on:
pull_request:
types: ["synchronize"]

jobs:
prt_labels_remover:
name: remove the PRT label when amendments or new commits added to PR
runs-on: ubuntu-latest
if: "(contains(github.event.pull_request.labels.*.name, 'PRT-Passed') || contains(github.event.pull_request.labels.*.name, 'PRT-Failed'))"
steps:
- name: Avoid the race condition as PRT result will be cleaned
run: |
echo "Avoiding the race condition if prt result will be cleaned" && sleep 60

- name: Fetch the PRT status
id: prt
uses: omkarkhatavkar/wait-for-status-checks@main
with:
ref: ${{ github.head_ref }}
context: 'Robottelo-Runner'
wait-interval: 2
count: 5

- name: remove the PRT Passed/Failed label, for new commit
if: always() && ${{steps.prt.outputs.result}} == 'not_found'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CHERRYPICK_PAT }}
script: |
const prNumber = '${{ github.event.number }}';
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const labelsToRemove = ['PRT-Failed', 'PRT-Passed'];
const labelsToRemoveFiltered = labelsToRemove.filter(label => issue.data.labels.some(({ name }) => name === label));
if (labelsToRemoveFiltered.length > 0) {
await Promise.all(labelsToRemoveFiltered.map(async label => {
await github.rest.issues.removeLabel({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
name: label
});
}));
}
84 changes: 84 additions & 0 deletions .github/workflows/prt_result.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
### The prt result workflow triggered through dispatch request from CI
name: post-prt-result

# Run on workflow dispatch from CI
on:
workflow_dispatch:
inputs:
pr_number:
type: string
description: pr number for PRT run
build_number:
type: string
description: build number for PRT run
pytest_result:
type: string
description: pytest summary result line
build_status:
type: string
description: status of jenkins build e.g. success, unstable or error
prt_comment:
type: string
description: prt pytest comment triggered the PRT checks


jobs:
post-the-prt-result:
runs-on: ubuntu-latest

steps:
- name: Add last PRT result into the github comment
id: add-prt-comment
if: ${{ always() && github.event.inputs.pytest_result != '' }}
uses: thollander/actions-comment-pull-request@v2
with:
message: |
**PRT Result**
```
Build Number: ${{ github.event.inputs.build_number }}
Build Status: ${{ github.event.inputs.build_status }}
PRT Comment: ${{ github.event.inputs.prt_comment }}
Test Result : ${{ github.event.inputs.pytest_result }}
```
pr_number: ${{ github.event.inputs.pr_number }}
GITHUB_TOKEN: ${{ secrets.CHERRYPICK_PAT }}

- name: Add the PRT passed/failed labels
id: prt-status
if: ${{ always() && github.event.inputs.build_status != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CHERRYPICK_PAT }}
script: |
const prNumber = ${{ github.event.inputs.pr_number }};
const buildStatus = "${{ github.event.inputs.build_status }}";
const labelToAdd = buildStatus === "SUCCESS" ? "PRT-Passed" : "PRT-Failed";
github.rest.issues.addLabels({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [labelToAdd]
});
- name: Remove failed label on test pass or vice-versa
if: ${{ always() && github.event.inputs.build_status != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CHERRYPICK_PAT }}
script: |
const prNumber = ${{ github.event.inputs.pr_number }};
const issue = await github.rest.issues.get({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: prNumber,
});
const buildStatus = "${{ github.event.inputs.build_status }}";
const labelToRemove = buildStatus === "SUCCESS" ? "PRT-Failed" : "PRT-Passed";
const labelExists = issue.data.labels.some(({ name }) => name === labelToRemove);
if (labelExists) {
github.rest.issues.removeLabel({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
name: [labelToRemove]
});
}
Loading