-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: VaniHaripriya <[email protected]>
- Loading branch information
1 parent
1bd0f4a
commit a2be651
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# This workflow adds the 'ci-passed' label to a pull request once the 'CI Check' workflow completes successfully. | ||
# Resets the 'ci-passed' label status when a pull request is synchronized or reopened, | ||
# indicating that changes have been pushed and CI needs to rerun. | ||
name: Add CI Passed Label | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["CI Check"] | ||
types: | ||
- completed | ||
|
||
permissions: | ||
pull-requests: write | ||
checks: read | ||
actions: read | ||
|
||
jobs: | ||
fetch_data: | ||
name: Fetch workflow payload | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
outputs: | ||
pr_number: ${{ steps.extract.outputs.pr_number }} | ||
event_action: ${{ steps.extract.outputs.event_action }} | ||
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)); | ||
- name: Unzip artifact | ||
run: unzip pr.zip | ||
|
||
- name: Extract PR information | ||
id: extract | ||
run: | | ||
pr_number=$(cat ./pr_number) | ||
event_action=$(cat ./event_action) | ||
echo "pr_number=${pr_number}" >> $GITHUB_OUTPUT | ||
echo "event_action=${event_action}" >> $GITHUB_OUTPUT | ||
reset_ci_passed_label: | ||
name: Reset 'ci-passed' label on PR Synchronization | ||
runs-on: ubuntu-latest | ||
needs: fetch_data | ||
steps: | ||
- name: Check and reset label | ||
run: | | ||
if [[ "${{ needs.fetch_data.outputs.event_action }}" == "synchronize" || "${{ needs.fetch_data.outputs.event_action }}" == "reopened" ]]; then | ||
echo "Resetting 'ci-passed' label as changes were pushed (event: ${{ needs.fetch_data.outputs.event_action }})." | ||
gh pr edit ${{ needs.fetch_data.outputs.pr_number }} --remove-label "ci-passed" --repo $GITHUB_REPOSITORY || echo "Label not present" | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
add_ci_passed_label: | ||
name: Add 'ci-passed' label | ||
runs-on: ubuntu-latest | ||
needs: fetch_data | ||
steps: | ||
- name: Add 'ci-passed' label | ||
run: | | ||
echo "Adding 'ci-passed' label to PR #${{ needs.fetch_data.outputs.pr_number }}" | ||
gh pr edit ${{ needs.fetch_data.outputs.pr_number }} --add-label "ci-passed" --repo $GITHUB_REPOSITORY | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# This workflow checks if all CI checks have passed by polling every 5 minutes for a total of 8 attempts. | ||
name: CI Check | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened, labeled] | ||
|
||
jobs: | ||
check_ci_status: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: read | ||
pull-requests: write | ||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for 'needs-ok-to-test' and 'ok-to-test' labels | ||
id: label_check | ||
run: | | ||
LABELS=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name') | ||
if echo "$LABELS" | grep -q 'needs-ok-to-test'; then | ||
echo "Label 'needs-ok-to-test' found. Skipping the workflow." | ||
exit 0 | ||
fi | ||
if echo "$LABELS" | grep -q 'ok-to-test'; then | ||
echo "Label 'ok-to-test' found. Continuing the workflow." | ||
else | ||
echo "Label 'ok-to-test' not found. Skipping the workflow." | ||
exit 0 | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Check if all CI checks passed | ||
uses: wechuli/allcheckspassed@0b68b3b7d92e595bcbdea0c860d05605720cf479 | ||
with: | ||
delay: '5' | ||
retries: '8' | ||
polling_interval: '5' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Save PR payload | ||
shell: bash | ||
run: | | ||
mkdir -p ./pr | ||
echo ${{ github.event.pull_request.number }} >> ./pr/pr_number | ||
echo ${{ github.event.action }} >> ./pr/event_action | ||
- uses: actions/[email protected] | ||
with: | ||
name: pr | ||
path: pr/ |