-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.tpl.sh
executable file
·110 lines (94 loc) · 3.14 KB
/
release.tpl.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
107
108
109
110
#!/bin/bash
token=""
app_name="writeme"
# extract version from Cargo.toml
version=$(grep -m1 "version" Cargo.toml | sed 's/version = //' | sed 's/"//g')
echo "Program version: $version"
# Run cargo build with the --release flag
cargo build --release
path="target/release"
cd $path
target_darwin_arm64="$app_name-$version-darwin-arm64.tar.gz"
tar -czf "$target_darwin_arm64" "$app_name"
echo "Created $target_darwin_arm64"
cd ../..
# {REPO_NAME}-{VERSION}-{OPERATING_SYSTEM}-{ARCHITECTURE}.tar.gz
cargo build --release --target=x86_64-apple-darwin
path_x86="target/x86_64-apple-darwin/release"
cd $path_x86
target_darwin_amd64="$app_name-$version-darwin-amd64.tar.gz"
tar -czf "$target_darwin_amd64" "$app_name"
echo "Created $target_darwin_amd64"
cd ../../..
# github release
# requires curl and jq on PATH: https://stedolan.github.io/jq/
# create a new release
# user: user's name
# repo: the repo's name
# token: github api user token
# tag: name of the tag pushed
create_release() {
user=$1
repo="writeme"
tag="v$version"
# Get the previous release version
previous_tag=$(git describe --abbrev=0 --tags)
# Generate the changelog URL
changelog_url="https://github.com/$user/$repo/compare/$previous_tag...$tag"
# Create the release body with the changelog URL
body="**Full Changelog**: $changelog_url"
command="curl -s -w '%{http_code}' \
--request POST \
--header 'authorization: Bearer ${token}' \
--header 'content-type: application/json' \
--data '{\"tag_name\": \"${tag}\", \"body\": \"$body\"}' \
https://api.github.com/repos/$user/$repo/releases"
http_code=$(eval $command)
if [ $http_code == "201" ]; then
echo "created release:"
cat release.json
upload_release_file "$path/$target_darwin_arm64" "$target_darwin_arm64"
upload_release_file "$path_x86/$target_darwin_amd64" "$target_darwin_amd64"
rm "$path/$target_darwin_arm64"
rm "$path_x86/$target_darwin_amd64"
else
echo "create release failed with code '$http_code':"
cat release.json
echo "command:"
echo $command
return 1
fi
}
# upload a release file.
# this must be called only after a successful create_release, as create_release saves
# the json response in release.json.
# token: github api user token
# file: path to the asset file to upload
# name: name to use for the uploaded asset
upload_release_file() {
file=$1
name=$2
url=$(jq -r .upload_url release.json | cut -d{ -f'1')
command="\
curl -s -w '%{http_code}' \
--request POST \
--header 'authorization: Bearer ${token}' \
--header 'Content-Type: application/octet-stream' \
--data-binary '@$file' \
${url}?name=${name}"
http_code=$(eval $command)
if [ $http_code == "201" ]; then
echo "asset $name uploaded:"
jq -r .browser_download_url upload.json
else
echo "upload failed with code '$http_code':"
cat upload.json
echo "command:"
echo $command
return 1
fi
}
create_release "writeme-project"
# Publish to crates.io
cargo publish
echo "Published to crates.io"