-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpublish-cli
executable file
·119 lines (105 loc) · 4.31 KB
/
publish-cli
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
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
# Purpose : Script builds aah CLI for various OS and ARCH and publishes to GitHub Release
# Script License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
# Creator : Jeevanandam M. (https://github.com/jeevatkm, jeeva@myjeeva.com)
#
# Version History
# ---------------
# v1.0.0 Initial publish aah CLI script created for CLI v0.13.0 release
#
# Usage:
# $ curl -s https://aahframework.org/publish-cli | bash
# OR
# $ wget -qO- https://aahframework.org/publish-cli | bash
trap "exit 1" TERM
set -e
say() {
echo -e $1
}
repo_base_path=$TRAVIS_BUILD_DIR
if [ -z "$repo_base_path" ]; then
script_path=$(realpath "$0")
repo_base_path=$(dirname "$script_path")
fi
build_base_dir=$repo_base_path/artifacts
cli_name=aah
if [ -z "$TRAVIS_TAG" ]; then
cli_version=$(cat $repo_base_path/aah/version.go | grep -oP "([0-9]+([.][0-9]+)+(\-edge|\-beta)?)")
else
cli_version=$TRAVIS_TAG
fi
cli_version=${cli_version#"v"}
cli_import_path=aahframe.work/cli/aah
cli_git_commit_sha=$TRAVIS_COMMIT
build() {
say "Starting aah CLI binary cross-platform builds for v$cli_version ..."
platforms="darwin/amd64 windows/386 windows/amd64 linux/386 linux/amd64"
rm -rf $build_base_dir
mkdir -p $build_base_dir
errors=""
for platform in $platforms; do
goos=${platform%/*}
goarch=${platform#*/}
build_dir=$build_base_dir/$cli_name-v$cli_version-$goos-$goarch
mkdir -p $build_dir
output="$cli_name"
if [[ "$goos" == "windows" ]]; then output="$output.exe"; fi
cmd="GOOS=$goos GOARCH=$goarch go build -o $build_dir/$output -ldflags=\"-s -w -X main.Version=$cli_version -X main.CliCommitID=$cli_git_commit_sha -X main.CliPackaged=true -X main.CliOS=$goos -X main.CliArch=$goarch\" $cli_import_path"
say "Running $cmd"
eval $cmd || errors="$errors $platform"
done
if [[ "$errors" != "" ]]; then
say ""
say "build cli script failed on: $errors"
exit 1
else
say "Finished aah CLI binary cross-platform builds for $platforms"
fi
}
# aah uses only zip archive for all platforms binary packing as a unified.
# So it requires 'unzip' program for installation.
checksum_file="$build_base_dir/sha256-checksum.txt"
archive_checksum() {
say "\nStarting aah CLI binary zip archive and checksum generations ..."
rm -f $checksum_file
for file in $build_base_dir/*/ ; do
if [[ -d "$file" && ! -L "$file" ]]; then
archive_name=$(basename -- "$file")
archive_dir=$(dirname "$file")
say "Packing $archive_name.zip"
cp $repo_base_path/LICENSE "$file/LICENSE.txt"
cp $repo_base_path/LICENSE-3RD-PARTY.txt "$file/LICENSE-3RD-PARTY.txt"
zip -q -r -j $archive_dir/$archive_name.zip $file
sha256=$(sha256sum $archive_dir/$archive_name.zip | cut -d " " -f 1)
echo "$sha256 $archive_name.zip" >> $checksum_file
fi;
done
cat $checksum_file
say "Finished aah CLI binary zip archive and checksum generations."
}
upload() {
say ""
gh_release_tmp_dir="/tmp/github-release"
gh_release_dist_file="linux-amd64-github-release.tar.bz2"
gh_release_download_uri="https://github.com/aktau/github-release/releases/download/v0.7.2/$gh_release_dist_file"
say "Downloading github-release binary $gh_release_dist_file"
curl -sL $gh_release_download_uri -o /tmp/$gh_release_dist_file
mkdir -p $gh_release_tmp_dir
tar -jxf /tmp/$gh_release_dist_file -C $gh_release_tmp_dir
say "Installing github-release into $GOPATH/bin"
cp $gh_release_tmp_dir/bin/linux/amd64/github-release $GOPATH/bin
github-release --version
say "\nStarting aah CLI zip archives upload into GitHub Release v$cli_version ..."
for file in $build_base_dir/*.zip; do
filename=$(basename -- "$file")
say "Uploading $filename"
github-release upload --replace --user go-aah --repo tools --tag "v$cli_version" --name $filename --file $file
done
say "Finished aah CLI zip archives upload into GitHub Release."
checksum_filename=$(basename -- "$checksum_file")
say "\nUploading $checksum_filename"
github-release upload --replace --user go-aah --repo tools --tag "v$cli_version" --name $checksum_filename --file $checksum_file
}
build
archive_checksum
upload