@@ -29,14 +29,16 @@ stages:
29
29
- finalize
30
30
31
31
variables :
32
+ CI_DEBUG_TRACE : " false" # Enable debug tracing for CI jobs
33
+ CI_DEBUG_SERVICES : " false" # Enable debug services for CI jobs
32
34
PIPELINE_TYPE : pr_cases # Default to PR Cases if not overwritten by GitLab Scheduled Pipelines
33
35
RUN_ON_MACHINES : all # Default to all machines (overwritten by triggers)
34
36
# Set GFS_CI_RUN_TYPE=nightly in the GitLab Scheuled Pipelines
35
37
# to run the nightly against the develop branch
36
38
GFS_CI_RUN_TYPE : pr_cases # default value (overwritten by GitLab Scheuled Pipelines)
37
39
GW_REPO_URL : https://github.com/NOAA-EMC/global-workflow.git
38
40
# Using CI_PIPELINE_ID guarantees uniqueness per pipeline (also used for pslot tags)
39
- WORKSPACE_ID : ${GFS_CI_RUN_TYPE}_${CI_COMMIT_SHORT_SHA}_${CI_PIPELINE_ID}
41
+ WORKSPACE_ID : ${GFS_CI_RUN_TYPE}_${PR_NUMBER}_${ CI_COMMIT_SHORT_SHA}_${CI_PIPELINE_ID}
40
42
# Define a base path that will be used for initial cloning
41
43
GIT_CLONE_PATH : ${CI_BUILDS_DIR}/${WORKSPACE_ID}/global-workflow
42
44
GIT_DEPTH : 10
@@ -53,19 +55,21 @@ include:
53
55
54
56
.base_config :
55
57
variables :
58
+ badge_GIST_ID : " 66059582886cb5c2485ff64bf24e7f93"
56
59
GIT_STRATEGY : none
57
60
before_script :
58
61
- |
59
- export GW_RUN_PATH="${CI_BUILDS_DIR}/${WORKSPACE_ID}"
60
- export GW_HOMEgfs="${GIT_CLONE_PATH}" # This is set by GitLab for initial clone
61
- export RUNTESTS_DIR="${GW_RUN_PATH}/RUNTESTS"
62
-
62
+ echo "Starting GitLab CI pipeline for global-workflow project"
63
63
PR_NUMBER=${PR_NUMBER:-0}
64
64
if [[ "${PIPELINE_TYPE}" == "ctests" ]]; then
65
65
GFS_CI_RUN_TYPE="ctests"
66
- WORKSPACE_ID="${GFS_CI_RUN_TYPE}_${CI_COMMIT_SHORT_SHA}_${CI_PIPELINE_ID}"
66
+ WORKSPACE_ID="${GFS_CI_RUN_TYPE}_${PR_NUMBER}_${ CI_COMMIT_SHORT_SHA}_${CI_PIPELINE_ID}"
67
67
fi
68
68
69
+ export GW_RUN_PATH="${CI_BUILDS_DIR}/${WORKSPACE_ID}"
70
+ export GW_HOMEgfs="${GIT_CLONE_PATH}" # This is set by GitLab for initial clone
71
+ export RUNTESTS_DIR="${GW_RUN_PATH}/RUNTESTS"
72
+
69
73
# Create a date-based directory name for successful nightly runs
70
74
# on success of nightly pipelines will have the final directory name
71
75
# (GFS_CI_RUN_TYPE)_(SHORT_SHA)_(MMDDYY) such as nightly_affeae_061025
@@ -89,35 +93,84 @@ include:
89
93
exit 1
90
94
fi
91
95
96
+ # Setup GitHub CLI for use throughout the pipeline
97
+ export GH=$(which gh 2>/dev/null || echo "${HOME}/bin/gh")
98
+ if [[ ! -x "${GH}" ]]; then
99
+ echo "ERROR: GitHub CLI (gh) not found or not executable. Please install it."
100
+ exit 1
101
+ fi
102
+
92
103
# Common build template for all modalities
93
104
.build_template :
94
- extends : .base_config
105
+ extends :
106
+ - .base_config
107
+ - .failure_cleanup_template
95
108
variables :
96
109
GIT_STRATEGY : clone
97
110
GIT_SUBMODULE_STRATEGY : recursive
98
111
GIT_SSL_NO_VERIFY : " true" # Address potential certificate verification issues
99
112
stage : build
100
113
script :
101
114
- |
102
- echo "Setting up build environment for ${machine} "
115
+ echo "Setting up build environment for ${machine^}... "
103
116
echo "Using build directory ${GW_HOMEgfs}"
104
117
git submodule status
105
118
# When GFS_CI_RUN_TYPE is set to "nightly", we use the develop branch
106
119
# It should be set when configuring the scheculed nightly pipeline
107
120
if [[ ${GFS_CI_RUN_TYPE} == "pr_cases" && ${PR_NUMBER} != 0 ]]; then
108
- echo "pipeline is set to checkout PR_NUMBER=${PR_NUMBER} from ${GW_REPO_URL}"
121
+ echo "pipeline is set to checkout PR_NUMBER=${PR_NUMBER} from ${GW_REPO_URL} on machine ${machine^}"
122
+ ${GH} pr edit ${PR_NUMBER} --repo ${GW_REPO_URL} --add-label "CI-${machine^}-Building" --remove-label "CI-${machine^}-Ready"
109
123
git remote add github "${GW_REPO_URL}"
110
124
git fetch github
111
- gh pr checkout "${PR_NUMBER}"
125
+ ${GH} pr checkout "${PR_NUMBER}"
112
126
fi
113
127
114
128
dev/ci/scripts/utils/ci_utils.sh build
115
129
build_status=$?
116
130
117
131
if [[ ${build_status} -ne 0 ]]; then
118
132
echo "Build failed with exit code ${build_status}"
133
+ # Mark the build as failed, but don't update labels here - let after_script handle it
119
134
exit 1
135
+ elif [[ ${GFS_CI_RUN_TYPE} == "pr_cases" && ${PR_NUMBER} != 0 ]]; then
136
+ ${GH} pr edit ${PR_NUMBER} --repo ${GW_REPO_URL} --add-label "CI-${machine^}-Running" --remove-label "CI-${machine^}-Building"
120
137
fi
121
138
122
139
sorc/link_workflow.sh
123
140
mkdir -p ${RUNTESTS_DIR}
141
+
142
+ # Reusable template for failure cleanup in after_script
143
+ .failure_cleanup_template :
144
+ after_script :
145
+ - |
146
+ echo "After script is running for job ${CI_JOB_NAME} on ${machine} with status ${CI_JOB_STATUS}"
147
+ if [[ ${CI_JOB_STATUS} == "failed" ]]; then
148
+ Machine="${machine^}"
149
+ echo "Job failed, performing cleanup actions for ${Machine}"
150
+
151
+ # Re-setup GH if needed
152
+ export GH=$(which gh 2>/dev/null || echo "${HOME}/bin/gh")
153
+ if [ ! -x "${GH}" ]; then
154
+ echo "WARNING: GitHub CLI (gh) not found in after_script, trying to continue anyway"
155
+ fi
156
+
157
+ if [[ "${GFS_CI_RUN_TYPE}" == "pr_cases" && "${PR_NUMBER}" != 0 ]]; then
158
+ echo "Updating GitHub labels for PR ${PR_NUMBER} failure on ${Machine}"
159
+ ${GH} pr edit ${PR_NUMBER} --repo ${GW_REPO_URL} \
160
+ --add-label "CI-${Machine}-Failed" \
161
+ --remove-label "CI-${Machine}-Building" \
162
+ --remove-label "CI-${Machine}-Running" || true
163
+
164
+ elif [[ "${GFS_CI_RUN_TYPE}" == "nightly" && "${CI_PIPELINE_SOURCE}" == "schedule" ]]; then
165
+ echo "Updating nightly badge for ${Machine} failure with GIST ID ${badge_GIST_ID}"
166
+ badge_img_file="${TMPDIR:-/tmp}/$(uuidgen)/${machine}_pipeline_badge.svg"
167
+ mkdir -p "$(dirname "${badge_img_file}")"
168
+ curl -sSL "https://img.shields.io/badge/${machine}_nightly-failed-red?style=flat-round&logo=gitlab" -o "${badge_img_file}"
169
+ ${GH} gist edit "${badge_GIST_ID}" --add "${badge_img_file}" || true
170
+
171
+ else
172
+ echo "No cleanup actions needed for GFS_CI_RUN_TYPE=${GFS_CI_RUN_TYPE}, CI_PIPELINE_SOURCE=${CI_PIPELINE_SOURCE}"
173
+ fi
174
+ else
175
+ echo "Job status: ${CI_JOB_STATUS}, no failure cleanup needed"
176
+ fi
0 commit comments