Skip to content

Commit 77260df

Browse files
committed
smarter pr number fetching for grype and report
1 parent bc235df commit 77260df

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

.github/actions/create_workflow_report/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ runs:
1010
steps:
1111
- name: Create and upload workflow report
1212
env:
13-
PR_NUMBER: ${{ github.event.pull_request.number || 0 }}
1413
COMMIT_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
1514
ACTIONS_RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}
1615
FINAL: ${{ inputs.final }}
@@ -19,7 +18,7 @@ runs:
1918
pip install clickhouse-driver==0.2.8 numpy==1.26.4 pandas==2.0.3 jinja2==3.1.5
2019
2120
CMD="python3 .github/actions/create_workflow_report/create_workflow_report.py"
22-
ARGS="--pr-number $PR_NUMBER --commit-sha $COMMIT_SHA --actions-run-url $ACTIONS_RUN_URL --known-fails tests/broken_tests.json --cves"
21+
ARGS="--commit-sha $COMMIT_SHA --actions-run-url $ACTIONS_RUN_URL --known-fails tests/broken_tests.json --cves"
2322
2423
set +e
2524
if [[ "$FINAL" == "false" ]]; then

.github/workflows/grype_scan.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ on:
1515
description: 'Docker image. If no tag, it will be determined by version_helper.py'
1616
required: true
1717
type: string
18+
version:
19+
description: 'Version tag. If no version, it will be determined by version_helper.py'
20+
required: false
21+
type: string
22+
default: ""
23+
tag-suffix:
24+
description: 'Tag suffix. To be appended the version from version_helper.py'
25+
required: false
26+
type: string
27+
default: ""
1828
env:
1929
PYTHONUNBUFFERED: 1
2030
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -40,17 +50,25 @@ jobs:
4050
sudo apt-get install -y python3-pip python3-venv
4151
python3 -m venv venv
4252
source venv/bin/activate
43-
pip install --upgrade requests chardet urllib3
53+
pip install --upgrade requests chardet urllib3 unidiff boto3 PyGithub
4454
pip install testflows==$TESTFLOWS_VERSION awscli==1.33.28
4555
echo PATH=$PATH >>$GITHUB_ENV
4656
4757
- name: Set image tag if not given
4858
if: ${{ !contains(inputs.docker_image, ':') }}
4959
id: set_version
60+
env:
61+
TAG_SUFFIX: ${{ inputs.tag-suffix }}
62+
SPECIFIED_VERSION: ${{ inputs.version }}
5063
run: |
5164
python3 ./tests/ci/version_helper.py | tee /tmp/version_info
5265
source /tmp/version_info
53-
echo "docker_image=${{ inputs.docker_image }}:${{ github.event.pull_request.number || 0 }}-$CLICKHOUSE_VERSION_STRING" >> $GITHUB_OUTPUT
66+
if [ -z "$SPECIFIED_VERSION" ]; then
67+
VERSION=$CLICKHOUSE_VERSION_STRING
68+
else
69+
VERSION=$SPECIFIED_VERSION
70+
fi
71+
echo "docker_image=${{ inputs.docker_image }}:$PR_NUMBER-$VERSION$TAG_SUFFIX" >> $GITHUB_OUTPUT
5472
echo "commit_sha=$CLICKHOUSE_VERSION_GITHASH" >> $GITHUB_OUTPUT
5573
5674
- name: Run Grype Scan
@@ -68,9 +86,10 @@ jobs:
6886
env:
6987
S3_BUCKET: "altinity-build-artifacts"
7088
COMMIT_SHA: ${{ steps.set_version.outputs.commit_sha || github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
71-
PR_NUMBER: ${{ github.event.pull_request.number || 0 }}
89+
PR_NUMBER: ${{ env.PR_NUMBER || github.event.pull_request.number || 0 }}
7290
DOCKER_IMAGE: ${{ steps.set_version.outputs.docker_image || inputs.docker_image }}
7391
run: |
92+
echo "PR_NUMBER=$PR_NUMBER"
7493
./.github/grype/transform_and_upload_results_s3.sh
7594
7695
- name: Create step summary

.github/workflows/release_branches.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ jobs:
201201
uses: ./.github/workflows/grype_scan.yml
202202
secrets: inherit
203203
with:
204-
docker_image: altinityinfra/clickhouse-${{ matrix.image }}:${{ github.event.pull_request.number || 0 }}-${{ fromJson(needs.RunConfig.outputs.data).version }}${{ matrix.suffix }}
204+
docker_image: altinityinfra/clickhouse-${{ matrix.image }}
205+
version: ${{ fromJson(needs.RunConfig.outputs.data).version }}
206+
tag-suffix: ${{ matrix.suffix }}
205207
############################################################################################
206208
##################################### BUILD REPORTER #######################################
207209
############################################################################################

tests/ci/version_helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from pathlib import Path
55
from typing import Any, Dict, Iterable, List, Literal, Optional, Set, Tuple, Union
66

7+
from pr_info import PRInfo # grype scan needs to know the PR number
8+
79
from git_helper import TWEAK, Git, get_tags, git_runner, removeprefix, VersionType
810

911
FILE_WITH_VERSION_PATH = "cmake/autogenerated_versions.txt"
@@ -532,6 +534,12 @@ def main():
532534
if args.update_part or args.update_cmake:
533535
update_cmake_version(version)
534536

537+
# grype scan needs to know the PR number
538+
pr_info = PRInfo()
539+
print(f"PR_NUMBER={pr_info.number}")
540+
if args.export:
541+
print(f"export PR_NUMBER")
542+
535543
for k, v in version.as_dict().items():
536544
name = f"CLICKHOUSE_VERSION_{k.upper()}"
537545
print(f"{name}='{v}'")

0 commit comments

Comments
 (0)