-
Notifications
You must be signed in to change notification settings - Fork 12
/
github-release.sh
executable file
·106 lines (80 loc) · 2.79 KB
/
github-release.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
106
#!/bin/sh
# Create a Craft CLI release
#
# Usage: ./github-release.sh <versionNumber>
#
# 1) Change dir to craft-cli repo
# 2) Bumps version number in src/Application.php
# 3) Commit, tag new version and push those changes/tags to origin
# 4) Build new craft.phar
# 5) Create new github release based on new tag
# 6) Upload craft.phar to release
# 7) Change dir to homebrew-craft-cli
# 8) Update craft-cli homebrew formula with latest version (version number, SHA1 hash, download url)
# 9) Commit and push changes to homebrew formula
TAG=$1
if [[ -z $CRAFT_CLI_HOMEBREW_DIR ]]; then
CRAFT_CLI_HOMEBREW_DIR="../../homebrew-craft-cli"
fi
if [[ -z $(which github-release) ]]; then
echo "\x1B[31mYou must first install github-release.\x1B[39m"
exit 1
fi
if [[ -z $(which box) ]]; then
echo "\x1B[31mYou must first install box.\x1B[39m"
exit 1
fi
# check for a valid tag
if [[ -z $TAG ]]; then
echo 'Usage: ./github-release.sh <tag-to-create>'
exit 1
fi
# check if correct repo
if [[ $(git config --get remote.origin.url) != "[email protected]:rsanchez/craft-cli.git" ]]; then
echo "\x1B[31mYou must be in the rsanchez/craft-cli repo.\x1B[39m"
exit 1
fi
# go to root of repo
if [[ -n $(git rev-parse --show-cdup) ]]; then
echo "\x1B[31mYou must be in root of the repo.\x1B[39m"
exit 1
fi
# check if master branch
if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]]; then
echo "\x1B[31mYou must be in the master branch.\x1B[39m"
exit 1
fi
# check if there are any changes
if [[ -n $(git status -s -uno) ]]; then
echo "\x1B[31mYou have uncommitted changes.\x1B[39m"
exit 1
fi
# test github-release credentials
github-release info --user "rsanchez" --repo "craft-cli" >/dev/null || { echo "\x1B[31mYou have invalid github-release credentials.\x1B[39m"; exit 1; }
# replace tag in text
perl -pi -w -e "s/const VERSION = '.*?';/const VERSION = '$TAG';/g;" src/Application.php
# commit version number changes
git add src/Application.php
git commit -m "Release $TAG"
# add new tag
git tag "$TAG"
# push changes
git push origin master
# and tags
git push --tags
# build the phar
box build
# create the github release
github-release release --user "rsanchez" --repo "craft-cli" --tag "$TAG"
# upload the phar to the release
github-release upload --user "rsanchez" --repo "craft-cli" --tag "$TAG" --name craft.phar --file craft.phar
# get sha hash of phar
SHA=$(shasum -a 256 craft.phar | cut -d ' ' -f 1)
cd $CRAFT_CLI_HOMEBREW_DIR
perl -pi -w -e "s/download\/.*?\/craft\.phar/download\/$TAG\/craft.phar/g;" craft-cli.rb
perl -pi -w -e "s/version '.*?'/version '$TAG'/g;" craft-cli.rb
perl -pi -w -e "s/sha1 '.*?'/sha256 '$SHA'/g;" craft-cli.rb
perl -pi -w -e "s/sha256 '.*?'/sha256 '$SHA'/g;" craft-cli.rb
git add craft-cli.rb
git commit -m "Release $TAG"
git push origin master