-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathfunctions.sh
executable file
·105 lines (84 loc) · 2.81 KB
/
functions.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
setup_git() {
echo " Setting up git configuration..."
# Set the user name and email to match the API token holder
# This will make sure the git commits will have the correct photo
# and the user gets the credit for a checkin
git config --global user.email "devops@block.one"
git config --global user.name "blockone-devops"
git config --global push.default matching
# Get the credentials from a file
git config credential.helper "store --file=.git/credentials"
# This associates the API Key with the account
echo "https://${GITHUB_API_KEY}:@github.com" > .git/credentials
echo "✔ Set up git configuration"
}
clean_git() {
echo " Cleaning working tree from changes..."
# Make sure that the workspace is clean
# It could be "dirty" if
# 1. package-lock.json is not aligned with package.json
# 2. npm install is run
git checkout -- .
# Echo the status to the log so that we can see it is OK
git status
clean_tree=$(git diff-index --quiet HEAD --)
if $clean_tree; then
echo "✔ Working tree clean"
return 0
fi
echo "✖ Unable to clean working tree"
echo " Git status:"
git status
return 1
}
check_head() {
echo " Checking if HEAD aligns with master..."
git fetch origin master:master
if ! [ "$(git rev-parse HEAD)" = "$(git show-ref refs/heads/master --hash)" ]; then
echo "✖ Current HEAD does not match head of master!"
echo " - HEAD: $(git rev-parse HEAD)"
echo " - master: $(git show-ref refs/heads/master --hash)"
return 1
fi
echo "✔ Current HEAD matches head of master"
return 0
}
check_version() {
echo " Checking if version of tag matches version in package.json..."
if ! [ "$TRAVIS_TAG" = "$(yarn current-version --silent)" ]; then
echo "✖ Tag does not match the version in package.json!"
echo " - Tag: $TRAVIS_TAG"
echo " - Version: $(yarn current-version --silent)"
return 1
fi
echo "✔ Tag matches version in package.json"
echo " - Tag: $TRAVIS_TAG"
echo " - Version: $(yarn current-version --silent)"
return 0
}
current_version() {
version=$(grep '"version"' package.json | sed 's/.*\([0-9]\.[0-9]\.[0-9].*\)",/\1/g')
echo "$version"
}
update_package_json() {
new_version=$1
sed -i.bak "s/\"version\": \"\([0-9]\.[0-9]\.[0-9].*\)\",/\"version\": \"${new_version}\",/g" package.json
}
publish_edge() {
echo " Publishing edge release to NPM..."
version=$(current_version)
new_version="${version}-${TRAVIS_BUILD_NUMBER}"
update_package_json "$new_version"
git commit -a -m "Updating version [skip ci]"
cp .npmrc.template "$HOME"/.npmrc
npm publish --tag edge
rm package.json.bak
echo "✔ Published edge release"
}
publish_latest() {
echo " Publishing new release to NPM..."
cp .npmrc.template "$HOME"/.npmrc
npm publish
echo "✔ Published new release"
}