Skip to content

Commit d025d49

Browse files
committed
Copy code from code-review-demo and use reuseable code review action
0 parents  commit d025d49

File tree

7 files changed

+482
-0
lines changed

7 files changed

+482
-0
lines changed

.github/workflows/code-review.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Code Review
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
kosli-org:
7+
description: 'Kosli organization name'
8+
required: true
9+
type: string
10+
kosli-build-flow:
11+
description: 'Kosli build flow name *where the PR attestations are made*'
12+
required: true
13+
type: string
14+
15+
kosli-release-flow:
16+
description: 'Kosli release flow name *where the attestation will be made*'
17+
required: true
18+
type: string
19+
kosli-trail:
20+
description: 'Kosli trail SHA to use'
21+
required: true
22+
type: string
23+
base-tag:
24+
description: 'Base tag to compare against (default: 1.0.0)'
25+
required: false
26+
type: string
27+
default: '1.0.0'
28+
secrets:
29+
kosli-api-token:
30+
description: 'Kosli API token'
31+
required: true
32+
33+
jobs:
34+
code-review:
35+
runs-on: ubuntu-24.04
36+
permissions:
37+
id-token: write
38+
contents: write
39+
env:
40+
OUTPUT_FILE: output.json
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
with:
46+
fetch-depth: 0
47+
fetch-tags: true
48+
49+
- name: Setup Kosli cli
50+
uses: kosli-dev/setup-cli-action@v2
51+
with:
52+
version: ${{ vars.KOSLI_CLI_VERSION }}
53+
54+
- name: Setup Python
55+
uses: actions/setup-python@v4
56+
with:
57+
python-version: '3.11'
58+
59+
- name: Install dependencies
60+
run: pip install -r requirements.txt
61+
62+
- name: Get commit list between HEAD and base tag
63+
id: get-commits
64+
run: |
65+
# Check if the base tag exists
66+
if git rev-parse --verify ${{ inputs.base-tag }} >/dev/null 2>&1; then
67+
# Tag exists, get all commit SHAs between HEAD and base tag (excluding the tag commit)
68+
COMMIT_LIST=$(git log --format="%H" ${{ inputs.base-tag }}..HEAD)
69+
echo "Using commits between HEAD and ${{ inputs.base-tag }} tag"
70+
else
71+
# Tag doesn't exist, use only HEAD commit
72+
COMMIT_LIST=$(git rev-parse HEAD)
73+
echo "Tag ${{ inputs.base-tag }} not found, using only HEAD commit"
74+
fi
75+
# Convert to space-separated list for the Python script
76+
COMMIT_LIST_SPACED=$(echo "$COMMIT_LIST" | tr '\n' ' ')
77+
echo "commit_list=$COMMIT_LIST_SPACED" >> $GITHUB_OUTPUT
78+
echo "Found commits: $COMMIT_LIST_SPACED"
79+
80+
- name: Run code review evaluation
81+
run: python3 "bin/code-review-evaluation.py"
82+
--host "https://app.kosli.com"
83+
--org "${{ inputs.kosli-org }}"
84+
--flow "${{ inputs.kosli-build-flow }}"
85+
--commit-list ${{ steps.get-commits.outputs.commit_list }}
86+
--attestation-type "pull_request"
87+
--api-token "${{ secrets.kosli-api-token }}"
88+
--output-file "${{ env.OUTPUT_FILE }}"
89+
90+
- name: attest code review evidence to Kosli
91+
run: kosli attest custom
92+
--type code-review
93+
--name code-review
94+
--attestation-data "${{ env.OUTPUT_FILE }}"
95+
--flow ${{ inputs.kosli-release-flow }}
96+
--trail ${{ inputs.kosli-trail }}
97+
--api-token "${{ secrets.kosli-api-token }}"
98+
--org ${{ inputs.kosli-org }}

