Skip to content

Commit 2bc028c

Browse files
authored
Merge pull request #41 from HumairAK/fix_cc
UPSTREAM: <carry>: move commit checker to separate wf
2 parents bdd4217 + 15464f6 commit 2bc028c

File tree

3 files changed

+93
-33
lines changed

3 files changed

+93
-33
lines changed

.github/workflows/build-prs-trigger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Trigger build images for PRs
1+
name: Trigger PR CI
22
on:
33
pull_request:
44
paths-ignore:

.github/workflows/build-prs.yml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build images for PRs
22
on:
33
workflow_run:
4-
workflows: ["Trigger build images for PRs"]
4+
workflows: ["Trigger PR CI"]
55
types:
66
- completed
77
env:
@@ -11,37 +11,6 @@ env:
1111
GH_USER_EMAIL: [email protected]
1212
GH_USER_NAME: dsp-developers
1313
jobs:
14-
commit_checker:
15-
name: Run Commit Checker report
16-
runs-on: ubuntu-latest
17-
needs: build-pr-images
18-
steps:
19-
- uses: actions/checkout@v3
20-
- name: Get Commits
21-
id: get-commits
22-
run: |
23-
master_commit=$(cat .git/refs/remotes/origin/master)
24-
echo "master_commit_hash=$master_commit" >> $GITHUB_OUTPUT
25-
last_commit=$(cat .git/refs/remotes/pull/${{ github.event.pull_request.number }}/merge)
26-
echo "last_commit_hash=$last_commit" >> $GITHUB_OUTPUT
27-
- name: Run Commit Checker
28-
shell: bash
29-
env:
30-
GH_TOKEN: ${{ secrets.GH_TOKEN_PROJECT_EDIT }}
31-
continue-on-error: true
32-
run: |
33-
git config user.email "${{ env.GH_USER_EMAIL }}"
34-
git config user.name "${{ env.GH_USER_NAME }}"
35-
36-
cat <<"EOF" >> /tmp/body-file.txt
37-
Commit Checker results:
38-
==== These are the results of the commit checker scans ====
39-
==== If these are not commits from upstream kfp, then ====
40-
==== please ensure you adhere to the commit checker formatting ====
41-
$(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 }})
42-
EOF
43-
44-
gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/body-file.txt
4514
fetch-data:
4615
name: Fetch workflow payload
4716
runs-on: ubuntu-latest

.github/workflows/commit-check-pr.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
GH_USER_EMAIL: [email protected]
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+
uses: actions/[email protected]
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

Comments
 (0)