Skip to content

Commit 57771bb

Browse files
fix merge report job in gitlab ci (#2897)
1 parent 122f6fc commit 57771bb

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

.github/workflows/dashboard-done.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ jobs:
2626
script: |
2727
const inputs = context.payload.inputs
2828
const pr = inputs.pr_number
29-
const dashboardBranch = inputs.source_branch ? inputs.source_branch : cva6
3029
const success = inputs.success == 'true'
3130
const status_text = success ? ":heavy_check_mark: successful" : ":x: failed"
32-
const url = `https://riscv-ci.pages.thales-invia.fr/dashboard/dashboard_${dashboardBranch}_${pr}.html`
31+
const url = `https://riscv-ci.pages.thales-invia.fr/dashboard/dashboard_${source_branch}_${pr}.html`
3332
await github.rest.issues.createComment({
3433
issue_number: pr,
3534
owner: context.repo.owner,

.gitlab-ci/scripts/merge_job_reports.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
import github_integration as gh
1818
import source_branch_finder as source_branch
1919

20+
21+
def find_pr(branch, prs):
22+
match = re.search(r'(.*)_PR_([a-zA-Z0-9](?:[a-zA-Z0-9]|[-_](?=[a-zA-Z0-9])){0,38})', branch)
23+
if match:
24+
label = f'{match.group(2)}:{match.group(1)}'
25+
for pr in prs:
26+
if label == pr['head']['label']:
27+
return pr
28+
return None
29+
2030
# arguments: inputdir outputfile
2131

2232
cwd = os.getcwd()
@@ -47,6 +57,7 @@
4757
cvv_sha = os.environ['CORE_V_VERIF_HASH'].strip('\'\"')
4858
cva6_branch = os.environ['CVA6_BRANCH'].strip('\'\"')
4959
cva6_sha = os.environ['CVA6_HASH'].strip('\'\"')
60+
source_branch = source_branch.find(cva6_branch)
5061
else: # gitlab
5162
workflow_uid = os.environ['CI_PIPELINE_ID'].strip('\'\"')
5263
cvv_branch = 'none'
@@ -56,8 +67,7 @@
5667
cva6_sha = os.environ['CI_COMMIT_SHA'].strip('\'\"')
5768
workflow_commit_subject = os.environ['CI_COMMIT_MESSAGE'].strip('\'\"')
5869
workflow_commit_author = os.environ['CI_COMMIT_AUTHOR'].strip('\'\"')
59-
60-
source_branch = source_branch.find(cva6_branch)
70+
source_branch = "master"
6171

6272
if len(workflow_commit_subject) > 60:
6373
title = workflow_commit_subject[0:60] + '...'
@@ -118,6 +128,8 @@
118128
filename = re.sub('[^\w\.]', '', sys.argv[2])
119129
print(filename)
120130

131+
pipeline_report_dir = "cva6" if source_branch == "master" else source_branch
132+
121133
with open(f'{sys.argv[1]}/{filename}', 'w+') as f:
122134
yaml.dump(pipeline, f)
123135

@@ -126,33 +138,28 @@
126138
print(subprocess.check_output(f'''
127139
rm -r .gitlab-ci/dashboard_tmp || echo "nothing to do"
128140
git clone {dashboard_url} .gitlab-ci/dashboard_tmp
129-
mkdir -p .gitlab-ci/dashboard_tmp/pipelines_{source_branch}
141+
mkdir -p .gitlab-ci/dashboard_tmp/pipelines_{pipeline_report_dir}
130142
ls -al {sys.argv[1]}
131-
cp {sys.argv[1]}/{filename} .gitlab-ci/dashboard_tmp/pipelines_{source_branch}/
143+
cp {sys.argv[1]}/{filename} .gitlab-ci/dashboard_tmp/pipelines_{pipeline_report_dir}/
132144
cd .gitlab-ci/dashboard_tmp
133145
git config user.email {git_email}
134146
git config user.name {git_name}
135-
git add pipelines_{source_branch}/{filename}
136-
git commit -m '{source_branch}: '{quoted_title} || echo "commit fail"
147+
git add pipelines_{pipeline_report_dir}/{filename}
148+
git commit -m '{pipeline_report_dir}: '{quoted_title} || echo "commit fail"
137149
git push
138150
cd -
139151
''', shell=True))
140152
except subprocess.CalledProcessError as e:
141153
print(f"Error: {e.output}")
142154

143-
def find_pr(branch, prs):
144-
match = re.search(r'(.*)_PR_([a-zA-Z0-9](?:[a-zA-Z0-9]|[-_](?=[a-zA-Z0-9])){0,38})', branch)
145-
if match:
146-
label = f'{match.group(2)}:{match.group(1)}'
147-
for pr in prs:
148-
if label == pr['head']['label']:
149-
return pr
150-
return None
155+
if workflow_type == "github":
156+
pulls = gh.pulls('openhwgroup', workflow_repo)
157+
pr = find_pr(workflow_commit_ref_name, pulls)
158+
else:
159+
pr = None
151160

152-
pulls = gh.pulls('openhwgroup', workflow_repo)
153-
pr = find_pr(workflow_commit_ref_name, pulls)
154161
if pr is not None:
155162
ref_branch = pr['base']['ref']
156163
wf = gh.DashboardDone('openhwgroup', workflow_repo, ref_branch)
157-
response = wf.send(pr['number'], success, source_branch)
164+
response = wf.send(pr['number'], success, pipeline_report_dir)
158165
print(response.text)
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import gitlab
22
import os
33

4-
GITLAB_URL = "https://gitlab.thales-invia.fr"
5-
CVA6_PROJECT_ID = os.environ["CVA6_PROJECT_ID"]
6-
CVA6_PROJECT = gitlab.Gitlab(GITLAB_URL, private_token=os.environ["CVA6_TOKEN"]).projects.get(CVA6_PROJECT_ID, lazy=True)
7-
84
def find(branch):
5+
GITLAB_URL = "https://gitlab.thales-invia.fr"
6+
CVA6_PROJECT_ID = os.environ["CVA6_PROJECT_ID"]
7+
CVA6_PROJECT = gitlab.Gitlab(GITLAB_URL, private_token=os.environ["CVA6_TOKEN"]).projects.get(CVA6_PROJECT_ID, lazy=True)
98
MONITORED_BRANCHES = ["master", "cv32a60x"]
9+
1010
monitored_branches_commit_ids = []
1111

1212
for monitored_branch in MONITORED_BRANCHES:
13-
monitored_branches_commit_ids.append(get_branch_commits_ids(monitored_branch))
13+
monitored_branches_commit_ids.append(get_branch_commits_ids(monitored_branch, CVA6_PROJECT))
1414
branch_commits_ids = get_branch_commits_ids(branch)
1515

1616
for commit_id in branch_commits_ids:
@@ -19,5 +19,5 @@ def find(branch):
1919
return MONITORED_BRANCHES[i]
2020
return "master"
2121

22-
def get_branch_commits_ids(branch):
23-
return set(commit.id for commit in CVA6_PROJECT.commits.list(ref_name=branch, get_all=False, per_page=100))
22+
def get_branch_commits_ids(branch, project):
23+
return set(commit.id for commit in project.commits.list(ref_name=branch, get_all=False, per_page=100))

0 commit comments

Comments
 (0)