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