#!/bin/bash #------------------------------------------------------------------------------ set -u declare Version=1.2.0.HI.2 # 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, and is part of the directory path. declare Product=HelixInstaller declare product=helix-installer declare JobBaseURL="https://swarm.workshop.perforce.com/jobs" 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 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.md 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 "**${DateString}**: ${NewReleaseTag#Rev\. }\\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)) 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") JobURL="$JobBaseURL/$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 # echo -e "$j ($TypeTag): $Description" >> "$NewRelNotesFile" echo -e "* [$j]($JobURL) ($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\\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." msg "\\nMassage the release notes and changelist description as needed.\\nThen do:\\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 | |
---|---|---|---|---|---|
#2 | 26791 | C. Thomas Tyler |
Adapted to Markdown format of ReleaseNotes.md file, and other minor refinements. |
||
#1 | 26786 | C. Thomas Tyler |
Added initial relase notes generator for Helix Insetaller, based on SDP version. Further tweaks are needed to account for Markdown format rather than raw text in the SDP version. |