rel_notes.sh #18

  • //
  • guest/
  • perforce_software/
  • sdp/
  • tools/
  • rel_notes.sh
  • View
  • Commits
  • Open Download .zip Download (10 KB)
#!/bin/bash
#------------------------------------------------------------------------------
set -u
declare Version=1.5.0

# For usage info, see ReleaseProcessOverview.md

# Micro functions.
function dbg () { [[ $DEBUG -eq 1 ]] && echo -e "DEBUG: $*" >&2; }
function msg () { echo -e "$*"; }
function bail () { msg "\\nError: ${1:-Unknown Error}\\n"; exit "${2:-1}"; }
# shellcheck disable=SC2048
function cmd () { msg "Executing: $*"; $*; return $?; }

# $Product can be mixed case, $product is the lowercase form.
declare Product=SDP
# shellcheck disable=SC2155
declare product=$(echo $Product | tr '[:upper:]' '[:lower:]')

declare OldCL=
declare NewCL=
declare UpdateCL=
declare NewEpochTime=
declare DateString=
declare Description=
declare Type=
declare TypeTag=
declare DefaultMajorVersion=
declare MajorVersion=
declare VersionString=
declare Input=
declare JobBaseURL="https://swarm.workshop.perforce.com/projects/perforce-software-sdp/jobs"
declare JobURL=
declare DEBUG=0

# Folder name is assumed to be Product name, normalized to lowercase.
declare DevBranch="//guest/perforce_software/$product/dev"
declare BranchSpec="//guest/perforce_software/$product/dev"
declare Owner=perforce_software
declare BranchSpec="${Owner}-${product}-dev"
declare MainBranch="//guest/perforce_software/$product/main"
declare VersionDepotFile=$DevBranch/Version
declare VersionFile=
declare RelNotesDepotFile="$DevBranch/doc/ReleaseNotes.adoc"
declare RelNotesFile=
declare NewReleaseTag=
declare TmpDir=
declare NewVersionFile=
declare NewRelNotesFile=
declare TmpFile=
declare -i i=
declare -i firstNLines=
declare -i lastNLines=
declare -i NoOp=0

msg "Start ${0##*/} v$Version at $(date)."
TmpDir=$(mktemp -d)
TmpFile="$TmpDir/temp"
NewVersionFile="$TmpDir/Version"
NewRelNotesFile="$TmpDir/${RelNotesDepotFile##*/}"

if [[ $* == *"-n"* ]]; then
   msg "\\nRunning in No-Op (Preview) mode."
   NoOp=1
fi

VersionFile=$(p4 -ztag -F %path% where "$VersionDepotFile")
RelNotesFile=$(p4 -ztag -F %path% where "$RelNotesDepotFile")

# shellcheck disable=SC2143 disable=2086
if [[ -n "$(p4 -s merge -n -b $BranchSpec 2>&1 | grep 'All revision(s) already integrated.')" ]]; then
   msg "Verified: Merge Down preview from main shows dev is updated."
else
   bail "A Merge Down from Main may be required.  Aborting.Check with:\\n\\tp4 -s merge -n -b $BranchSpec\\n"
fi

# shellcheck disable=SC2143 disable=2086
if [[ -n "$(p4 -s opened $DevBranch/... 2>&1 | grep 'not opened on this client')" ]]; then
   msg "Verified: Nothing is checked out in the $Product dev branch."
else
   # shellcheck disable=SC2086
   bail "Failed to verify that no files are checked out in the $Product dev branch.  The 'p4 opened' check shows:\\n$(p4 -s opened $DevBranch/... 2>&1)\\nAborting."
fi

# shellcheck disable=SC2143 disable=2086
if [[ -n "$(p4 status $DevBranch/... 2>&1 | grep 'no file(s) to reconcile.')" ]]; then
   msg "Verified: No excesss files are in the dev branch in your workspace."
