-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-releases.sh
executable file
·136 lines (118 loc) · 4.02 KB
/
build-releases.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# change dir to this script's location
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
if ! command -v mkfs.hfsplus >/dev/null 2>/dev/null; then
echo "mkfs.hfsplus not found on your path"
exit 3
fi
if ! command -v tar >/dev/null 2>/dev/null; then
echo "tar not found on your path"
exit 4
fi
# install latest pkg version
echo installing latest version of pkg bundler
sudo npm install --global pkg
echo '------------------------------------------------------'
echo
# check if pkg binary is available
if ! command -v pkg >/dev/null 2>&1; then
echo "pkg bundler not found on your PATH."
exit 1
fi
# find current sampleman version from git tags
sampleManVersion="$(git tag --points-at "$(git branch --show-current)" | grep '^v')"
installedNodeVersion="$(node --version | grep -oP '\d+\.\d+\.\d+')"
if [[ "$sampleManVersion" == "" ]]; then
# check if repo is clean or need commit
git update-index --refresh >/dev/null 2>&1
if git diff-index --quiet HEAD --; then
sampleManVersion="$(git rev-parse --short HEAD)"
echo "current commit is not tagged as a release, building as commit$sampleManVersion"
else
sampleManVersion="snapshot"
echo "uncommitted changes exist in repo, building as $sampleManVersion"
fi
else
echo "BUILDING SAMPLEMAN $sampleManVersion RELEASES"
fi
echo "> node --version is v$(node --version | grep -oP '\d+\.\d+\.\d+')"
echo
# build targets
for target in "linux-x64" "win-x64" "macos-x64" "macos-arm64"; do
echo "begin building target $target..."
effTarget="$target"
nodeVersion="18.5.0" # enforce 18.5.0 for compability with node-lts-hydrogen
# check latest nodejs prebuilt binary version if none is set yet
if [[ "$nodeVersion" == "" ]]; then
npm install --no-save semver-sort >/dev/null 2>&1
echo "const s = require('semver-sort'); \
console.log(s.desc(process.argv.slice(2))[0])" >.tmp-script.js
nodeVersion="$(node .tmp-script.js $(curl "https://github.com/vercel/pkg-fetch/releases" 2>/dev/null \
| grep -oP 'v\d+\.\d+\.\d+-'"$effTarget" | grep -oP '\d+\.\d+\.\d+'))"
rm .tmp-script.js
fi
echo "> using prebuilt node v$nodeVersion"
mkdir -p releases/
outname="sampleman-$sampleManVersion-$target-node$nodeVersion"
pkg . --targets "node$nodeVersion-$effTarget" \
--output "releases/$outname" \
| grep -i "error!"
if [[ "${PIPESTATUS[0]}" == "0" ]]; then
created="$created $outname"
echo "> done."
else
echo "> failed."
fi
echo
done
echo "stuffing linux builds into .tar.gz archives to preserve "
echo "> executable rights after download..."
echo
for f in $(ls "releases"); do
if [[ "$(echo "$f" | cut -d'-' -f3)" == "linux" ]] && [[ "${f: -7}" != ".tar.gz" ]]; then
echo "begin packing $f..."
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" \
&& cd "releases/" \
&& tar -czf "$f.tar.gz" "$f" \
&& rm "$f" \
&& cd ..
if [[ -e "releases/$f" ]]; then
echo "> failed."
else
echo "> done."
fi
fi
done
echo
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
echo "stuffing macos builds into .dmg containers to preserve"
echo "> executable rights after download..."
echo
mkdir -p "mnt"
for f in $(ls "releases"); do
if [[ "$(echo "$f" | cut -d'-' -f3)" == "macos" ]] && [[ "${f: -4}" != ".dmg" ]]; then
echo "begin packing $f..."
dd if=/dev/zero of="releases/$f.dmg" bs=1M count=$(expr $(du -BM "releases/$f" | grep -oP '^\d+') + 3) >/dev/null 2>&1 \
&& mkfs.hfsplus -v sampleman "releases/$f.dmg" >/dev/null \
&& sudo mount -o loop "releases/$f.dmg" "mnt" \
&& sudo cp -a "releases/$f" "mnt/" \
&& sudo umount "mnt" \
&& rm "releases/$f"
if [[ -e "releases/$f" ]]; then
echo "> failed."
else
echo "> done."
fi
echo
fi
done
rmdir "mnt"
# report how many binaries were created
if [[ "$created" == "" ]]; then
echo "no binaries were created."
else
echo "created $(echo -e "$created" | sed '/^\s*$/d' | wc -w) binaries in ./releases/:"
for cr in $created; do
echo "> $(ls releases/ | grep -F $cr)"
done
fi