OXYGENHUB
◆ v0.9.22 oxygenhub / scripts / dist.sh
7.7 KiB · Bourne Again Shell (bash) · executable · last changed The source tarball leaves out the job disk's lost+found (refs andymccall/oxygen#157) 6 days ago source blame history raw
99ca93d6 Andy McCall ↶ 1
#!/usr/bin/env bash
2
# Build release archives of one binary for every platform from Linux:
c2732e07 Andy McCall ↶ 3
#   Linux x86_64, arm64 and riscv64 (glibc 2.28 and later): .tar.gz and .deb
99ca93d6 Andy McCall ↶ 4
#   macOS x86_64 and arm64: .tar.gz
5
#   Windows x86_64: .zip
e1540908 Andy McCall ↶ 6
# plus the hub server for Linux x86_64 on PostgreSQL (oxygenhub-server-*),
7
# and SHA256SUMS, in target/dist/VERSION.
99ca93d6 Andy McCall ↶ 8
#
9
#   scripts/dist.sh [VERSION]    (default: the package version)
f2c97576 Andy McCall ↶ 10
#   ONLY=linux-x86_64 scripts/dist.sh   builds one platform (a glob)
99ca93d6 Andy McCall ↶ 11
#
12
# Needs: rustup targets x86_64-pc-windows-gnu, aarch64-unknown-linux-gnu,
c2732e07 Andy McCall ↶ 13
# riscv64gc-unknown-linux-gnu,
99ca93d6 Andy McCall ↶ 14
# x86_64-apple-darwin and aarch64-apple-darwin; cargo-zigbuild and zig on
15
# PATH (Linux with an old glibc, and macOS without Apple's SDK); the
16
# MinGW-w64 gcc (Windows); dpkg-deb and zip.
17
set -euo pipefail
18
19
PKG=oh                   # the cargo package
20
BIN=oh                   # the binary it builds
21
DEB_NAME=oh              # the Debian package
f2c97576 Andy McCall ↶ 22
OTHER_DEB=oxy            # the other package sharing the apt repository files
99ca93d6 Andy McCall ↶ 23
SUMMARY="OxygenHub from the command line"
24
DESCRIPTION="oh talks to an OxygenHub (such as https://oxygenhub.io): issues,
25
 proposals and their reviews, releases, Flow runs and checks, from the
26
 terminal. It works alongside oxy, the Oxygen version control client."
27
HOMEPAGE="https://oxygenhub.io/andymccall/oxygenhub"
28
MAINTAINER="Andy McCall <[email protected]>"
29
DOCS=(README.md LICENSE docs/oh.md)
30
31
cd "$(dirname "$0")/.."
c33dbd9a Andy McCall ↶ 32
VERSION="${1:-$(cargo pkgid -p "$PKG" | sed 's/.*[#@]//')}"
99ca93d6 Andy McCall ↶ 33
VERSION="${VERSION#v}"
34
OUT="target/dist/$VERSION"
35
rm -rf "$OUT" && mkdir -p "$OUT"
36
export PATH="$HOME/.local/opt/zig:$PATH"
37
# Stripped, with no debug info: these are for people, not for debugging.
38
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0
39
# The version the binary reports.
40
export OXY_BUILD="v$VERSION"
41
42
# target triple | platform name | build tool | Debian architecture
43
PLATFORMS=(
44
  "x86_64-unknown-linux-gnu.2.28|linux-x86_64|zig|amd64"
45
  "aarch64-unknown-linux-gnu.2.28|linux-arm64|zig|arm64"
c2732e07 Andy McCall ↶ 46
  "riscv64gc-unknown-linux-gnu.2.28|linux-riscv64|zig|riscv64"
99ca93d6 Andy McCall ↶ 47
  "x86_64-apple-darwin|macos-x86_64|zig|"
48
  "aarch64-apple-darwin|macos-arm64|zig|"
49
  "x86_64-pc-windows-gnu|windows-x86_64|cargo|"
50
)
51
52
for p in "${PLATFORMS[@]}"; do
53
  IFS='|' read -r target platform tool deb <<<"$p"