else
   # shellcheck disable=SC2086
   bail "The 'p4 status' check failed for $DevBranch.  The 'p4 status' check shows:\\n$(p4 status $DevBranch/... 2>&1)\\nAborting."
fi

# shellcheck disable=SC2143 disable=2086
if [[ -n "$(p4 -s opened $MainBranch/... 2>&1 | grep 'not opened on this client')" ]]; then
   msg "Verified: Nothing is checked out in the $Product main branch."
else
   # shellcheck disable=SC2086
   bail "Failed to verify that no files are checked out in the $Product main branch.  The 'p4 opened' check shows:\\n$(p4 -s opened $MainBranch/... 2>&1)\\nAborting."
fi

# shellcheck disable=SC2143 disable=2086
if [[ -n "$(p4 status $MainBranch/... 2>&1 | grep 'no file(s) to reconcile.')" ]]; then
   msg "Verified: No excesss files are in the main branch in your workspace."
else
   # shellcheck disable=SC2086
   bail "The 'p4 status' check failed for $MainBranch.  The 'p4 status' check shows:\\n$(p4 status $MainBranch/... 2>&1)\\nAborting."
fi

msg Syncing $Product dev and main Branches.
if [[ "$NoOp" -eq 0 ]]; then
   cmd p4 -s sync "$DevBranch/..." "$MainBranch/..." ||\
      bail "Failed to sync $Product dev and main branches. Aborting."
else
   msg "NO-OP: Would run: p4 -s sync $DevBranch/... $MainBranch/..."
fi

# shellcheck disable=SC2002
DefaultMajorVersion=$(cat "$VersionFile"|cut -d '/' -f 3|cut -d ' ' -f 1)
# shellcheck disable=SC2086 disable=SC2116
DefaultMajorVersion=$(echo $DefaultMajorVersion)

# Ask the user for the major version, e.g 2017.1, suggesting a default as whatever the
# current major version is.  In preview mode, assume the default to avoid being
# interactive.
if [[ "$NoOp" -eq 0 ]]; then
   echo -e -n "\\n\\nEnter $Product Major Version for this release [$DefaultMajorVersion]: "
   read -r -e Input

   # shellcheck disable=SC2086 disable=SC2116
   Input=$(echo $Input)
fi

MajorVersion="${Input:-$DefaultMajorVersion}"

NewCL=$(p4 -ztag -F %change% changes -s submitted -m 1 "$DevBranch/...")
[[ -n "$NewCL" ]] ||\
   bail "Could not get latest changelist in dev branch [$DevBranch]. Aborting."
NewEpochTime=$(p4 -ztag -F %time% describe -s "$NewCL")
[[ -n "$NewEpochTime" ]] ||\
   bail "Could not get epoch time for change [$NewCL]. Aborting."

# Given a current changelist number, get the date submitted.  'p4 -ztag'
# tagged/formatted output gives the data in epoch time format.  (We could also
# parse the date from untagged output, so we could do our work parsing or do
# it converting.  Converting deals with left cruft data, parsing might be more
# future proof if the format of the 'date' command changes.  But I don't think
# it will.

# So we convert the 'epoch time' format (just a big integer, number of seconds
# elapsed since midnight, January 1, 1970) to a date in the format we want for
# our current purposes, e.g. '2017/02/17.'  The syntax of the 'date' command to
# convert is platform-specific (and possibly platform-version specific).  This
# code works on Mac OSX Sierra and modern Linux 2.6 kernel, probably others too).
if [[ $(uname -s) == Darwin ]]; then
   # At least as of Mac OSX 10.11.6 El Capitan, the 'time' command is different
   # on Linux.
   DateString=$(date -j -r "$NewEpochTime" +'%Y/%m/%d')
else
   DateString=$(date -d @"$NewEpochTime" +'%Y/%m/%d')
fi

[[ -n "$DateString" ]] ||\
   bail "Could not get date string from epoch time [$NewEpochTime]."

