-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add release tracks to the Monorepo CLI. (#38095)
* Added a tracks sending script. * Added a version diff function. * Added release start event tracking. * Added the point release number check. * Added more logic to the start event data. * Update tools/includes/version-compare.sh Co-authored-by: Brad Jorsch <[email protected]> * Update tools/includes/version-compare.sh Co-authored-by: Brad Jorsch <[email protected]> * Update tools/includes/version-compare.sh Co-authored-by: Brad Jorsch <[email protected]> * Update tools/release-plugin.sh Co-authored-by: Brad Jorsch <[email protected]> * Changed the increment function name to better reflect the getter status. * Changed the version_diff to output actual values. * Optimized the logic a bit, h/t @anomiex. * Removed the unneded function, h/t @anomiex. * Added release step tracking events. * Update tools/includes/send_tracks_event.sh Co-authored-by: tbradsha <[email protected]> * Added a return statement. * Fixed the additional data to be like a flat object. --------- Co-authored-by: Brad Jorsch <[email protected]> Co-authored-by: tbradsha <[email protected]>
- Loading branch information
1 parent
fb3c2bd
commit 6e9ff5d
Showing
3 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# Sends a tracks event. | ||
# - 1: Event name | ||
# - 2: An optional JSON-formatted payload of extra tracks params, e.g. `{"a":1, "b":2}` | ||
function send_tracks_event { | ||
# Bail if no event name is provided. | ||
if [[ -z "$1" ]]; then | ||
return | ||
fi | ||
|
||
local TRACKS_URL TRACKS_RESPONSE USER_AGENT PAYLOAD | ||
TRACKS_URL='https://public-api.wordpress.com/rest/v1.1/tracks/record?http_envelope=1' | ||
USER_AGENT='jetpack-monorepo-cli' | ||
PAYLOAD=$(jq -nr --arg email "$(git config --get user.email)" '.commonProps._ul = $email') | ||
|
||
# Add event name to payload. | ||
PAYLOAD=$(jq -r --arg eventName "$1" '.events = [{_en: $eventName}]' <<< "$PAYLOAD") | ||
|
||
# Add extra params to payload if provided. | ||
if [[ -n "$2" ]]; then | ||
PAYLOAD=$(jq --argjson extraParams "$2" '.events[0] += $extraParams' <<< "$PAYLOAD") | ||
fi | ||
|
||
# True on fail to bypass pipefail. | ||
TRACKS_RESPONSE=$(curl --fail -sS "$TRACKS_URL" \ | ||
-H "User-Agent: $USER_AGENT" \ | ||
-H 'Accept-Encoding: gzip, deflate' \ | ||
-H 'Content-Type: application/json' \ | ||
-H 'Accept: application/json' \ | ||
--data "$PAYLOAD" \ | ||
--compressed 2>&1 || true) | ||
|
||
if ! jq -e . <<< "$TRACKS_RESPONSE" &> /dev/null; then | ||
# Likely a cURL error response. | ||
echo "Invalid response: $TRACKS_RESPONSE" | ||
elif ! jq -e '.code == 202' <<< "$TRACKS_RESPONSE" &> /dev/null; then | ||
# Likely a Tracks error response. | ||
echo "Failed Tracks call: $TRACKS_RESPONSE" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters