Skip to content

Commit daaa18d

Browse files
committed
Add Cloudsmith upload step to Azure pipeline
Ensures artifact availability during the transition period. Signed-off-by: Liviu Tomoiaga <Liviu.Tomoiaga@analog.com>
1 parent 20cb952 commit daaa18d

File tree

2 files changed

+172
-1
lines changed

2 files changed

+172
-1
lines changed

azure-pipelines.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ variables:
33
- name: isMain
44
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
55

6+
resources:
7+
repositories:
8+
- repository: wiki-scripts
9+
type: github
10+
name: analogdevicesinc/wiki-scripts
11+
endpoint: analogdevicesinc
12+
613
trigger:
714
- main
815
- next_stable
@@ -176,7 +183,43 @@ stages:
176183
ARTIFACTORY_TOKEN: $(ART_TOKEN)
177184
name: PushArtifacts
178185
displayName: "Push to Artifactory"
179-
186+
- job: Publish_to_Cloudsmith
187+
timeoutInMinutes: 90
188+
pool:
189+
name: Default
190+
demands:
191+
- agent.name -equals linux_default
192+
condition: or(
193+
and(
194+
startsWith(variables['Build.SourceBranch'], 'refs/pull/'),
195+
ne(variables['SYSTEM.PULLREQUEST.ISFORK'], 'true'),
196+
or(
197+
eq(variables['System.PullRequest.TargetBranch'], 'main'),
198+
eq(variables['System.PullRequest.TargetBranch'], 'next_stable'),
199+
startsWith(variables['System.PullRequest.TargetBranch'], '202')
200+
)
201+
),
202+
or(
203+
eq(variables['Build.SourceBranch'], 'refs/heads/main'),
204+
eq(variables['Build.SourceBranch'], 'refs/heads/next_stable'),
205+
startsWith(variables['Build.SourceBranch'], 'refs/heads/202')
206+
)
207+
)
208+
steps:
209+
- checkout: self
210+
fetchDepth: 1
211+
clean: true
212+
- checkout: wiki-scripts
213+
fetchDepth: 1
214+
clean: true
215+
- task: DownloadPipelineArtifact@2
216+
inputs:
217+
path: $(Build.SourcesDirectory)/bin
218+
- bash: bash $(Build.SourcesDirectory)/linux/ci/travis/prepare_artifacts_for_cloudsmith.sh
219+
env:
220+
CLOUDSMITH_API_KEY: $(CLOUDSMITH_API_KEY)
221+
name: PushArtifacts
222+
displayName: "Push to Cloudsmith"
180223
- stage: TestHarness
181224
dependsOn: PushArtifacts
182225
condition: succeeded()
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#!/bin/bash -e
3+
4+
TIMESTAMP=$(date +%Y_%m_%d-%H_%M_%S)
5+
# For PRs, Azure makes a merge commit (HEAD) because of the shallow copy option
6+
# (which we want). So, GIT_SHA in this case is the actual correct commit inside
7+
# the PR, and MERGE_COMMIT is the commit made by Azure (which we extract the date
8+
# from)
9+
echo "$SYSTEM_PULLREQUEST_TARGETBRANCH"
10+
if [[ "$SYSTEM_PULLREQUEST_SOURCECOMMITID" != "" ]]; then
11+
GIT_SHA=$SYSTEM_PULLREQUEST_SOURCECOMMITID
12+
else
13+
GIT_SHA=$BUILD_SOURCEVERSION
14+
fi
15+
MERGE_COMMIT_SHA=$(git rev-parse --short HEAD)
16+
GIT_SHA_DATE=$(git show -s --format=%cd --date=format:'%Y-%m-%d %H:%M' ${MERGE_COMMIT_SHA} | sed -e "s/ \|\:/-/g")
17+
CLOUDSMITH_REPO="sdg-linux"
18+
SERVER_PATH="${CLOUDSMITH_REPO}/"
19+
if [ "$SYSTEM_PULLREQUEST_TARGETBRANCH" != "" ]; then
20+
BRANCH_NAME="$SYSTEM_PULLREQUEST_TARGETBRANCH"
21+
SERVER_PATH+="PRs/"
22+
else
23+
BRANCH_NAME="$(echo $BUILD_SOURCEBRANCH | awk -F'/' '{print $NF}')"
24+
fi
25+
26+
set_cloudsmith_version_path() {
27+
if [ "$SYSTEM_PULLREQUEST_TARGETBRANCH" != "" ]; then
28+
SERVER_PATH+="$BRANCH_NAME/pr_$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
29+
else
30+
if [ "$BRANCH_NAME" == "main" ]; then
31+
SERVER_PATH+="main"
32+
else
33+
SERVER_PATH+="releases/$BRANCH_NAME"
34+
fi
35+
fi
36+
}
37+
38+
create_extlinux() {
39+
local platform=$1
40+
41+
touch extlinux.conf
42+
if [ "${platform}" == "arria10" ]; then
43+
dtb_name="socfpga_arria10_socdk_sdmmc.dtb"
44+
else
45+
dtb_name="socfpga.dtb"
46+
fi
47+
48+
echo "LABEL Linux Default" > extlinux.conf
49+
echo " KERNEL ../zImage" >> extlinux.conf
50+
echo " FDT ../${dtb_name}" >> extlinux.conf
51+
echo " APPEND root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyS0,115200n8" >> extlinux.conf
52+
}
53+
54+
# Prepare the structure of the folder containing artifacts
55+
artifacts_structure() {
56+
cd ${SOURCE_DIRECTORY}
57+
58+
# Create folder to be uploaded
59+
mkdir ${TIMESTAMP}
60+
61+
# Generate properties file
62+
echo "git_branch=${BUILD_SOURCEBRANCHNAME}" >> ${TIMESTAMP}/git_properties.txt
63+
echo "git_sha=${GIT_SHA}" >> ${TIMESTAMP}/git_properties.txt
64+
echo "git_sha_date=${GIT_SHA_DATE}" >> ${TIMESTAMP}/git_properties.txt
65+
66+
declare -A typeARCH
67+
typeARCH=( ["arm"]="arria10 cyclone5 zynq"
68+
["arm64"]="versal zynqmp"
69+
["microblaze"]="kc705 kcu105 vc707 vcu118 vcu128" )
70+
71+
declare -A image_to_copy
72+
image_to_copy=( ["arria10"]="socfpga_adi_defconfig/zImage"
73+
["cyclone5"]="socfpga_adi_defconfig/zImage"
74+
["zynq"]="zynq_xcomm_adv7511_defconfig/uImage"
75+
["versal"]="adi_versal_defconfig/Image"
76+
["zynqmp"]="adi_zynqmp_defconfig/Image" )
77+
78+
for arch in "${!typeARCH[@]}"; do
79+
mkdir ${TIMESTAMP}/${arch}
80+
for platform in ${typeARCH[$arch]}; do
81+
# First copy kernels and make extlinux files.
82+
if [ "${arch}" != "microblaze" ]; then
83+
image_location="${TIMESTAMP}/${arch}/${platform}"
84+
mkdir ${image_location}
85+
if [ "${platform}" == "arria10" ] || [ "${platform}" == "cyclone5" ]; then
86+
create_extlinux ${platform}
87+
cp ./extlinux.conf ${image_location}
88+
fi
89+
echo "IMAGE: ${image_to_copy[${platform}]}!"
90+
cp ${image_to_copy[${platform}]} ${image_location}
91+
fi
92+
93+
if [ "${arch}" == "microblaze" ]; then
94+
dtbs_to_copy=$(ls -d -1 Microblaze/*)
95+
else
96+
dtbs_to_copy=$(ls -d -1 DTBs/* | grep "${platform}[-|_]")
97+
fi
98+
99+
# Copy DTBs to the correct location
100+
for dtb in ${dtbs_to_copy}; do
101+
cp ${dtb} "${TIMESTAMP}/${arch}"
102+
done
103+
done
104+
done
105+
}
106+
107+
#### Start
108+
artifacts_structure
109+
set_cloudsmith_version_path
110+
# This script is called from azure-pipelines.yml after setting the CLOUDSMITH_API_KEY secret variable
111+
# so we can use it directly here
112+
# Upload to Cloudsmith done using upload_to_cloudsmith.py script from wiki-scripts repo
113+
python3 ../wiki-scripts/utils/cloudsmith_utils/upload_to_cloudsmith.py \
114+
--repo="${CLOUDSMITH_REPO}" \
115+
--version="${SERVER_PATH}" \
116+
--local_path="${TIMESTAMP}" \
117+
--tags="git_sha-${GIT_SHA};timestamp_${TIMESTAMP}" \
118+
--token="${CLOUDSMITH_API_KEY}" \
119+
--log_file="upload_to_cloudsmith.log"
120+
121+
# Set these Azure env vars to be used later in the pipeline
122+
echo "##vso[task.setvariable variable=TIMESTAMP;isOutput=true]${TIMESTAMP}"
123+
echo "##vso[task.setvariable variable=BRANCH;isOutput=true]${BRANCH_NAME}"
124+
if [ "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" != "" ]; then
125+
echo "##vso[task.setvariable variable=PR_ID;isOutput=true]$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
126+
else
127+
echo "##vso[task.setvariable variable=PR_ID;isOutput=true]commit"
128+
fi

0 commit comments

Comments
 (0)