1variantSubDir=
2variantHeadline=
3if [ -n "${VARIANT:-}" ]; then
4    variantSubDir="/${VARIANT}"
5    variantHeadline=" [${VARIANT}]"
6fi
7
8# AUTO PR Feature
9# If the following variables are defined, then all pipelines
10# of other branches will be considered pull-requests to
11# autoPRBranch.
12# Customized
13autoPRRepository="${AUTO_PR_REPOSITORY:-}"
14# Customized
15autoPRBranch="${AUTO_PR_BRANCH:-}"
16
17# Customized
18artifactsRoot=/var/local/eclair
19
20case "${ci}" in
21github)
22    # To be customized
23    repository="${GITHUB_REPOSITORY}"
24    jobId="${GITHUB_RUN_NUMBER}"
25
26    autoPRRemoteUrl="${GITHUB_SERVER_URL}/${autoPRRepository:-}.git"
27
28    case "${GITHUB_EVENT_NAME}" in
29    pull_request*)
30        event=pull_request
31        pullRequestId="${GITHUB_EVENT_PULL_REQUEST_NUMBER}"
32        pullRequestHeadRepo="${PR_HEAD_REPO}"
33        pullRequestHeadRef="${PR_HEAD_REF}"
34        pullRequestBaseRef="${PR_BASE_REF}"
35        pullRequestUser="${PR_USER}"
36        # baseCommitId and headCommitId are the most recent merge points without conflicts
37        git fetch -q --deepen=2
38        baseCommitId=$(git show -s --pretty=%H HEAD^1)
39        headCommitId=$(git show -s --pretty=%H HEAD^2)
40        ;;
41    push | workflow_dispatch)
42        event=push
43        # Extract the branch name from "refs/heads/<branch>"
44        ref="${GITHUB_REF#refs/heads/}"
45        headCommitId="${GITHUB_SHA}"
46        pushUser="${GITHUB_ACTOR}"
47        ;;
48    *)
49        echo "Unexpected GITHUB_REF ${GITHUB_REF}" >&2
50        exit 1
51        ;;
52    esac
53    ;;
54gitlab)
55    # Customized
56    repository="${CI_PROJECT_PATH}"
57    jobId="${CI_JOB_ID}"
58
59    gitlabApiUrl="${CI_SERVER_PROTOCOL}://${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4"
60    autoPRRemoteUrl="${CI_SERVER_PROTOCOL}://${CI_SERVER_HOST}:${CI_SERVER_PORT}/${autoPRRepository:-}.git"
61
62    # Customized
63    gitlabBotToken="${ECLAIR_BOT_TOKEN:-}"
64
65    case "${CI_PIPELINE_SOURCE}" in
66    merge_request_event)
67        event=pull_request
68        pullRequestId="${CI_MERGE_REQUEST_IID}"
69        pullRequestHeadRef="${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"
70        pullRequestHeadRepo="${CI_MERGE_REQUEST_SOURCE_PROJECT_PATH}"
71        pullRequestBaseRef="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
72        pullRequestUser="${GITLAB_USER_LOGIN}"
73        headCommitId="${CI_COMMIT_SHA}"
74        baseCommitId="${CI_MERGE_REQUEST_DIFF_BASE_SHA}"
75        ;;
76    push | pipeline | web | schedule)
77        event=push
78        if [ -n "${CI_COMMIT_BRANCH:-}" ]; then
79            ref_kind=branch
80            ref="${CI_COMMIT_BRANCH}"
81        else
82            ref_kind=tag
83            ref="${CI_COMMIT_TAG}"
84        fi
85        headCommitId="${CI_COMMIT_SHA}"
86        pushUser="${GITLAB_USER_NAME}"
87        ;;
88    *)
89        echo "Unexpected event ${CI_PIPELINE_SOURCE}" >&2
90        exit 1
91        ;;
92    esac
93    ;;
94jenkins)
95    # To be customized
96    repository="${JOB_BASE_NAME}"
97    project="${JOB_NAME}"
98    jobId="${BUILD_NUMBER}"
99
100    jenkinsApiUrl="${JENKINS_URL}"
101    autoPRRemoteUrl="${JENKINS_URL}/${autoPRRepository:-}.git"
102
103    # To be customized
104    jenkinsBotUsername="${ECLAIR_BOT_USERNAME:-}"
105    jenkinsBotToken="${ECLAIR_BOT_TOKEN:-}"
106
107    event=push
108    ref="${GIT_BRANCH}"
109    headCommitId="${GIT_COMMIT}"
110    pushUser=$(git show --pretty='format:%aN' -s)
111    ;;
112*)
113    echo "Unexpected CI/CD context" >&2
114    exit 1
115    ;;
116esac
117
118if [ "${event}" = "push" ] && [ -n "${autoPRBranch:-}" ]; then
119    # AUTO PR Feature enabled
120    if ! [ "${ref}" = "${autoPRBranch}" ] ||
121        ! [ "${repository}" = "${autoPRRepository}" ]; then
122        event=auto_pull_request
123    fi
124fi
125
126case "${event}" in
127pull_request)
128    subDir="${pullRequestHeadRepo}.ecdf/${pullRequestBaseRef}"
129    jobHeadline="ECLAIR ${ANALYSIS_KIND} on repository ${repository}: ${pullRequestUser} wants to merge ${pullRequestHeadRepo}:${pullRequestHeadRef} (${headCommitId}) into ${pullRequestBaseRef} (${baseCommitId})"
130    ;;
131push)
132    subDir="${ref}"
133    jobHeadline="ECLAIR ${ANALYSIS_KIND} on repository ${repository}: ${ref_kind} ${ref} (${headCommitId})"
134    badgeLabel="ECLAIR ${ANALYSIS_KIND} ${ref}${variantHeadline} #${jobId}"
135    ;;
136auto_pull_request)
137    git remote remove autoPRRemote 2>/dev/null || true
138    git remote add autoPRRemote "${autoPRRemoteUrl}"
139    git fetch -q autoPRRemote
140    subDir="${ref}"
141    if ! baseCommitId=$(git merge-base "autoPRRemote/${autoPRBranch}" HEAD); then
142        baseCommitId=no_merge_point
143    fi
144    jobHeadline="ECLAIR ${ANALYSIS_KIND} on repository ${repository}: ${pushUser} wants to merge ${repository}:${ref} (${headCommitId}) into ${autoPRRepository}/${autoPRBranch} (${baseCommitId})"
145    ;;
146*)
147    echo "Unexpected event ${event}" >&2
148    exit 1
149    ;;
150esac
151
152case "${repository}" in
153xen-project/xen)
154    # Customized
155    keepOldAnalyses=0
156    ;;
157xen-project/*)
158    # Customized
159    keepOldAnalyses=10
160    ;;
161*)
162    echo "Unexpected repository" >&2
163    exit 1
164    ;;
165esac
166
167ECLAIR_BIN_DIR=/opt/bugseng/eclair/bin/
168
169artifactsDir="${artifactsRoot}/xen-project.ecdf/${repository}/ECLAIR_${ANALYSIS_KIND}"
170subDir="${subDir}${variantSubDir}"
171jobHeadline="${jobHeadline}${variantHeadline}"
172
173# Customized
174eclairReportUrlPrefix=https://saas.eclairit.com:3787
175
176jobDir="${artifactsDir}/${subDir}/${jobId}"
177updateLog="${analysisOutputDir}/update.log"
178cleanRegressionsLog="${analysisOutputDir}/clean_regressions.log"
179commentLog="${analysisOutputDir}/comment.json"
180indexHtmlUrl="${eclairReportUrlPrefix}/fs${jobDir}/index.html"
181summaryTxt="${analysisOutputDir}/summary.txt"
182