.github/workflows/main.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- '*-main'
7+
- '*-release'
8+
9+
env:
10+
KOSLI_ORG: kosli-public
11+
KOSLI_FLOW: test-code-review-action
12+
KOSLI_API_TOKEN: '${{ secrets.KOSLI_PUBLIC_API_TOKEN }}'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
17+
jobs:
18+
setup:
19+
runs-on: ubuntu-24.04
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
fetch-tags: true
25+
26+
- name: Setup Kosli cli
27+
uses: kosli-dev/setup-cli-action@v2
28+
with:
29+
version: ${{ vars.KOSLI_CLI_VERSION }}
30+
31+
32+
- name: Create Kosli Flow
33+
run: kosli create flow ${{ env.KOSLI_FLOW }}
34+
--template-file build-template.yml
35+
--description "Code Review Demo"
36+
37+
- name: Begin Kosli Trail
38+
run: kosli begin trail "${{ github.sha }}"
39+
--flow ${{ env.KOSLI_FLOW }}
40+
41+
42+
pull-request:
43+
needs: [setup]
44+
runs-on: ubuntu-24.04
45+
permissions:
46+
id-token: write
47+
contents: write
48+
pull-requests: read
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
fetch-tags: true
56+
57+
- name: Setup Kosli cli
58+
uses: kosli-dev/setup-cli-action@v2
59+
with:
60+
version: ${{ vars.KOSLI_CLI_VERSION }}
61+
62+
- name: Attest pull-request evidence to Kosli
63+
run: kosli attest pullrequest github
64+
--name pull-request
65+
--flow ${{ env.KOSLI_FLOW }}
66+
--trail ${{ github.sha }}
67+
--github-token ${{ secrets.GITHUB_TOKEN }}
68+
69+
70+
code-review:
71+
needs: [pull-request]
72+
uses: kosli-dev/control-actions/.github/actions/code-review@main
73+
with:
74+
base_ref: '1.0.0'
75+
kosli_api_token: ${{ secrets.KOSLI_PUBLIC_API_TOKEN }}
76+
kosli_org: 'kosli-public'
77+
kosli_search_flow_name: 'test-code-review-action'
78+
kosli_code_review_attestation_type: 'code-review'
79+
kosli_code_review_flow_name: 'test-code-review-action'
80+
kosli_code_review_trail_name: ${{ github.sha }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Release Code Review
2+
3+
on:
4+
push:
5+
tags:
6+
- 's*-1.0.*'
7+
8+
env:
9+
KOSLI_ORG: kosli-public
10+
KOSLI_FLOW: code-review-demo-release
11+
KOSLI_API_TOKEN: '${{ secrets.KOSLI_PUBLIC_API_TOKEN }}'
12+
13+
jobs:
14+
15+
setup:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
fetch-tags: true
22+
23+
- name: Setup Kosli cli
24+
uses: kosli-dev/setup-cli-action@v2
25+
with:
26+
version: ${{ vars.KOSLI_CLI_VERSION }}
27+
28+
- name: Create Kosli Flow
29+
run: kosli create flow ${{ env.KOSLI_FLOW }}
30+
--template-file release-template.yml
31+
--description "Code Review Demo Release"
32+
33+
- name: Begin Kosli Trail
34+
run: kosli begin trail "${{ github.ref_name }}"
35+
--flow ${{ env.KOSLI_FLOW }}
36+
37+
code-review:
38+
needs: [setup]
39+
uses: ./.github/workflows/code-review.yml
40+
with:
41+
kosli-org: kosli-public
42+
kosli-build-flow: code-review-demo
43+
kosli-release-flow: code-review-demo-release
44+
kosli-trail: ${{ github.ref_name }}
45+
base-tag: "1.0.0"
46+
secrets:
47+
kosli-api-token: ${{ secrets.KOSLI_PUBLIC_API_TOKEN }}

build-template.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 1
2+
trail:
3+
attestations:
4+
- name: code-review
5+
type: custom:code-review
6+
- name: pull-request
7+
type: pull_request

release-template.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 1
2+
trail:
3+
attestations:
4+
- name: code-review
5+
type: custom:code-review

0 commit comments

Comments
 (0)