OXYGENHUB
◆ v0.9.3 oxygenhub / scripts / dist.sh
6.8 KiB · Bourne Again Shell (bash) · executable · last changed dist: release the hub server for Linux x86_64 on PostgreSQL 19 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
72
    (cd "$OUT/stage" && zip -qr "../$name.zip" "$name")
73
  else
74
    tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
75
  fi
76
  if [ -n "$deb" ]; then
77
    root="$OUT/stage/deb-$deb"
78
    mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME"
79
    install -m 0755 "$built" "$root/usr/bin/$BIN"
80
    cp README.md docs/oh.md "$root/usr/share/doc/$DEB_NAME/"
81
    cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright"
f2c97576 Andy McCall ↶ 82
    # The apt repository at oxygenhub.io (oxygenhub#85): the package ships
83
    # the archive's key and, on its first install, adds the repository, so
84
    # apt upgrade keeps it current. oxy and oh share the files they write.
85
    mkdir -p "$root/usr/share/$DEB_NAME"
86
    install -m 0644 packaging/oxygenhub-archive-keyring.gpg "$root/usr/share/$DEB_NAME/"
87
    sed "s/@PKG@/$DEB_NAME/" >"$root/DEBIAN/postinst" <<'EOF'
88
#!/bin/sh
89
set -e
90
if [ "$1" = configure ]; then
91
  # The key is refreshed on every install, so a new one reaches everyone.
92
  install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg
93
  # The repository is added on the first install only: removing it
94
  # keeps it removed.
95
  L=/etc/apt/sources.list.d/oxygenhub.sources
96
  if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then
97
    cat >"$L" <<SRC
98
Types: deb
99
URIs: https://oxygenhub.io/apt
100
Suites: stable
101
Components: main
73beb84b Andy McCall ↶ 102
Architectures: $(dpkg --print-architecture)
f2c97576 Andy McCall ↶ 103
Signed-By: /usr/share/keyrings/oxygenhub-archive-keyring.gpg
104
SRC
105
  fi
73beb84b Andy McCall ↶ 106
  # Only this machine's architecture: with foreign ones enabled (i386 on
107
  # most amd64 systems) apt otherwise asks for packages the repository
108
  # has not got, and says so on every update. Sources written before
109
  # this get the line too.
110
  if [ -e "$L" ] && ! grep -q "^Architectures:" "$L"; then
111
    sed -i "/^Components:/a Architectures: $(dpkg --print-architecture)" "$L"
112
  fi
f2c97576 Andy McCall ↶ 113
fi
114
EOF
115
    sed "s/@OTHER@/$OTHER_DEB/" >"$root/DEBIAN/postrm" <<'EOF'
116
#!/bin/sh
117
set -e
118
if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then
119
  rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg
120
fi
121
EOF
122
    chmod 0755 "$root/DEBIAN/postinst" "$root/DEBIAN/postrm"
99ca93d6 Andy McCall ↶ 123
    cat >"$root/DEBIAN/control" <<EOF
124
Package: $DEB_NAME
125
Version: $VERSION
126
Architecture: $deb
127
Maintainer: $MAINTAINER
128
Depends: libc6 (>= 2.28)
129
Section: vcs
130
Priority: optional
131
Homepage: $HOMEPAGE
132
Installed-Size: $(du -sk "$root/usr" | cut -f1)
133
Description: $SUMMARY
134
 $DESCRIPTION
135
EOF
136
    dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null
137
  fi
138
done
139
e1540908 Andy McCall ↶ 140
# The hub server for oxygenhub.io on Google Cloud (oxygenhub-gcp's image
141
# job, phase 6): Linux x86_64, PostgreSQL (docs/postgres.md), glibc 2.28.
142
# Earth and small hubs build their own SQLite one (docs/deploy.md).
143
if [ -z "${ONLY:-}" ] || [[ server-linux-x86_64 == $ONLY ]]; then
144
  echo "== server-linux-x86_64 (postgres)"
145
  cargo zigbuild -q --release --locked --target x86_64-unknown-linux-gnu.2.28 -p oxygenhub --bin oxygenhub --features postgres
146
  name="oxygenhub-server-$VERSION-linux-x86_64"
147
  stage="$OUT/stage/$name"
148
  mkdir -p "$stage"
149
  cp target/x86_64-unknown-linux-gnu/release/oxygenhub "$stage/"
150
  cp LICENSE docs/postgres.md docs/deploy.md "$stage/"
151
  tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
152
fi
153
99ca93d6 Andy McCall ↶ 154
rm -rf "$OUT/stage"
f2c97576 Andy McCall ↶ 155
(cd "$OUT" && shopt -s nullglob && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS)
913e5ad2 Andy McCall ↶ 156
# DIST_FLAT=DIR: the same files again under names without the version, for
157
# a pipeline whose artifacts are fixed paths (the OxygenFlow dist job); the
158
# bytes are the release's, so its assets show as built by that job.
159
if [ -n "${DIST_FLAT:-}" ]; then
160
  mkdir -p "$DIST_FLAT"
161
  for f in "$OUT"/*.tar.gz "$OUT"/*.zip "$OUT"/*.deb "$OUT"/SHA256SUMS; do
162
    [ -e "$f" ] || continue
163
    b=$(basename "$f"); b=${b/-$VERSION-/-}; b=${b/_${VERSION}_/_}
164
    cp "$f" "$DIST_FLAT/$b"
165
  done
166
fi
99ca93d6 Andy McCall ↶ 167
echo "== $OUT"
168
ls -l "$OUT"