54
  triple="${target%%.2.*}"
f2c97576 Andy McCall ↶ 55
  # ONLY=linux-x86_64 (a glob) builds just the platforms it matches.
56
  if [ -n "${ONLY:-}" ] && [[ "$platform" != $ONLY ]]; then continue; fi
99ca93d6 Andy McCall ↶ 57
  echo "== $platform ($target)"
58
  if [ "$tool" = zig ]; then
59
    cargo zigbuild -q --release --locked --target "$target" -p "$PKG"
60
  else
61
    cargo build -q --release --locked --target "$target" -p "$PKG"
62
  fi
63
  exe="$BIN"
64
  [[ "$triple" == *windows* ]] && exe="$BIN.exe"
65
  built="target/$triple/release/$exe"
66
  name="$BIN-$VERSION-$platform"
67
  stage="$OUT/stage/$name"
68
  mkdir -p "$stage"
69
  cp "$built" "$stage/"
70
  cp "${DOCS[@]}" "$stage/"
71
  if [[ "$triple" == *windows* ]]; then
5d66f27c Andy McCall ↶ 72
    # PowerShell's built-in alias `oh` (Out-Host) hides oh.exe (#319):
73
    # ohub.exe is the same program under a name nothing hides, and
74
    # install.ps1 puts both on PATH and removes the alias in the profile.
75
    cp "$built" "$stage/ohub.exe"
76
    cp packaging/windows/install.ps1 "$stage/"
99ca93d6 Andy McCall ↶ 77
    (cd "$OUT/stage" && zip -qr "../$name.zip" "$name")
78
  else
79
    tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
80
  fi
81
  if [ -n "$deb" ]; then
82
    root="$OUT/stage/deb-$deb"
83
    mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME"
84
    install -m 0755 "$built" "$root/usr/bin/$BIN"
85
    cp README.md docs/oh.md "$root/usr/share/doc/$DEB_NAME/"
86
    cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright"
f2c97576 Andy McCall ↶ 87
    # The apt repository at oxygenhub.io (oxygenhub#85): the package ships
88
    # the archive's key and, on its first install, adds the repository, so
89
    # apt upgrade keeps it current. oxy and oh share the files they write.
90
    mkdir -p "$root/usr/share/$DEB_NAME"
91
    install -m 0644 packaging/oxygenhub-archive-keyring.gpg "$root/usr/share/$DEB_NAME/"
92
    sed "s/@PKG@/$DEB_NAME/" >"$root/DEBIAN/postinst" <<'EOF'
93
#!/bin/sh
94
set -e
95
if [ "$1" = configure ]; then
96
  # The key is refreshed on every install, so a new one reaches everyone.
97
  install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg
98
  # The repository is added on the first install only: removing it
99
  # keeps it removed.
100
  L=/etc/apt/sources.list.d/oxygenhub.sources
101
  if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then
102
    cat >"$L" <<SRC
103
Types: deb
104
URIs: https://oxygenhub.io/apt
105
Suites: stable
106
Components: main
73beb84b Andy McCall ↶ 107
Architectures: $(dpkg --print-architecture)
f2c97576 Andy McCall ↶ 108
Signed-By: /usr/share/keyrings/oxygenhub-archive-keyring.gpg
109
SRC
110
  fi
73beb84b Andy McCall ↶ 111
  # Only this machine's architecture: with foreign ones enabled (i386 on
112
  # most amd64 systems) apt otherwise asks for packages the repository
113
  # has not got, and says so on every update. Sources written before
114
  # this get the line too.
115
  if [ -e "$L" ] && ! grep -q "^Architectures:" "$L"; then
116
    sed -i "/^Components:/a Architectures: $(dpkg --print-architecture)" "$L"
117
  fi
f2c97576 Andy McCall ↶ 118
fi
119
EOF
120
    sed "s/@OTHER@/$OTHER_DEB/" >"$root/DEBIAN/postrm" <<'EOF'