VersionString="${MajorVersion}.${NewCL}"

# shellcheck disable=SC2002
OldCL=$(cat "$VersionFile" | cut -d '/' -f 4)
OldCL=${OldCL%%.*}
OldCL=${OldCL%% *}

echo "Rev. $Product/MultiArch/$MajorVersion/$NewCL ($DateString)." > "$NewVersionFile"

NewReleaseTag=$(head -1 "$NewVersionFile")
NewReleaseTag=${NewReleaseTag%\.}

if [[ "$OldCL" == "$NewCL" ]]; then
   bail "There appear to have been no changes in the dev branch since the last SDP release. Aborting."
fi

i=0; while read -r line; do
   [[ $line == "== Change History" ]] && break
   i=$((i+1))
done < "$RelNotesFile"

dbg i=$i
firstNLines=$((i+2))

dbg FNL="$firstNLines"

# shellcheck disable=SC2002
lines=$(cat "$RelNotesFile" | wc -l)
# shellcheck disable=SC2086 disable=SC2116
lines=$(echo $lines)
dbg Total Lines="$lines"

lastNLines=$((lines-firstNLines+1))

dbg LNL="$lastNLines"

dbg head -"$firstNLines" "$RelNotesFile"
head -"$firstNLines" "$RelNotesFile" > "$NewRelNotesFile"

echo -e "Released: $NewReleaseTag\\n\\nJobs Fixed since change $OldCL up to $NewCL (F=Feature, B=Bug):\\n" >> "$NewRelNotesFile"

# Increment $OldCL by 1 after the message above, to exclude
# jobs associated with the last CL of the prior release.
OldCL=$((OldCL+1))

# Add URLs for fixed jobs in the relesae notes.
for j in $(p4 -ztag -F %Job% jobs "$DevBranch/...@${OldCL},@${NewCL}"); do
   Description=$(p4 -ztag -F %Description% job -o "$j" | head -1)
   Type=$(p4 -ztag -F %Type% job -o "$j")

   # Use a one-letter shorthand for job types.
   case $Type in
      (Feature) TypeTag=F;;
      (Bug) TypeTag=B;;
      (*) TypeTag=$Type;; # For unrecognized types, use the given name.
   esac

   JobURL="$JobBaseURL/$j"

   # Append a bulleted list item containing an AsciiDoc URL ref.
   echo -e "* $JobURL[$j] ($TypeTag): $Description" >> "$NewRelNotesFile"
done

dbg tail -"$lastNLines" "$RelNotesFile"
tail -"$lastNLines" "$RelNotesFile" >> "$NewRelNotesFile"

