-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Integrate Git Hub Action Results into Tide (#11262)
Signed-off-by: vmudadla <[email protected]>
- Loading branch information
1 parent
1550b36
commit 4ccb047
Showing
2 changed files
with
116 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 | ||
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 }} | ||
|
||
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 }} |
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,32 @@ | ||
# This workflow checks if all CI checks have passed by polling every 5 minutes for a total of 7 attempts. | ||
name: CI Check | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
check_ci_status: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: read | ||
pull-requests: write | ||
steps: | ||
- name: Check if all CI checks passed | ||
uses: wechuli/allcheckspassed@0b68b3b7d92e595bcbdea0c860d05605720cf479 | ||
with: | ||
delay: '5' | ||
retries: '7' | ||
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/ |