121
#!/bin/sh
122
set -e
123
if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then
124
  rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg
125
fi
126
EOF
127
    chmod 0755 "$root/DEBIAN/postinst" "$root/DEBIAN/postrm"
99ca93d6 Andy McCall ↶ 128
    cat >"$root/DEBIAN/control" <<EOF
129
Package: $DEB_NAME
130
Version: $VERSION
131
Architecture: $deb
132
Maintainer: $MAINTAINER
133
Depends: libc6 (>= 2.28)
134
Section: vcs
135
Priority: optional
136
Homepage: $HOMEPAGE
137
Installed-Size: $(du -sk "$root/usr" | cut -f1)
138
Description: $SUMMARY
139
 $DESCRIPTION
140
EOF
141
    dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null
142
  fi
143
done
144
e1540908 Andy McCall ↶ 145
# The hub server for oxygenhub.io on Google Cloud (oxygenhub-gcp's image
146
# job, phase 6): Linux x86_64, PostgreSQL (docs/postgres.md), glibc 2.28.
147
# Earth and small hubs build their own SQLite one (docs/deploy.md).
148
if [ -z "${ONLY:-}" ] || [[ server-linux-x86_64 == $ONLY ]]; then
149
  echo "== server-linux-x86_64 (postgres)"
150
  cargo zigbuild -q --release --locked --target x86_64-unknown-linux-gnu.2.28 -p oxygenhub --bin oxygenhub --features postgres
151
  name="oxygenhub-server-$VERSION-linux-x86_64"
152
  stage="$OUT/stage/$name"
153
  mkdir -p "$stage"
154
  cp target/x86_64-unknown-linux-gnu/release/oxygenhub "$stage/"
155
  cp LICENSE docs/postgres.md docs/deploy.md "$stage/"
156
  tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
157
fi
158
93f445fa Andy McCall ↶ 159
# The source as released (oxygen#157): the oxygenhub tree with its subrepos (deps/), so oh builds from it alone,
160
# under oxygenhub-VERSION/, for packagers (haikuports) to fetch from the
161
# release at a fixed checksum. Reproducible: sorted, fixed times and
162
# owners, gzip without a timestamp.
163
if [ -z "${ONLY:-}" ] || [[ src == $ONLY ]]; then
164
  echo "== src"
165
  tar --sort=name --mtime='1970-01-01 00:00:00Z' --owner=0 --group=0 --numeric-owner \
806615f9 Andy McCall ↶ 166
    --mode='u+rwX,go+rX,go-w' --exclude=./target --exclude=./lost+found --exclude=.oxy \
93f445fa Andy McCall ↶ 167
    --transform "s|^\.|oxygenhub-$VERSION|" -cf - . | gzip -9n >"$OUT/$BIN-$VERSION-src.tar.gz"
168
fi
169
99ca93d6 Andy McCall ↶ 170
rm -rf "$OUT/stage"
f2c97576 Andy McCall ↶ 171
(cd "$OUT" && shopt -s nullglob && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS)
913e5ad2 Andy McCall ↶ 172
# DIST_FLAT=DIR: the same files again under names without the version, for
173
# a pipeline whose artifacts are fixed paths (the OxygenFlow dist job); the
174
# bytes are the release's, so its assets show as built by that job.
175
if [ -n "${DIST_FLAT:-}" ]; then
176
  mkdir -p "$DIST_FLAT"
177
  for f in "$OUT"/*.tar.gz "$OUT"/*.zip "$OUT"/*.deb "$OUT"/SHA256SUMS; do
178
    [ -e "$f" ] || continue
179
    b=$(basename "$f"); b=${b/-$VERSION-/-}; b=${b/_${VERSION}_/_}
180
    cp "$f" "$DIST_FLAT/$b"
181
  done
182
fi
99ca93d6 Andy McCall ↶ 183
echo "== $OUT"
184
ls -l "$OUT"