|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Promotes the aarch64-linux chef-cli package between |
| 4 | +# habitat channels. Expeditor's built-in promote_habitat_packages does not |
| 5 | +# support aarch64 targets, so this script handles it manually at each |
| 6 | +# promotion stage. |
| 7 | +# |
| 8 | +# Context is auto-detected from EXPEDITOR_ environment variables: |
| 9 | +# - project_promoted: uses EXPEDITOR_SOURCE_CHANNEL → EXPEDITOR_TARGET_CHANNEL |
| 10 | +# - buildkite_hab_build_group_published: defaults to unstable → current |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +PKG_ORIGIN="chef" |
| 15 | +PKG_NAME="chef-cli" |
| 16 | +PKG_TARGET="aarch64-linux" |
| 17 | + |
| 18 | +export HAB_LICENSE="accept-no-persist" |
| 19 | +export HAB_NONINTERACTIVE="true" |
| 20 | + |
| 21 | +# Determine the package version from Expeditor environment variables. |
| 22 | +# For buildkite_hab_build_group_published, the aarch64 build is a separate |
| 23 | +# pipeline (hab_aarch64/build) that runs in parallel with habitat/build. |
| 24 | +# Both build from the same git commit so they produce the same version. |
| 25 | +# The aarch64 target is NOT in .bldr.toml so it's absent from pkg_idents; |
| 26 | +# we extract the version from the x86_64-linux ident instead. |
| 27 | +# Expeditor flattens Hash metadata keys by appending with "_" and stripping |
| 28 | +# non-word chars (\W), then uppercases the key, so: |
| 29 | +# pkg_idents["chef-cli-x86_64-linux"] |
| 30 | +# -> EXPEDITOR_PKG_IDENTS_CHEFCLIX86_64LINUX |
| 31 | +PKG_VERSION="${EXPEDITOR_PKG_VERSION:-${EXPEDITOR_PROMOTABLE:-}}" |
| 32 | +if [[ -z "$PKG_VERSION" && -n "${EXPEDITOR_PKG_IDENTS_CHEFCLIX86_64LINUX:-}" ]]; then |
| 33 | + PKG_VERSION=$(echo "${EXPEDITOR_PKG_IDENTS_CHEFCLIX86_64LINUX}" | cut -d'/' -f3) |
| 34 | +fi |
| 35 | + |
| 36 | +# Determine source and target channels based on Expeditor workload context |
| 37 | +if [[ -n "${EXPEDITOR_TARGET_CHANNEL:-}" ]]; then |
| 38 | + # project_promoted workload |
| 39 | + SOURCE_CHANNEL="${EXPEDITOR_SOURCE_CHANNEL}" |
| 40 | + TARGET_CHANNEL="${EXPEDITOR_TARGET_CHANNEL}" |
| 41 | +else |
| 42 | + # buildkite_hab_build_group_published workload |
| 43 | + SOURCE_CHANNEL="unstable" |
| 44 | + TARGET_CHANNEL="current" |
| 45 | +fi |
| 46 | + |
| 47 | +echo "--- Promoting ${PKG_ORIGIN}/${PKG_NAME} (${PKG_TARGET}) from ${SOURCE_CHANNEL} to ${TARGET_CHANNEL}" |
| 48 | + |
| 49 | +# Use HAB_AUTH_TOKEN from the pipeline secret if available, otherwise fetch from vault |
| 50 | +if [[ -z "${HAB_AUTH_TOKEN:-}" ]]; then |
| 51 | + HAB_AUTH_TOKEN=$(vault kv get -field auth_token account/static/habitat/chef-ci) |
| 52 | + export HAB_AUTH_TOKEN |
| 53 | +fi |
| 54 | + |
| 55 | +# Find the exact aarch64 package ident for this version |
| 56 | +if [[ -n "$PKG_VERSION" ]]; then |
| 57 | + echo "--- Looking up ${PKG_TARGET} package for version ${PKG_VERSION}" |
| 58 | + PKG_IDENT=$(curl -sf "https://bldr.habitat.sh/v1/depot/pkgs/${PKG_ORIGIN}/${PKG_NAME}/${PKG_VERSION}/latest?target=${PKG_TARGET}" | jq -r '.ident_array | join("/")') |
| 59 | +else |
| 60 | + echo "WARNING: No version info available. Skipping aarch64 promotion." |
| 61 | + exit 0 |
| 62 | +fi |
| 63 | + |
| 64 | +if [[ -z "$PKG_IDENT" || "$PKG_IDENT" == "null" ]]; then |
| 65 | + echo "WARNING: No ${PKG_TARGET} package found for version ${PKG_VERSION}. Skipping promotion." |
| 66 | + exit 0 |
| 67 | +fi |
| 68 | + |
| 69 | +echo "--- Found package: ${PKG_IDENT}" |
| 70 | +echo "--- Promoting ${PKG_IDENT} to ${TARGET_CHANNEL} channel" |
| 71 | + |
| 72 | +hab pkg promote "${PKG_IDENT}" "${TARGET_CHANNEL}" "${PKG_TARGET}" |
| 73 | + |
| 74 | +echo "--- Successfully promoted ${PKG_IDENT} (${PKG_TARGET}) to ${TARGET_CHANNEL}" |
0 commit comments