BlueGit

ict rusty-teams

Files

rusty-teams / packaging / env.sh

env.sh

feat(packaging): Linux AppImage, deb, rpm and Flatpak
metis Samuel David Merlin Kemper · pushed by metis · 2 weeks ago
228f36c5 History
env.sh 1.8 KiB Download Raw
1# shellcheck shell=bash
2# Shared setup for the packaging scripts. Source it: `. "$(dirname "$0")/../env.sh"`.
3#
4# Exports:
5# ROOT workspace root
6# VERSION [workspace.package] version from Cargo.toml (override: RUSTY_TEAMS_VERSION)
7# DIST output directory for release artifacts (default: $ROOT/dist/release)
8# BUILD_DATE UTC build date, YYYY-MM-DD (override: RUSTY_TEAMS_BUILD_DATE)
9# CARGO_TARGET_DIR cargo's target dir (default: $ROOT/target)
10
11ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
12export ROOT
13
14# The version lives in one place: `[workspace.package] version` in the root Cargo.toml.
15workspace_version() {
16 awk '
17 /^\[/ { in_pkg = ($0 == "[workspace.package]") ; next }
18 in_pkg && $1 == "version" { gsub(/[" ]/, "", $3); print $3; exit }
19 ' "$ROOT/Cargo.toml"
20}
21
22VERSION="${RUSTY_TEAMS_VERSION:-$(workspace_version)}"
23VERSION="${VERSION#v}"
24if [[ -z "$VERSION" ]]; then
25 echo "error: could not read [workspace.package] version from $ROOT/Cargo.toml" >&2
26 exit 1
27fi
28export VERSION
29
30DIST="${DIST:-$ROOT/dist/release}"
31mkdir -p "$DIST"
32export DIST
33
34export BUILD_DATE="${RUSTY_TEAMS_BUILD_DATE:-$(date -u +%Y-%m-%d)}"
35export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}"
36
37# Emit a GitHub Actions warning (plain stderr outside Actions).
38warn() {
39 if [[ -n "${GITHUB_ACTIONS:-}" ]]; then echo "::warning::$*"; else echo "warning: $*" >&2; fi
40}
41
42# Copy licence and readme files that exist into a package directory.
43copy_docs() {
44 local dest="$1" f
45 for f in README.md LICENSE; do
46 if [[ -f "$ROOT/$f" ]]; then cp "$ROOT/$f" "$dest/"; fi
47 done
48}
49
50# Portable SHA-256 of a file (prints just the hash).
51sha256() {
52 if command -v sha256sum >/dev/null; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi
53}