Debian Codegraph @

etc/ci/before_deploy.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2 # Building and packaging for release
3
4 set -ex
5
6 pack() {
7 local tempdir
8 local out_dir
9 local package_name
10 local gcc_prefix
11
12 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
13 out_dir=$(pwd)
14 package_name="$PROJECT_NAME-${GITHUB_REF/refs\/tags\//}-$TARGET"
15
16 if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
17 gcc_prefix="arm-linux-gnueabihf-"
18 elif [[ $TARGET == "aarch64-unknown-linux-gnu" ]]; then
19 gcc_prefix="aarch64-linux-gnu-"
20 else
21 gcc_prefix=""
22 fi
23
24 # create a "staging" directory
25 mkdir "$tempdir/$package_name"
26
27 # copying the main binary
28 cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/"
29 if [ "$OS_NAME" != windows-latest ]; then
30 "${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME"
31 fi
32
33 # manpage, readme and license
34 cp README.md "$tempdir/$package_name"
35 cp LICENSE "$tempdir/$package_name"
36
37 # archiving
38 pushd "$tempdir"
39 if [ "$OS_NAME" = windows-latest ]; then
40 7z a "$out_dir/$package_name.zip" "$package_name"/*
41 else
42 tar czf "$out_dir/$package_name.tar.gz" "$package_name"/*
43 fi
44 popd
45 rm -r "$tempdir"
46 }
47
48 make_deb() {
49 local tempdir
50 local architecture
51 local version
52 local dpkgname
53 local conflictname
54 local gcc_prefix
55 local homepage
56 local maintainer
57
58 homepage="https://github.com/dandavison/delta"
59 maintainer="Dan Davison <[email protected]>"
60 copyright_years="2019 - "$(date "+%Y")
61
62 case $TARGET in
63 x86_64*)
64 architecture=amd64
65 gcc_prefix=""
66 library_dir=""
67 ;;
68 i686*)
69 architecture=i386
70 gcc_prefix=""
71 library_dir=""
72 ;;
73 aarch64*)
74 architecture=arm64
75 gcc_prefix="aarch64-linux-gnu-"
76 library_dir="-l/usr/aarch64-linux-gnu/lib"
77 ;;
78 arm*hf)
79 architecture=armhf
80 gcc_prefix="arm-linux-gnueabihf-"
81 library_dir="-l/usr/arm-linux-gnueabihf/lib"
82 ;;
83 *)
84 echo "make_deb: skipping target '${TARGET}'" >&2
85 return 0
86 ;;
87 esac
88 version=${GITHUB_REF/refs\/tags\//}
89
90 if [[ $TARGET = *musl* ]]; then
91 dpkgname=$PACKAGE_NAME-musl
92 conflictname=$PROJECT_NAME
93 else
94 dpkgname=$PACKAGE_NAME
95 conflictname=$PROJECT_NAME-musl
96 fi
97
98 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
99
100 # copy the main binary
101 install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
102 "${gcc_prefix}"strip "$tempdir/usr/bin/$PROJECT_NAME"
103
104 # Work out shared library dependencies
105 # dpkg-shlibdeps requires debian/control file. Dummy it and clean up
106 mkdir "./debian"
107 touch "./debian/control"
108 depends="$(dpkg-shlibdeps $library_dir -O "$tempdir/usr/bin/$PROJECT_NAME" 2> /dev/null | sed 's/^shlibs:Depends=//')"
109 rm -rf "./debian"
110
111 # readme and license
112 install -Dm644 README.md "$tempdir/usr/share/doc/$dpkgname/README.md"
113 cat > "$tempdir/usr/share/doc/$dpkgname/copyright" <<EOF
114 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
115 Upstream-Name: $PROJECT_NAME
116 Source: $homepage
117
118 Files: *
119 Copyright: $copyright_years $maintainer
120 License: MIT
121
122 License: MIT
123 Permission is hereby granted, free of charge, to any
124 person obtaining a copy of this software and associated
125 documentation files (the "Software"), to deal in the
126 Software without restriction, including without
127 limitation the rights to use, copy, modify, merge,
128 publish, distribute, sublicense, and/or sell copies of
129 the Software, and to permit persons to whom the Software
130 is furnished to do so, subject to the following
131 conditions:
132 .
133 The above copyright notice and this permission notice
134 shall be included in all copies or substantial portions
135 of the Software.
136 .
137 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
138 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
139 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
140 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
141 SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
142 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
143 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
144 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
145 DEALINGS IN THE SOFTWARE.
146 EOF
147 chmod 644 "$tempdir/usr/share/doc/$dpkgname/copyright"
148
149 # Control file
150 mkdir "$tempdir/DEBIAN"
151 cat > "$tempdir/DEBIAN/control" <<EOF
152 Package: $dpkgname
153 Version: $version
154 Section: utils
155 Priority: optional
156 Maintainer: Dan Davison <[email protected]>
157 Architecture: $architecture
158 Depends: $depends
159 Conflicts: $conflictname
160 Description: Syntax highlighter for git
161 Delta provides language syntax-highlighting, within-line insertion/deletion
162 detection, and restructured diff output for git on the command line.
163 EOF
164
165 fakeroot dpkg-deb -Zxz --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb"
166 }
167
168
169 main() {
170 pack
171 if [[ $TARGET = *linux* ]]; then
172 make_deb
173 fi
174 }
175
176 main