|
| 1 | +name: Commit Checker for PRs |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Trigger PR CI"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | +env: |
| 8 | + QUAY_ORG: opendatahub |
| 9 | + QUAY_ID: ${{ secrets.QUAY_ROBOT_USERNAME }} |
| 10 | + QUAY_TOKEN: ${{ secrets.QUAY_ROBOT_TOKEN }} |
| 11 | + |
| 12 | + GH_USER_NAME: dsp-developers |
| 13 | +jobs: |
| 14 | + fetch-data: |
| 15 | + name: Fetch workflow payload |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: > |
| 18 | + github.event.workflow_run.event == 'pull_request' && |
| 19 | + github.event.workflow_run.conclusion == 'success' |
| 20 | + outputs: |
| 21 | + pr_state: ${{ steps.vars.outputs.pr_state }} |
| 22 | + pr_number: ${{ steps.vars.outputs.pr_number }} |
| 23 | + head_sha: ${{ steps.vars.outputs.head_sha }} |
| 24 | + event_action: ${{ steps.vars.outputs.event_action }} |
| 25 | + steps: |
| 26 | + - name: 'Download artifact' |
| 27 | + |
| 28 | + with: |
| 29 | + script: | |
| 30 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + run_id: ${{github.event.workflow_run.id }}, |
| 34 | + }); |
| 35 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 36 | + return artifact.name == "pr" |
| 37 | + })[0]; |
| 38 | + var download = await github.actions.downloadArtifact({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + artifact_id: matchArtifact.id, |
| 42 | + archive_format: 'zip', |
| 43 | + }); |
| 44 | + var fs = require('fs'); |
| 45 | + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); |
| 46 | + - run: unzip pr.zip |
| 47 | + - shell: bash |
| 48 | + id: vars |
| 49 | + run: | |
| 50 | + pr_number=$(cat ./pr_number) |
| 51 | + pr_state=$(cat ./pr_state) |
| 52 | + head_sha=$(cat ./head_sha) |
| 53 | + event_action=$(cat ./event_action) |
| 54 | + echo "pr_number=${pr_number}" >> $GITHUB_OUTPUT |
| 55 | + echo "pr_state=${pr_state}" >> $GITHUB_OUTPUT |
| 56 | + echo "head_sha=${head_sha}" >> $GITHUB_OUTPUT |
| 57 | + echo "event_action=${event_action}" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + commit_checker: |
| 60 | + name: Run Commit Checker report |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: fetch-data |
| 63 | + env: |
| 64 | + PR_NUMBER: ${{ needs.fetch-data.outputs.pr_number }} |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v3 |
| 67 | + - name: Get Commits |
| 68 | + id: get-commits |
| 69 | + run: | |
| 70 | + master_commit=$(cat .git/refs/remotes/origin/master) |
| 71 | + echo "master_commit_hash=$master_commit" >> $GITHUB_OUTPUT |
| 72 | + last_commit=$(cat .git/refs/remotes/pull/${{ PR_NUMBER }}/merge) |
| 73 | + echo "last_commit_hash=$last_commit" >> $GITHUB_OUTPUT |
| 74 | + - name: Run Commit Checker |
| 75 | + shell: bash |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ secrets.GH_TOKEN_PROJECT_EDIT }} |
| 78 | + continue-on-error: true |
| 79 | + run: | |
| 80 | + git config user.email "${{ env.GH_USER_EMAIL }}" |
| 81 | + git config user.name "${{ env.GH_USER_NAME }}" |
| 82 | +
|
| 83 | + cat <<"EOF" >> /tmp/body-file.txt |
| 84 | + Commit Checker results: |
| 85 | + ==== These are the results of the commit checker scans ==== |
| 86 | + ==== If these are not commits from upstream kfp, then ==== |
| 87 | + ==== please ensure you adhere to the commit checker formatting ==== |
| 88 | + $(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 }}) |
| 89 | + EOF |
| 90 | +
|
| 91 | + gh pr comment ${{ PR_NUMBER }} --body-file /tmp/body-file.txt |
0 commit comments