-
Notifications
You must be signed in to change notification settings - Fork 919
Add Cloudsmith upload step to Azure pipeline #3042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
liviutomoiaga
wants to merge
2
commits into
main
Choose a base branch
from
staging/add-cloudsmith-upload-step
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| #!/bin/bash -e | ||
liviutomoiaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Note: Not using -u because SYSTEM_PULLREQUEST_* vars are unset (not empty) on branch builds. | ||
| # Not using -o pipefail because grep returns exit 1 on no match (used in dtb copy loop). | ||
| # SPDX-License-Identifier: GPL-2.0-only | ||
| # | ||
| # Required environment variables: | ||
| # SOURCE_DIRECTORY - Directory containing build artifacts (set in azure-pipelines.yml) | ||
| # CLOUDSMITH_API_KEY - Cloudsmith API token (secret, passed via env: in pipeline) | ||
| # | ||
| # Azure DevOps auto-provided variables: | ||
| # BUILD_SOURCEVERSION - Commit SHA for the build | ||
| # BUILD_SOURCEBRANCH - Full branch ref (e.g., refs/heads/main) | ||
| # BUILD_SOURCEBRANCHNAME - Short branch name | ||
| # | ||
| # PR-only variables (set only for pull request builds): | ||
| # SYSTEM_PULLREQUEST_SOURCECOMMITID - PR source commit SHA | ||
| # SYSTEM_PULLREQUEST_TARGETBRANCH - PR target branch | ||
| # SYSTEM_PULLREQUEST_PULLREQUESTNUMBER - PR number | ||
|
|
||
| TIMESTAMP=$(date +%Y_%m_%d-%H_%M_%S) | ||
| # For PRs, Azure makes a merge commit (HEAD) because of the shallow copy option | ||
| # (which we want). So, GIT_SHA in this case is the actual correct commit inside | ||
| # the PR, and MERGE_COMMIT is the commit made by Azure (which we extract the date | ||
| # from) | ||
| echo "$SYSTEM_PULLREQUEST_TARGETBRANCH" | ||
liviutomoiaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ "$SYSTEM_PULLREQUEST_SOURCECOMMITID" != "" ]]; then | ||
| GIT_SHA=$SYSTEM_PULLREQUEST_SOURCECOMMITID | ||
| else | ||
| GIT_SHA=$BUILD_SOURCEVERSION | ||
| fi | ||
| MERGE_COMMIT_SHA=$(git rev-parse --short HEAD) | ||
| GIT_SHA_DATE=$(git show -s --format=%cd --date=format:'%Y-%m-%d %H:%M' ${MERGE_COMMIT_SHA} | sed -e "s/ \|\:/-/g") | ||
| CLOUDSMITH_REPO="linux" | ||
| SERVER_PATH="${CLOUDSMITH_REPO}/" | ||
liviutomoiaga marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+33
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the CLOUDSMITH_REPO variable should still point to "sdg-linux", because that's the repo's name in cloudsmith. My previous comment was referring to the version of the packages, which should be linux/... (i.e. L34 should be |
||
| if [ "$SYSTEM_PULLREQUEST_TARGETBRANCH" != "" ]; then | ||
| BRANCH_NAME="$SYSTEM_PULLREQUEST_TARGETBRANCH" | ||
| SERVER_PATH+="PRs/" | ||
| else | ||
| BRANCH_NAME="$(echo $BUILD_SOURCEBRANCH | awk -F'/' '{print $NF}')" | ||
| fi | ||
|
|
||
| set_cloudsmith_version_path() { | ||
| if [ "$SYSTEM_PULLREQUEST_TARGETBRANCH" != "" ]; then | ||
| SERVER_PATH+="$BRANCH_NAME/pr_$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" | ||
| else | ||
| if [ "$BRANCH_NAME" == "main" ]; then | ||
| SERVER_PATH+="main" | ||
| else | ||
| SERVER_PATH+="releases/$BRANCH_NAME" | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| create_extlinux() { | ||
| local platform=$1 | ||
|
|
||
| touch extlinux.conf | ||
| if [ "${platform}" == "arria10" ]; then | ||
| dtb_name="socfpga_arria10_socdk_sdmmc.dtb" | ||
| else | ||
| dtb_name="socfpga.dtb" | ||
| fi | ||
|
|
||
| echo "LABEL Linux Default" > extlinux.conf | ||
| echo " KERNEL ../zImage" >> extlinux.conf | ||
| echo " FDT ../${dtb_name}" >> extlinux.conf | ||
| echo " APPEND root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyS0,115200n8" >> extlinux.conf | ||
| } | ||
|
|
||
| # Prepare the structure of the folder containing artifacts | ||
| artifacts_structure() { | ||
| cd ${SOURCE_DIRECTORY} | ||
|
|
||
| # Create folder to be uploaded | ||
| mkdir ${TIMESTAMP} | ||
|
|
||
| # Generate properties file | ||
| echo "git_branch=${BUILD_SOURCEBRANCHNAME}" >> ${TIMESTAMP}/git_properties.txt | ||
| echo "git_sha=${GIT_SHA}" >> ${TIMESTAMP}/git_properties.txt | ||
| echo "git_sha_date=${GIT_SHA_DATE}" >> ${TIMESTAMP}/git_properties.txt | ||
|
|
||
| declare -A typeARCH | ||
| typeARCH=( ["arm"]="arria10 cyclone5 zynq" | ||
| ["arm64"]="versal zynqmp" | ||
| ["microblaze"]="kc705 kcu105 vc707 vcu118 vcu128" ) | ||
|
|
||
| declare -A image_to_copy | ||
| image_to_copy=( ["arria10"]="socfpga_adi_defconfig/zImage" | ||
| ["cyclone5"]="socfpga_adi_defconfig/zImage" | ||
| ["zynq"]="zynq_xcomm_adv7511_defconfig/uImage" | ||
| ["versal"]="adi_versal_defconfig/Image" | ||
| ["zynqmp"]="adi_zynqmp_defconfig/Image" ) | ||
|
|
||
| for arch in "${!typeARCH[@]}"; do | ||
| mkdir ${TIMESTAMP}/${arch} | ||
| for platform in ${typeARCH[$arch]}; do | ||
| # First copy kernels and make extlinux files. | ||
| if [ "${arch}" != "microblaze" ]; then | ||
| image_location="${TIMESTAMP}/${arch}/${platform}" | ||
| mkdir ${image_location} | ||
| if [ "${platform}" == "arria10" ] || [ "${platform}" == "cyclone5" ]; then | ||
| create_extlinux ${platform} | ||
| cp ./extlinux.conf ${image_location} | ||
| fi | ||
| echo "IMAGE: ${image_to_copy[${platform}]}!" | ||
| cp ${image_to_copy[${platform}]} ${image_location} | ||
| fi | ||
|
|
||
| if [ "${arch}" == "microblaze" ]; then | ||
| dtbs_to_copy=$(ls -d -1 Microblaze/*) | ||
| else | ||
| dtbs_to_copy=$(ls -d -1 DTBs/* | grep "${platform}[-|_]") | ||
| fi | ||
|
|
||
| # Copy DTBs to the correct location | ||
| for dtb in ${dtbs_to_copy}; do | ||
| cp ${dtb} "${TIMESTAMP}/${arch}" | ||
| done | ||
| done | ||
| done | ||
| } | ||
|
|
||
| #### Start | ||
| artifacts_structure | ||
| set_cloudsmith_version_path | ||
| # This script is called from azure-pipelines.yml after setting the CLOUDSMITH_API_KEY secret variable | ||
| # so we can use it directly here | ||
| # Upload to Cloudsmith done using upload_to_cloudsmith.py script from wiki-scripts repo | ||
|
|
||
| echo "Uploading artifacts to Cloudsmith repo adi/${CLOUDSMITH_REPO} at path ${SERVER_PATH}/ ..." | ||
|
|
||
| python3 ../wiki-scripts/utils/cloudsmith_utils/upload_to_cloudsmith.py \ | ||
| --repo="${CLOUDSMITH_REPO}" \ | ||
| --version="${SERVER_PATH}/" \ | ||
| --local_path="${TIMESTAMP}" \ | ||
| --tags="git_sha-${GIT_SHA};timestamp_${TIMESTAMP}" \ | ||
| --token="${CLOUDSMITH_API_KEY}" \ | ||
| --log_file="upload_to_cloudsmith.log" | ||
|
|
||
| # Set these Azure env vars to be used later in the pipeline | ||
| echo "##vso[task.setvariable variable=TIMESTAMP;isOutput=true]${TIMESTAMP}" | ||
| echo "##vso[task.setvariable variable=BRANCH;isOutput=true]${BRANCH_NAME}" | ||
| if [ "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" != "" ]; then | ||
| echo "##vso[task.setvariable variable=PR_ID;isOutput=true]$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" | ||
| else | ||
| echo "##vso[task.setvariable variable=PR_ID;isOutput=true]commit" | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.