<commit_before>#!/bin/bash

set -o errexit

# Check all the required variables are defined
if [ -z "$ACCOUNT" ] || [ -z "$REPO" ] || [ -z "$ACCESS_TOKEN" ] || [ -z "$TRAVIS_TAG" ]; then
	echo "Please set value for ACCOUNT, REPO, ACCESS_TOKEN and TRAVIS_TAG"
	exit 1
fi

# Request the release as it may already exist
release=$(curl https://api.github.com/repos/$ACCOUNT/$REPO/releases/tags/$TRAVIS_TAG)

# Extract the id and the body
id=$(echo $release | jq .id)
body=$(echo $release | jq .body)

# Remove quotes from around the body
body="${body%\"}"
body="${body#\"}"

# Get the release string from travis (AWS download link)
release=$1

# Debugging print
echo ""
echo "START DEBUG"
echo "id: $id"
echo "body: $body"
echo "release: $release"
echo "END DEBUG"
echo ""

# Check the id
if [ $id = "null" ]; then
    # Release does not already exist so we create a new one
    echo "Creating a new $TRAVIS_TAG release"

    json="{
        \"tag_name\": \"$TRAVIS_TAG\",
        \"name\": \"$TRAVIS_TAG\",
        \"body\": \"[Changelog](https://github.com/resin-io/edge-node-manager/blob/master/CHANGELOG.md)\n$release\"
    }"

    curl --data "$json" --header "Content-Type:application/json" \
	    "https://api.github.com/repos/$ACCOUNT/$REPO/releases?access_token=$ACCESS_TOKEN"
else
    # Release already exists so we append to the existing body
    echo "Appending to existing $TRAVIS_TAG release"

    json="{
	\"body\": \"$body\n$release\"
    }"

    curl --data "$json" --header "Content-Type:application/json" \
	-X PATCH "https://api.github.com/repos/$ACCOUNT/$REPO/releases/$id?access_token=$ACCESS_TOKEN"
fi<commit_msg>Fix issue with conflicting travis jobs<commit_after>#!/bin/bash

set -o errexit

# Check all the required variables are defined
if [ -z "$ACCOUNT" ] || [ -z "$REPO" ] || [ -z "$ACCESS_TOKEN" ] || [ -z "$TRAVIS_TAG" ]; then
	echo "Please set value for ACCOUNT, REPO, ACCESS_TOKEN and TRAVIS_TAG"
	exit 1
fi

# Request the release as it may already exist
release=$(curl https://api.github.com/repos/$ACCOUNT/$REPO/releases/tags/$TRAVIS_TAG)

# Extract the id and the body
id=$(echo $release | jq .id)
body=$(echo $release | jq .body)

# Remove quotes from around the body
body="${body%\"}"
body="${body#\"}"

# Get the release string from travis (AWS download link)
release=$1

# Debugging print
echo ""
echo "START DEBUG"
echo "id: $id"
echo "body: $body"
echo "release: $release"
echo "END DEBUG"
echo ""

# Attempt to create a new release instead of checking whether the release already exists
# This avoids situations where the release is created by another job mid way through this script
echo "Attempting to create a new $TRAVIS_TAG release"
json="{
    \"tag_name\": \"$TRAVIS_TAG\",
    \"name\": \"$TRAVIS_TAG\",
    \"body\": \"Release of $TRAVIS_TAG: [changelog](https://github.com/resin-io/edge-node-manager/blob/master/CHANGELOG.md)\n$release\"
}"

resp=$(curl -i --data "$json" --header "Content-Type:application/json" \
	"https://api.github.com/repos/$ACCOUNT/$REPO/releases?access_token=$ACCESS_TOKEN" | \
	head -n 1 | cut -d$' ' -f2)

# Handle the response
if [ $resp = "201" ]; then
    echo "Success"
elif [ $resp = "422" ]; then
    echo "Release already exists, appending instead"

    json="{
	\"body\": \"$body\n$release\"
    }"

    curl --data "$json" --header "Content-Type:application/json" \
	-X PATCH "https://api.github.com/repos/$ACCOUNT/$REPO/releases/$id?access_token=$ACCESS_TOKEN"
fi
{'fraction_non_alphanumeric': 0.1650232018561485, 'fraction_numerical': 0.0034802784222737818, 'mean_word_length': 3.7441540577716643, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3977752', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1165, 'n_words': 352}