This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-core.bash
More file actions
executable file
·77 lines (66 loc) · 2.21 KB
/
Copy pathpublish-core.bash
File metadata and controls
executable file
·77 lines (66 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -e
# Similar to Perl die
function die() {
echo "$@" 1>&2 ; exit 1;
}
# Check if our Vagrant box is running. Expects `vagrant status` to look like:
#
# > Current machine states:
# >
# > default poweroff (virtualbox)
# >
# > The VM is powered off. To restart the VM, simply run `vagrant up`
#
# Parameters:
# 1. out_running (out parameter)
function is_running {
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
local __out_running=$1
set +e
vagrant status | sed -n 3p | grep -q "^default\s*running (virtualbox)$"
local retval=${?}
set -e
if [ ${retval} -eq "0" ] ; then
eval ${__out_running}=1
else
eval ${__out_running}=0
fi
}
# Get version, checking we are on the latest
#
# Parameters:
# 1. out_version (out parameter)
# 2. out_error (out parameter)
function get_core_version {
[ "$#" -eq 2 ] || die "2 arguments required, $# provided"
local __out_version=$1
local __out_error=$2
# Extract the version from package.json using Node and save it in a file named "VERSION"
vagrant ssh -c "cd /vagrant/core && node -e \"var fs=require('fs');fs.readFile('./package.json', 'utf8', function(e,d){console.log(JSON.parse(d)['version'])});\" > VERSION" \
|| die "Failed to extract version information from package.json"
file_version=`cat core/VERSION`
expected_tag="core-$file_version"
tag_version=`git describe --abbrev=0 --tags`
if [ ${expected_tag} != ${tag_version} ] ; then
eval ${__out_error}="'File version ${expected_tag} != tag version ${tag_version}'"
else
eval ${__out_version}=${expected_tag}
fi
}
# Go to parent-parent dir of this script
function cd_root() {
source="${BASH_SOURCE[0]}"
while [ -h "${source}" ] ; do source="$(readlink "${source}")"; done
dir="$( cd -P "$( dirname "${source}" )/../.." && pwd )"
cd ${dir}
}
cd_root
# Precondition for running
running=0 && is_running "running"
[ ${running} -eq 1 ] || die "Vagrant guest must be running to push"
# Git tag must match version in package.json
version="" && error="" && get_core_version "version" "error"
[ "${error}" ] && die "Versions don't match: ${error}. Are you trying to publish an old version, or maybe on the wrong branch?"
vagrant ssh -c "cd /vagrant/core && npm adduser && npm publish"
exit 0