-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
93 lines (74 loc) · 2.57 KB
/
run.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
#!/bin/bash
if [ ! -n "$WERCKER_GH_NPM_RELEASE_GHTOKEN" ]; then
fail "missing option \"ghtoken\""
fi
if [ ! -n "$WERCKER_GH_NPM_RELEASE_NPMTOKEN" ]; then
fail "missing option \"npmtoken\""
fi
if [ 'github.com' = "$WERCKER_GIT_DOMAIN" ]; then
repo="$WERCKER_GIT_OWNER/$WERCKER_GIT_REPOSITORY"
else
fail "missing option \"repo\""
fi
remote="https://[email protected]/$repo.git"
if [ -n "$WERCKER_GH_NPM_RELEASE_BRANCH" ]; then
branch="$WERCKER_GH_NPM_RELEASE_BRANCH"
else
fail "missing option \"branch\""
fi
info "using \"$repo\""
info "using branch \"$branch\""
git config user.email "[email protected]"
git config user.name "werckerbot"
git config push.default simple
git remote set-url origin "$remote"
git checkout "$branch"
git merge "origin/$WERCKER_GIT_BRANCH"
# the VERSION number is incremented after the merge is happened, so this always needs to have the latest published version
VERSION=$(node -p "require('./package.json').version" | awk -F. -v OFS=. '$NF=sprintf("%0*d", length($NF), ($NF+1));')
# update package.json file and create a new git tag
yarn version --new-version "$VERSION"
if [ "$WERCKER_GH_NPM_RELEASE_DRYRUN" = "false" ]; then
git push && git push --tags
if [ $? -ne 0 ]; then
fail "failed deploying a new version to github"
fi
else
echo "[dryrun] skipping git push..."
fi
# npm credentials
touch .npmrc
echo "//registry.npmjs.org/:_authToken=$WERCKER_GH_NPM_RELEASE_NPMTOKEN" >> .npmrc
while read pkg; do
name=$(node -e "console.log(require(\"$pkg\").name)")
published=$(npm view "$name" version 2>/dev/null)
current=$(node -e "console.log(require(\"$pkg\").version)")
if [ "$published" != "$current" ]; then
if [ -n "$WERCKER_GH_NPM_RELEASE_PACKER" ]; then
npm run "$WERCKER_GH_NPM_RELEASE_PACKER"
packagename="package"
else
npm pack
packagename="$name-$current"
packagename="${packagename/\//-}"
packagename="${packagename/@/}"
fi
mkdir -p .tmp/release
tar xf "$packagename.tgz" -C .tmp/release
cp .npmrc .tmp/release
if [ "$WERCKER_GH_NPM_RELEASE_DRYRUN" = "false" ]; then
(cd .tmp/release/package && yarn publish --access "$WERCKER_GH_NPM_RELEASE_ACCESS" --new-version "$VERSION")
else
echo "[dryrun] skipping npm publish..."
(cd .tmp/release/package && find . -name './*' && cat package.json)
echo "the next release will be $VERSION"
fi
else
fail "already published"
fi
done < <(find . -name package.json -maxdepth 1)
if [ $? -ne 0 ]; then
fail "failed deploying a new version to npm"
else
success "ok"
fi