Skip to content

Commit 4ccb047

Browse files
test: Integrate Git Hub Action Results into Tide (#11262)
Signed-off-by: vmudadla <vmudadla@redhat.com>
1 parent 1550b36 commit 4ccb047

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This workflow adds the 'ci-passed' label to a pull request once the 'CI Check' workflow completes successfully.
2+
# Resets the 'ci-passed' label status when a pull request is synchronized or reopened,
3+
# indicating that changes have been pushed and CI needs to rerun.
4+
name: Add CI Passed Label
5+
6+
on:
7+
workflow_run:
8+
workflows: ["CI Check"]
9+
types:
10+
- completed
11+
12+
permissions:
13+
pull-requests: write
14+
checks: read
15+
actions: read
16+
17+
jobs:
18+
fetch_data:
19+
name: Fetch workflow payload
20+
runs-on: ubuntu-latest
21+
if: >
22+
github.event.workflow_run.event == 'pull_request' &&
23+
github.event.workflow_run.conclusion == 'success'
24+
outputs:
25+
pr_number: ${{ steps.extract.outputs.pr_number }}
26+
event_action: ${{ steps.extract.outputs.event_action }}
27+
steps:
28+
- name: 'Download artifact'
29+
uses: actions/github-script@v3.1.0
30+
with:
31+
script: |
32+
var artifacts = await github.actions.listWorkflowRunArtifacts({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
run_id: ${{github.event.workflow_run.id}},
36+
});
37+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
38+
return artifact.name == "pr"
39+
})[0];
40+
var download = await github.actions.downloadArtifact({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
artifact_id: matchArtifact.id,
44+
archive_format: 'zip',
45+
});
46+
var fs = require('fs');
47+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
48+
49+
- name: Unzip artifact
50+
run: unzip pr.zip
51+
52+
- name: Extract PR information
53+
id: extract
54+
run: |
55+
pr_number=$(cat ./pr_number)
56+
event_action=$(cat ./event_action)
57+
echo "pr_number=${pr_number}" >> $GITHUB_OUTPUT
58+
echo "event_action=${event_action}" >> $GITHUB_OUTPUT
59+
60+
add_ci_passed_label:
61+
name: Add 'ci-passed' label
62+
runs-on: ubuntu-latest
63+
needs: fetch_data
64+
steps:
65+
- name: Add 'ci-passed' label
66+
run: |
67+
echo "Adding 'ci-passed' label to PR #${{ needs.fetch_data.outputs.pr_number }}"
68+
gh pr edit ${{ needs.fetch_data.outputs.pr_number }} --add-label "ci-passed" --repo $GITHUB_REPOSITORY
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
72+
reset_ci_passed_label:
73+
name: Reset 'ci-passed' label on PR Synchronization
74+
runs-on: ubuntu-latest
75+
needs: fetch_data
76+
steps:
77+
- name: Check and reset label
78+
run: |
79+
if [[ "${{ needs.fetch_data.outputs.event_action }}" == "synchronize" || "${{ needs.fetch_data.outputs.event_action }}" == "reopened" ]]; then
80+
echo "Resetting 'ci-passed' label as changes were pushed (event: ${{ needs.fetch_data.outputs.event_action }})."
81+
gh pr edit ${{ needs.fetch_data.outputs.pr_number }} --remove-label "ci-passed" --repo $GITHUB_REPOSITORY || echo "Label not present"
82+
fi
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci-checks.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow checks if all CI checks have passed by polling every 5 minutes for a total of 7 attempts.
2+
name: CI Check
3+
4+
on:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
check_ci_status:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
checks: read
13+
pull-requests: write
14+
steps:
15+
- name: Check if all CI checks passed
16+
uses: wechuli/allcheckspassed@0b68b3b7d92e595bcbdea0c860d05605720cf479
17+
with:
18+
delay: '5'
19+
retries: '7'
20+
polling_interval: '5'
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
- name: Save PR payload
24+
shell: bash
25+
run: |
26+
mkdir -p ./pr
27+
echo ${{ github.event.pull_request.number }} >> ./pr/pr_number
28+
echo ${{ github.event.action }} >> ./pr/event_action
29+
- uses: actions/upload-artifact@v3.1.0
30+
with:
31+
name: pr
32+
path: pr/

0 commit comments

Comments
 (0)