fix merge report job in gitlab ci (#2897)

This commit is contained in:
Valentin Thomazic 2025-04-02 11:32:28 +02:00 committed by GitHub
parent 122f6fcf92
commit 57771bbbe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 26 deletions

View file

@ -26,10 +26,9 @@ jobs:
script: |
const inputs = context.payload.inputs
const pr = inputs.pr_number
const dashboardBranch = inputs.source_branch ? inputs.source_branch : cva6
const success = inputs.success == 'true'
const status_text = success ? ":heavy_check_mark: successful" : ":x: failed"
const url = `https://riscv-ci.pages.thales-invia.fr/dashboard/dashboard_${dashboardBranch}_${pr}.html`
const url = `https://riscv-ci.pages.thales-invia.fr/dashboard/dashboard_${source_branch}_${pr}.html`
await github.rest.issues.createComment({
issue_number: pr,
owner: context.repo.owner,

View file

@ -17,6 +17,16 @@ import subprocess
import github_integration as gh
import source_branch_finder as source_branch
def find_pr(branch, prs):
match = re.search(r'(.*)_PR_([a-zA-Z0-9](?:[a-zA-Z0-9]|[-_](?=[a-zA-Z0-9])){0,38})', branch)
if match:
label = f'{match.group(2)}:{match.group(1)}'
for pr in prs:
if label == pr['head']['label']:
return pr
return None
# arguments: inputdir outputfile
cwd = os.getcwd()
@ -47,6 +57,7 @@ if workflow_type == 'github': # (from wrapper)
cvv_sha = os.environ['CORE_V_VERIF_HASH'].strip('\'\"')
cva6_branch = os.environ['CVA6_BRANCH'].strip('\'\"')
cva6_sha = os.environ['CVA6_HASH'].strip('\'\"')
source_branch = source_branch.find(cva6_branch)
else: # gitlab
workflow_uid = os.environ['CI_PIPELINE_ID'].strip('\'\"')
cvv_branch = 'none'
@ -56,8 +67,7 @@ else: # gitlab
cva6_sha = os.environ['CI_COMMIT_SHA'].strip('\'\"')
workflow_commit_subject = os.environ['CI_COMMIT_MESSAGE'].strip('\'\"')
workflow_commit_author = os.environ['CI_COMMIT_AUTHOR'].strip('\'\"')
source_branch = source_branch.find(cva6_branch)
source_branch = "master"
if len(workflow_commit_subject) > 60:
title = workflow_commit_subject[0:60] + '...'
@ -118,6 +128,8 @@ pprint.pprint(pipeline)
filename = re.sub('[^\w\.]', '', sys.argv[2])
print(filename)
pipeline_report_dir = "cva6" if source_branch == "master" else source_branch
with open(f'{sys.argv[1]}/{filename}', 'w+') as f:
yaml.dump(pipeline, f)
@ -126,33 +138,28 @@ try:
print(subprocess.check_output(f'''
rm -r .gitlab-ci/dashboard_tmp || echo "nothing to do"
git clone {dashboard_url} .gitlab-ci/dashboard_tmp
mkdir -p .gitlab-ci/dashboard_tmp/pipelines_{source_branch}
mkdir -p .gitlab-ci/dashboard_tmp/pipelines_{pipeline_report_dir}
ls -al {sys.argv[1]}
cp {sys.argv[1]}/{filename} .gitlab-ci/dashboard_tmp/pipelines_{source_branch}/
cp {sys.argv[1]}/{filename} .gitlab-ci/dashboard_tmp/pipelines_{pipeline_report_dir}/
cd .gitlab-ci/dashboard_tmp
git config user.email {git_email}
git config user.name {git_name}
git add pipelines_{source_branch}/{filename}
git commit -m '{source_branch}: '{quoted_title} || echo "commit fail"
git add pipelines_{pipeline_report_dir}/{filename}
git commit -m '{pipeline_report_dir}: '{quoted_title} || echo "commit fail"
git push
cd -
''', shell=True))
except subprocess.CalledProcessError as e:
print(f"Error: {e.output}")
def find_pr(branch, prs):
match = re.search(r'(.*)_PR_([a-zA-Z0-9](?:[a-zA-Z0-9]|[-_](?=[a-zA-Z0-9])){0,38})', branch)
if match:
label = f'{match.group(2)}:{match.group(1)}'
for pr in prs:
if label == pr['head']['label']:
return pr
return None
if workflow_type == "github":
pulls = gh.pulls('openhwgroup', workflow_repo)
pr = find_pr(workflow_commit_ref_name, pulls)
else:
pr = None
pulls = gh.pulls('openhwgroup', workflow_repo)
pr = find_pr(workflow_commit_ref_name, pulls)
if pr is not None:
ref_branch = pr['base']['ref']
wf = gh.DashboardDone('openhwgroup', workflow_repo, ref_branch)
response = wf.send(pr['number'], success, source_branch)
response = wf.send(pr['number'], success, pipeline_report_dir)
print(response.text)

View file

@ -1,16 +1,16 @@
import gitlab
import os
GITLAB_URL = "https://gitlab.thales-invia.fr"
CVA6_PROJECT_ID = os.environ["CVA6_PROJECT_ID"]
CVA6_PROJECT = gitlab.Gitlab(GITLAB_URL, private_token=os.environ["CVA6_TOKEN"]).projects.get(CVA6_PROJECT_ID, lazy=True)
def find(branch):
GITLAB_URL = "https://gitlab.thales-invia.fr"
CVA6_PROJECT_ID = os.environ["CVA6_PROJECT_ID"]
CVA6_PROJECT = gitlab.Gitlab(GITLAB_URL, private_token=os.environ["CVA6_TOKEN"]).projects.get(CVA6_PROJECT_ID, lazy=True)
MONITORED_BRANCHES = ["master", "cv32a60x"]
monitored_branches_commit_ids = []
for monitored_branch in MONITORED_BRANCHES:
monitored_branches_commit_ids.append(get_branch_commits_ids(monitored_branch))
monitored_branches_commit_ids.append(get_branch_commits_ids(monitored_branch, CVA6_PROJECT))
branch_commits_ids = get_branch_commits_ids(branch)
for commit_id in branch_commits_ids:
@ -19,5 +19,5 @@ def find(branch):
return MONITORED_BRANCHES[i]
return "master"
def get_branch_commits_ids(branch):
return set(commit.id for commit in CVA6_PROJECT.commits.list(ref_name=branch, get_all=False, per_page=100))
def get_branch_commits_ids(branch, project):
return set(commit.id for commit in project.commits.list(ref_name=branch, get_all=False, per_page=100))