From 882d04bc1140c24559357b3f3f2202d245ab2544 Mon Sep 17 00:00:00 2001 From: geekan Date: Thu, 26 Aug 2021 19:40:36 +0300 Subject: [PATCH 1/3] Added a script for sending commits --- workers/release/scripts/commits.sh | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 workers/release/scripts/commits.sh diff --git a/workers/release/scripts/commits.sh b/workers/release/scripts/commits.sh new file mode 100755 index 00000000..0fd129fd --- /dev/null +++ b/workers/release/scripts/commits.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +# Script help +if [[ "$1" =~ ^-h|--help$ ]] ; then + echo "Usage: `basename $0` [-h] [-p|--path=] [-t|--token=] [-ce|--collectorEndpoint=] + -t | --token : Hawk integration token for your project + -r | --release : Release name. Any string that will be associated with project events + -ce | --collectorEndpoint : Endpoint to send release data. (optional) +" + exit 0 +fi + +# Script arguments +for i in "$@" +do +case $i in + -t=*|--token=*) + token="${i#*=}" + ;; + + -r=*|--release=*) + release="${i#*=}" + ;; + + -ce=*|--collectorEndpoint=*) + collectorEndpoint="${i#*=}" + ;; +esac +done + +# Required fields +if [[ $release == "" ]]; then + echo "Please, provide [--]release name so we can attach commits to this release" + exit 0 +fi + +if [[ $token == "" ]]; then + echo "Please, provide hawk integration [--]token. You can get it in the project integration settings" + exit 0 +fi + +# Checking the git for availability +git --version 2>&1 >/dev/null +isGitAvailable=$? + +# Collecting the last few commits +if [ $isGitAvailable -eq 0 ]; then + commits=$(git --no-pager log --no-color --pretty="{\"hash\":\"%H\",\"title\":\"%s\",\"author\":\"%ae\",\"date\":\"%ad\"}@end@") + lastCommits="[ " + commitsCounter=0 + while [[ $commits ]] && [[ $commitsCounter -lt 5 ]] ; do + if [[ $commits = *@end@* ]]; then + first=${commits%%'@end@'*} + rest=${commits#*'@end@'} + else + first=$commits + rest='' + fi + + let "commitsCounter+=1" + lastCommits="$lastCommits$first," + commits=$rest + done + lastCommits="${lastCommits:0:${#lastCommits}-1}]" +else + echo "Could not find the 'git' command on the machine. You have to install it in order to send commits for release" + exit 0 +fi + +# Create endpoint name +if [[ $collectorEndpoint == "" ]]; then + collectorEndpoint="https://k1.hawk.so/release" + parsedToken=`echo $token | base64 --decode` + integrationId=`echo $parsedToken | awk -F '\"' '{print $4}'` + + if [[ $token != "" ]]; then + collectorEndpoint="https://$integrationId.k1.hawk.so/release" + fi +fi + +# Colors +CYAN='\033[1;36m' +GREEN='\033[1;32m' +BLUE='\033[1;34m' +NO_COLOR='\033[0m' + +echo "${CYAN}Sending ${GREEN}$commitsCounter${CYAN} commits for the ${GREEN}'$release'${CYAN} release to ${BLUE}$collectorEndpoint${NO_COLOR}" + +# Send request to the collector +curl --request POST -F release="$release" -F commits="$lastCommits" ${collectorEndpoint} -H "Authorization: Bearer $token" + +echo \ No newline at end of file From b38e517d585c79b3cd03bb6cdf90730a1e2431f5 Mon Sep 17 00:00:00 2001 From: geekan Date: Thu, 26 Aug 2021 20:00:56 +0300 Subject: [PATCH 2/3] Update README.md --- workers/release/README.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/workers/release/README.md b/workers/release/README.md index bd2c7af6..32a7389f 100644 --- a/workers/release/README.md +++ b/workers/release/README.md @@ -6,26 +6,32 @@ This worker is needed to save releases with commits or/and source-maps uploaded **Current implementation supports only single Rabbit prefetch count (SIMULTANEOUS_TASKS=1)** -## Source maps delivery scheme +## Delivery scheme 1. User wants to deploy project 2. He runs deploy script on the server and it runs static builder, for example Webpack. 3. After Webpack finished his job, our [Webpack Plugin](https://github.com/codex-team/hawk.webpack.plugin) gets a source maps for new bundles and sends them to us. -example request: - -```bash -curl -F file=@"main.min.js.map" -F 'release=$RANDOM' -H "Authorization: Bearer TOKEN" http://localhost:3000/release -``` +Example request: ```bash curl --request POST \ - -F 'release=Verison 1.0'\ + -F 'release=Verison 1.0.1'\ -F 'commits=[{"hash":"557940a440352d9d86ad5610f2e366aafb2729e4","title":"Add some stuff","author":"somebody@codex.so","date":"Wed May 6 13:37:00 2021 +0300"}]'\ - -F "repository=https://github.com/codex-team/hawk.api.nodejs"\ - -F file=@"main.min.js.map" - -H "Authorization: Bearer TOKEN" http://localhost:3000/release + -F file=@"main.min.js.map"\ + -H "Authorization: Bearer INTEGRATION_TOKEN" \ + http://localhost:3000/release ``` -4. Collector accepts file and give a task for ReleaseWorker for saving it to DB -5. ReleaseWorker saves it to DB. +4. Collector accepts files and give a task for ReleaseWorker for saving it to the database. +5. ReleaseWorker saves commits and source maps to the database. + +## Script for sending comments +To make it easier to send commits, you can use a [shell script](./scripts/commits.sh) that will take the last few commits and send them to the collector + +#### Script arguments +| Argument name | Required | Description | +| -- | -- | -- | +| `-t` \| `--token` | Yes | Hawk integration token for your project. | +| `-r` \| `--release` | Yes | Release name. Any string that will be associated with project events. | +| `-ce` \| `--collectorEndpoint` | No | Endpoint to send release data. | \ No newline at end of file From aec927934fe9609fe0edcdaa05da5fd4c9de37f0 Mon Sep 17 00:00:00 2001 From: geekan Date: Thu, 26 Aug 2021 21:14:14 +0300 Subject: [PATCH 3/3] Moved script to other repository and updated readme --- workers/release/README.md | 17 ++---- workers/release/scripts/commits.sh | 92 ------------------------------ 2 files changed, 6 insertions(+), 103 deletions(-) delete mode 100755 workers/release/scripts/commits.sh diff --git a/workers/release/README.md b/workers/release/README.md index 32a7389f..d81da6c9 100644 --- a/workers/release/README.md +++ b/workers/release/README.md @@ -6,11 +6,12 @@ This worker is needed to save releases with commits or/and source-maps uploaded **Current implementation supports only single Rabbit prefetch count (SIMULTANEOUS_TASKS=1)** -## Delivery scheme +## Release delivery scheme 1. User wants to deploy project 2. He runs deploy script on the server and it runs static builder, for example Webpack. 3. After Webpack finished his job, our [Webpack Plugin](https://github.com/codex-team/hawk.webpack.plugin) gets a source maps for new bundles and sends them to us. +4. Also webpack plugin will try to get a few last commits from `.git` directory that will be used to display commits suspected of an error event in the garage. Example request: @@ -23,15 +24,9 @@ curl --request POST \ http://localhost:3000/release ``` -4. Collector accepts files and give a task for ReleaseWorker for saving it to the database. -5. ReleaseWorker saves commits and source maps to the database. +5. Collector accepts commits and source map files and give a task for ReleaseWorker for saving it to the database. +6. ReleaseWorker saves commits and source maps to the database. -## Script for sending comments -To make it easier to send commits, you can use a [shell script](./scripts/commits.sh) that will take the last few commits and send them to the collector +A release doesn't have to contain commits or sourcemaps. But if there is a possibility it will be a useful feature for investigating errors. -#### Script arguments -| Argument name | Required | Description | -| -- | -- | -- | -| `-t` \| `--token` | Yes | Hawk integration token for your project. | -| `-r` \| `--release` | Yes | Release name. Any string that will be associated with project events. | -| `-ce` \| `--collectorEndpoint` | No | Endpoint to send release data. | \ No newline at end of file +To send commits not through the webpack plugin, you can use a script from the [hawk.release](https://github.com/codex-team/hawk.release) repository. \ No newline at end of file diff --git a/workers/release/scripts/commits.sh b/workers/release/scripts/commits.sh deleted file mode 100755 index 0fd129fd..00000000 --- a/workers/release/scripts/commits.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh - -# Script help -if [[ "$1" =~ ^-h|--help$ ]] ; then - echo "Usage: `basename $0` [-h] [-p|--path=] [-t|--token=] [-ce|--collectorEndpoint=] - -t | --token : Hawk integration token for your project - -r | --release : Release name. Any string that will be associated with project events - -ce | --collectorEndpoint : Endpoint to send release data. (optional) -" - exit 0 -fi - -# Script arguments -for i in "$@" -do -case $i in - -t=*|--token=*) - token="${i#*=}" - ;; - - -r=*|--release=*) - release="${i#*=}" - ;; - - -ce=*|--collectorEndpoint=*) - collectorEndpoint="${i#*=}" - ;; -esac -done - -# Required fields -if [[ $release == "" ]]; then - echo "Please, provide [--]release name so we can attach commits to this release" - exit 0 -fi - -if [[ $token == "" ]]; then - echo "Please, provide hawk integration [--]token. You can get it in the project integration settings" - exit 0 -fi - -# Checking the git for availability -git --version 2>&1 >/dev/null -isGitAvailable=$? - -# Collecting the last few commits -if [ $isGitAvailable -eq 0 ]; then - commits=$(git --no-pager log --no-color --pretty="{\"hash\":\"%H\",\"title\":\"%s\",\"author\":\"%ae\",\"date\":\"%ad\"}@end@") - lastCommits="[ " - commitsCounter=0 - while [[ $commits ]] && [[ $commitsCounter -lt 5 ]] ; do - if [[ $commits = *@end@* ]]; then - first=${commits%%'@end@'*} - rest=${commits#*'@end@'} - else - first=$commits - rest='' - fi - - let "commitsCounter+=1" - lastCommits="$lastCommits$first," - commits=$rest - done - lastCommits="${lastCommits:0:${#lastCommits}-1}]" -else - echo "Could not find the 'git' command on the machine. You have to install it in order to send commits for release" - exit 0 -fi - -# Create endpoint name -if [[ $collectorEndpoint == "" ]]; then - collectorEndpoint="https://k1.hawk.so/release" - parsedToken=`echo $token | base64 --decode` - integrationId=`echo $parsedToken | awk -F '\"' '{print $4}'` - - if [[ $token != "" ]]; then - collectorEndpoint="https://$integrationId.k1.hawk.so/release" - fi -fi - -# Colors -CYAN='\033[1;36m' -GREEN='\033[1;32m' -BLUE='\033[1;34m' -NO_COLOR='\033[0m' - -echo "${CYAN}Sending ${GREEN}$commitsCounter${CYAN} commits for the ${GREEN}'$release'${CYAN} release to ${BLUE}$collectorEndpoint${NO_COLOR}" - -# Send request to the collector -curl --request POST -F release="$release" -F commits="$lastCommits" ${collectorEndpoint} -H "Authorization: Bearer $token" - -echo \ No newline at end of file