if [[ "$NoOp" -eq 0 ]]; then
   cmd p4 -s edit "$VersionFile" "$RelNotesFile" ||\
      bail "Failed to checkout Version and Release Notes files [$VersionFile and $RelNotesFile]."

   cmd mv -f "$NewRelNotesFile" "$RelNotesFile" ||\
      bail "Failed to move new Release Notes file in place."

   cmd mv -f "$NewVersionFile" "$VersionFile" ||\
      bail "Failed to move new Version file in place."

   msg "\\nVersion file from/to:"
   cmd p4 diff "$VersionFile"

   msg "\\nUpdates to release notes:"
   cmd p4 diff "$RelNotesFile"

   echo -e "Change: new\\n\\nDescription:\\n\\tUpdated Version to release $Product $VersionString.\\n\\tRe-generated docs.\\n\\nFiles:\\n\\t$RelNotesDepotFile\\n\\t$VersionDepotFile" > "$TmpFile"

   msg "Creating new pending changelist for Version and Release Notes files."
   p4 -s change -i < "$TmpFile" ||\
      bail "Failed to create changelist with Version and Release Notes files."

   UpdateCL=$(p4 -ztag -F %change% opened -m 1 "$DevBranch/...")

   [[ -n "$UpdateCL" ]] ||\
      bail "Could not find newly created pending changelist. Aborting."

   DocDir="$(p4 -ztag -F %path% where "${RelNotesDepotFile%/*}")"
   cd  "$DocDir" || bail "Could not cd to doc dir: $DocDir"
   cmd p4 edit -c "$UpdateCL" "${RelNotesDepotFile%.adoc}.html" "${RelNotesDepotFile%.adoc}.pdf"

   msg "\\nMassage the release notes and changelist description as needed.\\nThen do:\\n\\tcd $DocDir\\n\\tmake clean all\\n\\tp4 rec -c $UpdateCL\\n\\tp4 -s submit -c $UpdateCL"
else
   msg "\\nPreview: Version file would change from/to:"
   diff "$VersionFile" "$NewVersionFile"

   msg "\\nPreview Updates to release notes:"
   diff "$RelNotesFile" "$NewRelNotesFile"

   msg "\\nPreview: Change Desc would be: Updated Version to release $Product $VersionString."

fi

/bin/rm -rf "$TmpDir"
# Change User Description Committed
#24 29835 C. Thomas Tyler Updated Release Process to account for migration to JIRA.

Removed scripts made obsolete by this change to avoid
confusion.
#23 29020 C. Thomas Tyler Added support for new 'Doc' type in jobspec.
#22 28991 C. Thomas Tyler Enhanced to change ':revdate:' field in ReleaseNotes.adoc.
#21 28258 C. Thomas Tyler Enhanced to apply new post-2020.1 versions.
#20 27538 C. Thomas Tyler Added explicit BASH version check.
#19 27523 C. Thomas Tyler Added release header.
#18 27461 C. Thomas Tyler Refined AsciiDoc generated doc update part of release process.
#17 27365 C. Thomas Tyler rel_notes.sh v1.4.1:
* Fixed bug in genererated per-job adoc refs.
#16 27329 C. Thomas Tyler Updated user instructions in release notes script, to include
generation of adoc-based release notes.
#15 27119 C. Thomas Tyler Further adoc adaptation.
#14 27117 C. Thomas Tyler Corrected file extension.
#13 27115 C. Thomas Tyler Updated SDP release process doc, adding info on how to ensure
generated script docs are incorporated in AsciiDoc files.

Adjusted generated release notes file from .txt to .adoc format.

Updated rel_notes.sh to add bulleted list items with links to
each fixed job.

Updated old release notes content to use new format (using
disposable link conversion scripts).
#12 26884 C. Thomas Tyler Fixed issue with errors going to stderr not being caught in grep expressions.
#11 25503 C. Thomas Tyler rel_notes.sh: Shellcheck compliance only.
#10 25244 C. Thomas Tyler Enhanced to support patch release versions.
#9 21719 C. Thomas Tyler Added '-n' flag to preview release notes.
Added internal comments.
#8 21336 C. Thomas Tyler Added check to fisrt a merge down preview, and bail if one is
required.  This prevents generating incorrect release notes
that don't account for changes made directly in main.

Also enhanced temp file handling.
#7 21237 C. Thomas Tyler Typo.
#6 20765 C. Thomas Tyler Tweaked.
#5 20756 C. Thomas Tyler Fixed bug showing correct new version in release notes.
#4 20516 C. Thomas Tyler Cosmetic tweak and enhancement to end-user instructions.
#3 20479 C. Thomas Tyler Added release process overview script.

Overhauled release notes helper script.

Fixed bug that listed a job in the release notes for the current
release that was associated with the last changelist of the prior
release.

Updated more of the manual steps in the SDP release process.
#2 19693 C. Thomas Tyler Minor enhancements to release notes script:
* Added job type (Bug/Feature) for each job.
* Generates more of the text needed to copy/paste
  into release notes file.
#1 17316 C. Thomas Tyler Added script to help generate release notes for SDP.