Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion hack/release-branch-pipeline-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,40 @@ EOT
awk "$awk_query" <(git show main:$MAIN_PR_PIPELINE) > $RELEASE_PR_PIPELINE
awk "$awk_query" <(git show main:$MAIN_PUSH_PIPELINE) > $RELEASE_PUSH_PIPELINE

# Set the CPE and name labels in Dockerfile.dist for the release branch.
# The TAS (Trusted Artifact Signer) version doesn't necessarily follow
# the Conforma version, so it must be provided explicitly.
TAS_VERSION="${TAS_VERSION:-}"
if [[ -z "$TAS_VERSION" ]]; then
read -rp "Enter the TAS version for this release (e.g. 1.5): " TAS_VERSION

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] error-handling

read -rp runs unguarded under set -o errexit. In a non-interactive context (CI, stdin closed) read returns non-zero on EOF, which under errexit terminates the script immediately with no output; the intended echo Error: TAS version is required at line 103 is never reached. Callers see a bare non-zero exit with no explanation.

Suggested fix: read -rp "..." TAS_VERSION || true, or guard with if [[ -t 0 ]]; then read -rp ...; fi, so the subsequent [[ -z "$TAS_VERSION" ]] check runs and emits the informative error.

fi

if [[ -z "$TAS_VERSION" ]]; then
echo "Error: TAS version is required"
exit 1
fi

if [[ ! "$TAS_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "Error: TAS version must be in MAJOR.MINOR format (e.g. 1.5), got: ${TAS_VERSION}"
exit 1
fi

sed -i.bak -e 's|name="ec"|name="rhtas/ec-rhel9"|' Dockerfile.dist
rm -f Dockerfile.dist.bak
sed -i.bak -e "/name=\"rhtas\/ec-rhel9\"/a\\
cpe=\"cpe:/a:redhat:trusted_artifact_signer:${TAS_VERSION}::el9\" \\\\" Dockerfile.dist
rm -f Dockerfile.dist.bak

grep -q "cpe:/a:redhat:trusted_artifact_signer:${TAS_VERSION}::el9" Dockerfile.dist || {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] correctness

grep -q cpe:/a:redhat:trusted_artifact_signer:${TAS_VERSION}::el9 interpolates ${TAS_VERSION} (containing a literal .) into a BRE, where . matches any character. The ^[0-9]+.[0-9]+$ validator makes a false positive essentially impossible in practice, but defensive scripting prefers fixed-string matching.

Suggested fix: Use grep -qF to treat the pattern as a fixed string.

echo "Error: failed to update Dockerfile.dist labels (pattern not found — file may already be patched, or the label format changed)"
exit 1
}

echo "Updated Dockerfile.dist labels:"
echo " name=\"rhtas/ec-rhel9\" \\"
echo " cpe=\"cpe:/a:redhat:trusted_artifact_signer:${TAS_VERSION}::el9\""
echo ""

echo "To review the new pipeline definitions:"
echo " vimdiff <(git show main:$MAIN_PR_PIPELINE) $RELEASE_PR_PIPELINE"
echo " vimdiff <(git show main:$MAIN_PUSH_PIPELINE) $RELEASE_PUSH_PIPELINE"
Expand All @@ -100,4 +134,4 @@ echo " vimdiff <(git show release-v$OLD_VERSION:$OLD_RELEASE_PUSH_PIPELINE) $RE
echo ""
echo "If the above comparisons look good then you probably want to do this:"
echo " git rm $MAIN_PR_PIPELINE $MAIN_PUSH_PIPELINE"
echo " git add $RELEASE_PR_PIPELINE $RELEASE_PUSH_PIPELINE"
echo " git add $RELEASE_PR_PIPELINE $RELEASE_PUSH_PIPELINE Dockerfile.dist"
Loading