From f11a08323824a4eef05982ce8c1ce4262c60acb3 Mon Sep 17 00:00:00 2001 From: Patrik Polakovič Date: May 29 2024 13:36:06 +0000 Subject: Fix/improve the release-candidate script. Signed-off-by: Patrik Polakovic --- diff --git a/release-candidate.sh b/release-candidate.sh index f1c6b25..ac87f99 100755 --- a/release-candidate.sh +++ b/release-candidate.sh @@ -1,50 +1,107 @@ #!/bin/sh +# This script is used to generate Beta and Final release candidate composes. +# Relevant SOPs: +# Beta RC: https://docs.fedoraproject.org/en-US/infra/release_guide/beta_RC_compose/ +# Final RC: https://docs.fedoraproject.org/en-US/infra/release_guide/final_RC_compose/ +# It can be run in dry mode by adding the -d option. +# The -d option is a POSITIONAL argument and must be added AFTER the label. +# Example usage: `./release-candidate.sh 39_Beta-1.3 -d` export LC_ALL=C -# Remove the label from arguments. It gets special treatment. Other arguments -# to the script are passed to pungi-koji directly. +# Remove the label from arguments. It gets special treatment. +# Other arguments to the script are passed to `pungi-koji` directly. LABEL=$1 shift -CONFIG="fedora-final.conf" + +# Find out which config file to use based on the label. +if [[ "$LABEL" = *"Beta"* ]]; then + CONFIG="fedora-beta.conf" + echo "========================================" + echo "CONFIG: $CONFIG" + echo "" +elif [[ "$LABEL" = *"RC"* ]]; then + CONFIG="fedora-final.conf" + echo "========================================" + echo "CONFIG: $CONFIG" + echo "" +else + echo "ERROR: Invalid label." + exit 1 +fi + +# Extract the Fedora version from the label. Example label: 39_RC-1.1 FEDORA_VERSION="${LABEL%%_*}" TARGET_DIR="/mnt/koji/compose/${FEDORA_VERSION}" -#OLD_COMPOSES_DIR="--old-composes=/mnt/fedora_koji/compose/f23 --old-composes=${TARGET_DIR}" +# OLD_COMPOSES_DIR="--old-composes=/mnt/fedora_koji/compose/f23 --old-composes=${TARGET_DIR}" NIGHTLY="" SKIP_PHASES="--skip-phase=productimg" -DEST=$(pwd) +# DEST=$(pwd) DATE=$(date "+%Y%m%d") -COMPSFILE="comps-f39.xml" +# Comps file nomenclature example: comps-f39.xml +# COMPSFILE="comps-f${FEDORA_VERSION}.xml" TMPDIR=$(mktemp -d /tmp/fedoraRC."${DATE}".XXXX) -RELEASE="f39" +RELEASE="f${FEDORA_VERSION}" SHORT="Fedora" RSYNCPREFIX="sudo -u ftpsync" RSYNCTARGET="/pub/alt/stage/${LABEL}" # Uncomment and edit for resuming a failed compose, e.g. "COMPOSE_ID="Fedora-23-20150530.n.0" # COMPOSE_ID="Fedora-23-20150530.n.0" -# Set up our fedora messaging function, using the releng repo definition +# Find out if the dry run (-d) option was invoked. +DRY_RUN=false +while getopts 'd' opt; do + case "$opt" in + d) DRY_RUN=true ;; + *) echo "Error in command line parsing." >&2 + exit 1 + esac +done + +if "$DRY_RUN"; then + printf "THIS IS A DRY RUN.\n\n" + CMD_PREFIX="echo" +else + printf "THIS IS NOT A DRY RUN.\n\n" + CMD_PREFIX='' +fi + +echo "========================================" +echo "ASSUME THAT THE RELENG REPOSITORY IS AVAILABLE AND REBASE. CLONE IT IF IT'S NOT." +echo "" +if [ -d releng ]; then + $CMD_PREFIX pushd releng + $CMD_PREFIX git pull --rebase + $CMD_PREFIX popd + echo "" +else + $CMD_PREFIX git clone https://pagure.io/releng.git + echo "" +fi + +# Set up our fedora-messaging function using the releng repository definition. +# https://pagure.io/releng/blob/main/f/scripts/fedora-messaging.sh FEDMSG_MODNAME="compose" FEDMSG_CERTPREFIX="releng" . ./releng/scripts/fedora-messaging.sh -# Announce that we are starting, even though we don't know the compose_id yet.. -fedora_message_json_start=$(printf '{"log": "start", "branch": "%s", "arch": "%s", "short": "%s"}' "$RELEASE" "$ARCH" "$SHORT") -send_fedora_message "${fedora_message_json_start}" ${RELEASE} start +echo "========================================" +echo "ANNOUNCE THAT WE ARE STARTING (EVEN THOUGH THE COMPOSE_ID IS NOT YET KNOWN)." +echo "" -# Public URL the synced compose will wind up at, we put them in fedora-messaging -LOCATION="https://dl.fedoraproject.org$RSYNCTARGET" +fedora_message_json_start=$(printf '{"log": "start", "branch": "%s", "short": "%s"}' \ + "$RELEASE" "$SHORT") +$CMD_PREFIX send_fedora_message "${fedora_message_json_start} ${RELEASE} start" +echo "" -# Update fedora_message template -fedora_message_json_start=$(printf '{"log": "start", "branch": "%s", "arch": "%s", "short": "%s", "compose_id": "%s", "location"}' "$RELEASE" "$ARCH" "$SHORT" "$LOCATION") -fedora_message_json_done=$(printf '{"log": "done", "branch": "%s", "arch": "%s", "short": "%s", "location": "%s"}' "$RELEASE" "$ARCH" "$SHORT" "$LOCATION") - -pushd "${TMPDIR}" -git clone https://pagure.io/fedora-comps.git && { - pushd fedora-comps - make "${COMPSFILE}" - cp "${COMPSFILE}" "${DEST}"/ - popd -} -popd +# The `pungi-koji` script checks out the fedora-comps repository so this can be removed (commented out for now). +#pushd "${TMPDIR}" +#git clone https://pagure.io/fedora-comps.git && { +# pushd fedora-comps +# make "${COMPSFILE}" +# cp "${COMPSFILE}" "${DEST}"/ +# popd +#} +#popd +#echo "" CMD="pungi-koji --notification-script=/usr/bin/pungi-fedmsg-notification \ --notification-script=pungi-wait-for-signed-ostree-handler \ @@ -52,25 +109,109 @@ CMD="pungi-koji --notification-script=/usr/bin/pungi-fedmsg-notification \ --label=${LABEL}" if [ -z "${COMPOSE_ID}" ]; then - CMD="${CMD} --target-dir=${TARGET_DIR}" + CMD="${CMD_PREFIX} ${CMD} --target-dir=${TARGET_DIR}" +else + CMD="${CMD_PREFIX} ${CMD} --debug-mode --compose-dir=${TARGET_DIR}/${COMPOSE_ID}" +fi + +echo "========================================" +echo "RUN THE COMPOSE. EXIT IF THE EXIT STATUS IS NOT ZERO." +echo "" + +if ! time ${CMD}; then + echo "ERROR: Command failed with a non-zero exit status." + "$CMD_PREFIX" exit 1 + echo "" +fi +echo "" + +# Check if the compose ID exists and exit if it does not. +if [ ! -f "${TARGET_DIR}"/latest-$SHORT-"${FEDORA_VERSION}"/COMPOSE_ID ]; then + echo "ERROR: No compose ID available." + "$CMD_PREFIX" exit 1 + echo "" +fi + +# Get the compose ID if it exists, exit if it does not. +# Note: The COMPOSE_ID variable is used for debugging purposes so another variable with the same value is needed. +if [ -e "${TARGET_DIR}"/latest-$SHORT-"${FEDORA_VERSION}"/COMPOSE_ID ]; then + COMPOSE_ID_2=$(cat "${TARGET_DIR}"/latest-$SHORT-"${FEDORA_VERSION}"/COMPOSE_ID) +else + echo "ERROR: Compose ID not found." + "$CMD_PREFIX" exit 1 + echo "" +fi + +# Check if the compose STATUS exists and exit if it does not. +if [ ! -f "/mnt/koji/compose/${FEDORA_VERSION}/${COMPOSE_ID_2}/STATUS" ]; then + echo "ERROR: No compose STATUS available." + "$CMD_PREFIX" exit 1 + echo "" +fi + +# Find out what the status of the compose is. Do not proceed if the status is DOOMED. +COMPOSE_STATUS=$(cat "/mnt/koji/compose/${FEDORA_VERSION}/${COMPOSE_ID_2}/STATUS") +echo "========================================" +echo "COMPOSE DETAILS" +echo "Compose ID: ${COMPOSE_ID_2}" +echo "Compose status: ${COMPOSE_STATUS}" +if [ "$COMPOSE_STATUS" = "DOOMED" ]; then + echo "ERROR: The compose status is DOOMED." + "$CMD_PREFIX" exit 1 + echo "" else - CMD="${CMD} --debug-mode --compose-dir=${TARGET_DIR}/${COMPOSE_ID}" + echo "Proceeding to rsync." + echo "" fi -time "$CMD" "$@" +# Update the fedora_message template. +fedora_message_json_start=$(printf '{"log": "start", "branch": "%s", "short": "%s", "compose_id": "%s"}' \ + "$RELEASE" "$SHORT" "$COMPOSE_ID_2") +fedora_message_json_done=$(printf '{"log": "done", "branch": "%s", "short": "%s", "compose_id": "%s"}' \ + "$RELEASE" "$SHORT" "$COMPOSE_ID_2") -# Tell interested persons that the rsync is starting -send_fedora_message "${fedora_message_json_start}" ${RELEASE} rsync.start +echo "========================================" +echo "LET INTERESTED PERSONS KNOW ABOUT THE COMPOSE." +echo "" +$CMD_PREFIX send_fedora_message "${fedora_message_json_done} ${RELEASE} complete" +echo "" +echo "========================================" +echo "TELL INTERESTED PERSONS THAT THE RSYNC IS STARTING." +echo "" +$CMD_PREFIX send_fedora_message "${fedora_message_json_start} ${RELEASE} rsync.start" +echo "" + +echo "========================================" +echo "CREATE THE DIRECTORY TARGETED FOR THE COPY (IF IT DOESN'T EXIST)." +echo "" if [ ! -d "${RSYNCTARGET}" ]; then - $(RSYNCPREFIX) mkdir -m 750 -p "${RSYNCTARGET}" + "${CMD_PREFIX}" "${RSYNCPREFIX}" mkdir -m 750 -p "${RSYNCTARGET}" fi +echo "" + +echo "========================================" +echo "RUN THE SYNCHRONIZATION." +echo "" +ARTIFACTS="Everything Cloud Container Kinoite Labs Server Silverblue Spins \ + Workstation Onyx Sericea metadata" -# Note from documentation: -# If multiple composes are run like 1.2, 1.3, add multiple --link-dest arguments above with multiple composes -${RSYNCPREFIX} sh -c 'for dir in Everything Cloud Container Kinoite Labs Modular Server Silverblue Spins Workstation Onyx Sericea metadata; do rsync -avhH ${TARGET_DIR}/${COMPOSE_ID}/compose/$dir/ ${RSYNCTARGET}/$dir/ --link-dest=/pub/fedora/linux/development/${FEDORA_VERSION}/Everything/ --link-dest=${RSYNCTARGET}/Everything/; done' +for dir in ${ARTIFACTS}; do + ${CMD_PREFIX} "${RSYNCPREFIX} sh -c rsync -avhH ${TARGET_DIR}/${COMPOSE_ID_2}/compose/$dir/ \ +${RSYNCTARGET}/$dir/ --link-dest=/pub/fedora/linux/development/${FEDORA_VERSION}/Everything/ \ +--link-dest=${RSYNCTARGET}/Everything" +done +echo "" -${RSYNCPREFIX} chmod 755 "${RSYNCTARGET}" +echo "========================================" +echo "SET THE PERMISSIONS OF THE SYNCED COMPOSE." +echo "" +if [ -d "${RSYNCTARGET}" ]; then + "${CMD_PREFIX}" "${RSYNCPREFIX}" chmod 755 "${RSYNCTARGET}" +fi +echo "" -# Let interested persons know the rsync is complete -send_fedora_message "${fedora_message_json_done}" ${RELEASE} rsync.complete +echo "========================================" +echo "LET INTERESTED PERSONS KNOW THAT THE RSYNC IS COMPLETE." +echo "" +$CMD_PREFIX send_fedora_message "${fedora_message_json_done} ${RELEASE} rsync.complete"