|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -o pipefail |
| 3 | +set -e |
| 4 | + |
| 5 | +# There are cases where you want to build artifact in any given branch. In that |
| 6 | +# scenario - we use date string, but primarily this should always be driven from |
| 7 | +# the tag name. |
| 8 | +if [[ "${CI_COMMIT_TAG}" != "" ]] |
| 9 | +then |
| 10 | + buildVersion="${CI_COMMIT_TAG}" |
| 11 | + echo "Publishing artifacts for tag: ${CI_COMMIT_TAG}" |
| 12 | +else |
| 13 | + buildVersion=$(printf "%s_%s" "$(date -u +%y.%m.%d)" "${CI_PIPELINE_ID}") |
| 14 | + echo "Building artifacts for tag: ${buildVersion}" |
| 15 | +fi |
| 16 | + |
| 17 | +targetFile="sert_${buildVersion}.zip" |
| 18 | +publishBaseUrl="${P_ARTIFACTORY_BASE_URL}/artifactory/xgbu-ace-dev/sert" |
| 19 | +apiBaseUrl="${P_ARTIFACTORY_BASE_URL}/api/storage/xgbu-ace-dev/sert" |
| 20 | + |
| 21 | +# URL's for the version release (e.g. sert_23.11.01.zip) |
| 22 | +publishUrl="${publishBaseUrl}/${targetFile}" |
| 23 | + |
| 24 | +# URL's for teh latest release (e.g. sert_latest.zip). Whenever doing a new build |
| 25 | +# we always duplicate the release file into a file ending in latest. This is so |
| 26 | +# people taking it up can always just grab the latest release, but we still have |
| 27 | +# a version history if anyone wanted to grab a specific version. |
| 28 | +publishUrlLatest="${publishBaseUrl}/sert_latest.zip" |
| 29 | + |
| 30 | +# Create a temporary folder to copy files into that we want to form the zip/release |
| 31 | +# This file-set may evolve over time. |
| 32 | +tmpDir=$(mktemp -d -p .) |
| 33 | + |
| 34 | +# Disable SC2086 because we want the product files to be read directly so it can |
| 35 | +# be sed to copy all the specified files, rather than being treated as a single |
| 36 | +# value. |
| 37 | +# shellcheck disable=SC2086 |
| 38 | +cp -r ${PRODUCT_FILES} "${tmpDir}/" |
| 39 | + |
| 40 | +# Substitute the version string in our release file |
| 41 | +sed -i "s|#DEVELOPMENT_BUILD#|${buildVersion}|g" "${tmpDir}/product/sert/sert_core/seed_data/055_prefs_internal_merge.sql" |
| 42 | + |
| 43 | +(cd "${tmpDir}" && zip -r "../${targetFile}" ./*) |
| 44 | + |
| 45 | +# We have no need for the temp folder now we have zipped up all the files |
| 46 | +rm -rf "${tmpDir}" |
| 47 | + |
| 48 | +# Only publish the artifact to artifactory on tag pipeline |
| 49 | +if [[ "${CI_COMMIT_TAG}" != "" ]] |
| 50 | +then |
| 51 | + # Publishing process can include two files - the version bound to the tag name |
| 52 | + # and a separate version (which is the same file with a different name) using |
| 53 | + # -latest, so consumers can just always pull the latest. |
| 54 | + # |
| 55 | + # Additionally, the published file we will attach properties with the version |
| 56 | + # so consumers can do things programatically - and the short SHA of the reference |
| 57 | + # commit. This is helpful to go to the point in time in the git history. |
| 58 | + # More info on the properties API here: https://jfrog.com/help/r/jfrog-rest-apis/set-item-properties |
| 59 | + |
| 60 | + # First publish the versioned file |
| 61 | + curl -H "Authorization:Bearer ${ARTIFACTORY_ACCESS_TOKEN}" -T "${targetFile}" "${publishUrl}" |
| 62 | + propertiesUrl="${apiBaseUrl}/${targetFile}?properties=version=${buildVersion};ci_commit_short_sha=${CI_COMMIT_SHORT_SHA}" |
| 63 | + curl -X PUT --fail -H "Authorization:Bearer ${ARTIFACTORY_ACCESS_TOKEN}" "${propertiesUrl}" |
| 64 | + |
| 65 | + # Then create a latest version. BUT we don't want to do this on beta tags. A |
| 66 | + # pattern to adapt is to use `beta.` prefix on the tag when doing some testing. |
| 67 | + # In that scenario, we don't want to affect the latest version that gets published. |
| 68 | + if [[ ! "${CI_COMMIT_TAG}" =~ ^beta\..+ ]] |
| 69 | + then |
| 70 | + curl -H "Authorization:Bearer ${ARTIFACTORY_ACCESS_TOKEN}" -T "${targetFile}" "${publishUrlLatest}" |
| 71 | + propertiesUrlLatest="${apiBaseUrl}/sert_latest.zip?properties=version=${buildVersion};ci_commit_short_sha=${CI_COMMIT_SHORT_SHA}" |
| 72 | + curl -X PUT --fail -H "Authorization:Bearer ${ARTIFACTORY_ACCESS_TOKEN}" "${propertiesUrlLatest}" |
| 73 | + fi |
| 74 | +fi |
0 commit comments