Commit Checker for PRs #298
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
name: Commit Checker for PRs | |
on: | |
workflow_run: | |
workflows: ["Trigger PR CI"] | |
types: | |
- completed | |
env: | |
QUAY_ORG: opendatahub | |
GH_USER_EMAIL: [email protected] | |
GH_USER_NAME: dsp-developers | |
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_state: ${{ steps.vars.outputs.pr_state }} | |
pr_number: ${{ steps.vars.outputs.pr_number }} | |
head_sha: ${{ steps.vars.outputs.head_sha }} | |
event_action: ${{ steps.vars.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)); | |
- run: unzip pr.zip | |
- shell: bash | |
id: vars | |
run: | | |
pr_number=$(cat ./pr_number) | |
pr_state=$(cat ./pr_state) | |
head_sha=$(cat ./head_sha) | |
event_action=$(cat ./event_action) | |
echo "pr_number=${pr_number}" >> $GITHUB_OUTPUT | |
echo "pr_state=${pr_state}" >> $GITHUB_OUTPUT | |
echo "head_sha=${head_sha}" >> $GITHUB_OUTPUT | |
echo "event_action=${event_action}" >> $GITHUB_OUTPUT | |
commit_checker: | |
name: Run Commit Checker report | |
runs-on: ubuntu-latest | |
needs: fetch-data | |
env: | |
PR_NUMBER: ${{ needs.fetch-data.outputs.pr_number }} | |
PR_HASH: ${{ needs.fetch-data.outputs.head_sha }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get Commits | |
id: get-commits | |
run: | | |
master_commit=$(cat .git/refs/remotes/origin/master) | |
echo "master_commit_hash=$master_commit" >> $GITHUB_OUTPUT | |
echo "last_commit_hash=${{ env.PR_HASH }}" >> $GITHUB_OUTPUT | |
- name: Run Commit Checker | |
shell: bash | |
env: | |
GH_TOKEN: ${{ secrets.GH_TOKEN_PROJECT_EDIT }} | |
continue-on-error: true | |
run: | | |
git config user.email "${{ env.GH_USER_EMAIL }}" | |
git config user.name "${{ env.GH_USER_NAME }}" | |
gh pr checkout ${{ env.PR_NUMBER }} | |
cat <<"EOF" >> /tmp/body-file.txt | |
### Commit Checker results: | |
``` | |
**NOTE**: These are the results of the commit checker scans. | |
If these are not commits from upstream kfp, then please ensure | |
you adhere to the commit checker formatting | |
``` | |
EOF | |
echo "\`\`\`" >> /tmp/body-file.txt | |
podman run -q -v ${{ github.workspace }}:/src/app-root quay.io/rmartine/commitchecker:latest --start ${{ steps.get-commits.outputs.master_commit_hash }} --end ${{ steps.get-commits.outputs.last_commit_hash }} >> /tmp/body-file.txt 2>&1 || true | |
echo "\`\`\`" >> /tmp/body-file.txt | |
gh pr comment ${{ env.PR_NUMBER }} --body-file /tmp/body-file.txt |