Skip to content

Commit 6319bb5

Browse files
committed
ci: add script to upload build artifacts to Cloudsmith
Add prepare_artifacts_for_cloudsmith.sh which: - Organizes kernel images and DTBs by architecture/platform - Generates git properties file with branch and commit info - Uploads artifacts to Cloudsmith using wiki-scripts utility - Sets Azure pipeline variables for downstream stages Called from azure-pipelines.yml in the Publish_to_Cloudsmith job. Signed-off-by: Liviu Tomoiaga <[email protected]>
1 parent 6fa2182 commit 6319bb5

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/bash -e
2+
# Note: Not using -u because SYSTEM_PULLREQUEST_* vars are unset (not empty) on branch builds.
3+
# Not using -o pipefail because grep returns exit 1 on no match (used in dtb copy loop).
4+
# SPDX-License-Identifier: GPL-2.0-only
5+
#
6+
# Required environment variables:
7+
# SOURCE_DIRECTORY - Directory containing build artifacts (set in azure-pipelines.yml)
8+
# CLOUDSMITH_API_KEY - Cloudsmith API token (secret, passed via env: in pipeline)
9+
#
10+
# Azure DevOps auto-provided variables:
11+
# BUILD_SOURCEVERSION - Commit SHA for the build
12+
# BUILD_SOURCEBRANCH - Full branch ref (e.g., refs/heads/main)
13+
# BUILD_SOURCEBRANCHNAME - Short branch name
14+
#
15+
# PR-only variables (set only for pull request builds):
16+
# SYSTEM_PULLREQUEST_SOURCECOMMITID - PR source commit SHA
17+
# SYSTEM_PULLREQUEST_TARGETBRANCH - PR target branch
18+
# SYSTEM_PULLREQUEST_PULLREQUESTNUMBER - PR number
19+
20+
TIMESTAMP=$(date +%Y_%m_%d-%H_%M_%S)
21+
# For PRs, Azure makes a merge commit (HEAD) because of the shallow copy option
22+
# (which we want). So, GIT_SHA in this case is the actual correct commit inside
23+
# the PR, and MERGE_COMMIT is the commit made by Azure (which we extract the date
24+
# from)
25+
echo "$SYSTEM_PULLREQUEST_TARGETBRANCH"
26+
if [[ "$SYSTEM_PULLREQUEST_SOURCECOMMITID" != "" ]]; then
27+
GIT_SHA=$SYSTEM_PULLREQUEST_SOURCECOMMITID
28+
else
29+
GIT_SHA=$BUILD_SOURCEVERSION
30+
fi
31+
MERGE_COMMIT_SHA=$(git rev-parse --short HEAD)
32+
GIT_SHA_DATE=$(git show -s --format=%cd --date=format:'%Y-%m-%d %H:%M' ${MERGE_COMMIT_SHA} | sed -e "s/ \|\:/-/g")
33+
CLOUDSMITH_REPO="sdg-linux"
34+
SERVER_PATH="${CLOUDSMITH_REPO}/"
35+
if [ "$SYSTEM_PULLREQUEST_TARGETBRANCH" != "" ]; then
36+
BRANCH_NAME="$SYSTEM_PULLREQUEST_TARGETBRANCH"
37+
SERVER_PATH+="PRs/"
38+
else
39+
BRANCH_NAME="$(echo $BUILD_SOURCEBRANCH | awk -F'/' '{print $NF}')"
40+
fi
41+
42+
set_cloudsmith_version_path() {
43+
if [ "$SYSTEM_PULLREQUEST_TARGETBRANCH" != "" ]; then
44+
SERVER_PATH+="$BRANCH_NAME/pr_$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
45+
else
46+
if [ "$BRANCH_NAME" == "main" ]; then
47+
SERVER_PATH+="main"
48+
else
49+
SERVER_PATH+="releases/$BRANCH_NAME"
50+
fi
51+
fi
52+
}
53+
54+
create_extlinux() {
55+
local platform=$1
56+
57+
touch extlinux.conf
58+
if [ "${platform}" == "arria10" ]; then
59+
dtb_name="socfpga_arria10_socdk_sdmmc.dtb"
60+
else
61+
dtb_name="socfpga.dtb"
62+
fi
63+
64+
echo "LABEL Linux Default" > extlinux.conf
65+
echo " KERNEL ../zImage" >> extlinux.conf
66+
echo " FDT ../${dtb_name}" >> extlinux.conf
67+
echo " APPEND root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyS0,115200n8" >> extlinux.conf
68+
}
69+
70+
# Prepare the structure of the folder containing artifacts
71+
artifacts_structure() {
72+
cd ${SOURCE_DIRECTORY}
73+
74+
# Create folder to be uploaded
75+
mkdir ${TIMESTAMP}
76+
77+
# Generate properties file
78+
echo "git_branch=${BUILD_SOURCEBRANCHNAME}" >> ${TIMESTAMP}/git_properties.txt
79+
echo "git_sha=${GIT_SHA}" >> ${TIMESTAMP}/git_properties.txt
80+
echo "git_sha_date=${GIT_SHA_DATE}" >> ${TIMESTAMP}/git_properties.txt
81+
82+
declare -A typeARCH
83+
typeARCH=( ["arm"]="arria10 cyclone5 zynq"
84+
["arm64"]="versal zynqmp"
85+
["microblaze"]="kc705 kcu105 vc707 vcu118 vcu128" )
86+
87+
declare -A image_to_copy
88+
image_to_copy=( ["arria10"]="socfpga_adi_defconfig/zImage"
89+
["cyclone5"]="socfpga_adi_defconfig/zImage"
90+
["zynq"]="zynq_xcomm_adv7511_defconfig/uImage"
91+
["versal"]="adi_versal_defconfig/Image"
92+
["zynqmp"]="adi_zynqmp_defconfig/Image" )
93+
94+
for arch in "${!typeARCH[@]}"; do
95+
mkdir ${TIMESTAMP}/${arch}
96+
for platform in ${typeARCH[$arch]}; do
97+
# First copy kernels and make extlinux files.
98+
if [ "${arch}" != "microblaze" ]; then
99+
image_location="${TIMESTAMP}/${arch}/${platform}"
100+
mkdir ${image_location}
101+
if [ "${platform}" == "arria10" ] || [ "${platform}" == "cyclone5" ]; then
102+
create_extlinux ${platform}
103+
cp ./extlinux.conf ${image_location}
104+
fi
105+
echo "IMAGE: ${image_to_copy[${platform}]}!"
106+
cp ${image_to_copy[${platform}]} ${image_location}
107+
fi
108+
109+
if [ "${arch}" == "microblaze" ]; then
110+
dtbs_to_copy=$(ls -d -1 Microblaze/*)
111+
else
112+
dtbs_to_copy=$(ls -d -1 DTBs/* | grep "${platform}[-|_]")
113+
fi
114+
115+
# Copy DTBs to the correct location
116+
for dtb in ${dtbs_to_copy}; do
117+
cp ${dtb} "${TIMESTAMP}/${arch}"
118+
done
119+
done
120+
done
121+
}
122+
123+
#### Start
124+
artifacts_structure
125+
set_cloudsmith_version_path
126+
# This script is called from azure-pipelines.yml after setting the CLOUDSMITH_API_KEY secret variable
127+
# so we can use it directly here
128+
# Upload to Cloudsmith done using upload_to_cloudsmith.py script from wiki-scripts repo
129+
130+
echo "Uploading artifacts to Cloudsmith repo adi/${CLOUDSMITH_REPO} at path ${SERVER_PATH}/ ..."
131+
132+
python3 ../wiki-scripts/utils/cloudsmith_utils/upload_to_cloudsmith.py \
133+
--repo="${CLOUDSMITH_REPO}" \
134+
--version="${SERVER_PATH}/" \
135+
--local_path="${TIMESTAMP}" \
136+
--tags="git_sha-${GIT_SHA};timestamp_${TIMESTAMP}" \
137+
--token="${CLOUDSMITH_API_KEY}" \
138+
--log_file="upload_to_cloudsmith.log"
139+
140+
# Set these Azure env vars to be used later in the pipeline
141+
echo "##vso[task.setvariable variable=TIMESTAMP;isOutput=true]${TIMESTAMP}"
142+
echo "##vso[task.setvariable variable=BRANCH;isOutput=true]${BRANCH_NAME}"
143+
if [ "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" != "" ]; then
144+
echo "##vso[task.setvariable variable=PR_ID;isOutput=true]$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
145+
else
146+
echo "##vso[task.setvariable variable=PR_ID;isOutput=true]commit"
147+
fi

0 commit comments

Comments
 (0)