From fb481785c75e1f72d29f329d0fd0cb7d2c8b82a1 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 6 Jan 2020 09:55:47 -0800 Subject: [PATCH] Development (#5) * moved bash script, added try catch for async await * Copying bash script to diff dir --- .github/workflows/cut-release-branch.sh | 16 +++++++++++++ index.js | 31 ++++++++++++++----------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100755 .github/workflows/cut-release-branch.sh diff --git a/.github/workflows/cut-release-branch.sh b/.github/workflows/cut-release-branch.sh new file mode 100755 index 0000000..088a95a --- /dev/null +++ b/.github/workflows/cut-release-branch.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +regexString=$1 + +semanticVersion='' +branchName='' +if [ $regexString ]; then + branchName=$(echo $(git branch -a | grep $regexString | grep -E '([0-9]+\.){2}[0-9]+' | sort --version-sort | tail -n 1 | sed 's@.*/@@')) + semanticVersion=$(echo $(git branch -a | grep $regexString | egrep -o '([0-9]+\.){2}[0-9]+' | sort --version-sort | tail -n 1)) +else + branchName=$(echo $(git branch -a | grep -E '([0-9]+\.){2}[0-9]+' | sort --version-sort | tail -n 1 | sed 's@.*/@@')) + semanticVersion=$(echo $(git branch -a | egrep -o '([0-9]+\.){2}[0-9]+' | sort --version-sort | tail -n 1)) +fi + +echo '{"semanticVersion": "'$semanticVersion'", "branchName": "'$branchName'"}' diff --git a/index.js b/index.js index 6cf5eaf..4fd854b 100644 --- a/index.js +++ b/index.js @@ -32,20 +32,23 @@ try { async function getSemVerBranches(command) { // Get all the branches with the regex prefix and return the last version - const { err, stdout, stderr } = await exec(command, [{ shell: "bash" }]); + try{ + const { err, stdout, stderr } = await exec(command, [{ shell: "bash" }]); - if (err) { - console.log('\x1b[33m%s\x1b[0m', 'Could not find any branches because: '); - console.log('\x1b[31m%s\x1b[0m', stderr); - process.exit(1); - - return; - } - - const data = JSON.parse(stdout); - if (data) { - return data; + if (err) { + console.log('\x1b[33m%s\x1b[0m', 'Could not find any branches because: '); + console.log('\x1b[31m%s\x1b[0m', stderr); + process.exit(1); + + return; + } + + const data = JSON.parse(stdout); + if (data) { + return data; + } + } catch (err) { + console.log(err); + process.exit(0); } - - process.exit(0); } \ No newline at end of file