Skip to content

Commit

Permalink
build: replace positional args, use getopt
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer committed Jan 26, 2025
1 parent b38763d commit 0a5840e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
python -m pip install -U --upgrade-strategy=eager -r requirements.txt
- name: Build
run: |
SOURCE_DATE_EPOCH=$(git show -s --format=%ct) ./build.sh "" "" master
SOURCE_DATE_EPOCH=$(git show -s --format=%ct) ./build.sh --gitref=master
- name: Get file name
id: vars
run: |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ Supported architectures: `x86_64`, `aarch64`

```bash
# Build
./build.sh [$ARCH] [$GITREPO] [$GITREF]
./build.sh [--arch=$ARCH] [--gitrepo=$GITREPO] [--gitref=$GITREF]

# Get new list of Python dependencies (for updating config.yml)
./get-dependencies.sh [$ARCH] [$GITREPO] [$GITREF] [$OPT_DEPS]
./get-dependencies.sh [--arch=$ARCH] [--gitrepo=$GITREPO] [--gitref=$GITREF] [depspec...]
```

The AppImages are reproducible when `SOURCE_DATE_EPOCH` is set:
Expand Down
54 changes: 51 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

set -euo pipefail

ARCH="${1:-$(uname -m)}"
GITREPO="${2:-}"
GITREF="${3:-}"
ARCH="$(uname -m)"
GITREPO=""
GITREF=""

ROOT=$(git rev-parse --show-toplevel 2>/dev/null || dirname "$(readlink -f "${0}")")
CONFIG="${ROOT}/config.yml"
Expand All @@ -20,6 +20,10 @@ declare -A DEPS=(
[docker]=docker
)

_OPTS=$(getopt --name "$0" --long 'help,arch:,gitrepo:,gitref:' --options 'help,a:' -- "$@")
eval set -- "${_OPTS}"
unset _OPTS


# ----

Expand All @@ -33,6 +37,50 @@ err() {
exit 1
}

print_help() {
echo "Usage: ${0} [options]"
echo
echo "Options:"
echo " -a, --arch <arch> Target architecture"
echo " --gitrepo <url> Source"
echo " --gitref <ref> Git branch/tag/commit"
exit 0
}


# ----


while true; do
case "${1}" in
-h | --help)
print_help
;;
-a | --arch)
ARCH="${2}"
shift 2
;;
--gitrepo)
GITREPO="${2}"
shift 2
;;
--gitref)
GITREF="${2}"
shift 2
;;
--)
shift
break
;;
*)
err "Invalid option: ${1}"
;;
esac
done


# ----


for dep in "${!DEPS[@]}"; do
command -v "${dep}" >/dev/null 2>&1 || err "Missing dependency: ${DEPS["${dep}"]}"
Expand Down
59 changes: 54 additions & 5 deletions get-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

set -euo pipefail

ARCH="${1:-$(uname -m)}"
GITREPO="${2:-}"
GITREF="${3:-}"
OPT_DEPSPEC=("${@}")
OPT_DEPSPEC=("${OPT_DEPSPEC[@]:3}")
ARCH="$(uname -m)"
GITREPO=""
GITREF=""
OPT_DEPSPEC=()

ROOT=$(git rev-parse --show-toplevel 2>/dev/null || dirname "$(readlink -f "${0}")")
CONFIG="${ROOT}/config.yml"
Expand All @@ -18,6 +17,10 @@ declare -A DEPS=(
[docker]=docker
)

_OPTS=$(getopt --name "$0" --long 'help,arch:,gitrepo:,gitref:' --options 'help,a:' -- "$@")
eval set -- "${_OPTS}"
unset _OPTS


# ----

Expand All @@ -31,6 +34,52 @@ err() {
exit 1
}

print_help() {
echo "Usage: ${0} [options] [depspec]"
echo
echo "Options:"
echo " -a, --arch <arch> Target architecture"
echo " --gitrepo <url> Source"
echo " --gitref <ref> Git branch/tag/commit"
exit 0
}


# ----


while true; do
case "${1}" in
-h | --help)
print_help
;;
-a | --arch)
ARCH="${2}"
shift 2
;;
--gitrepo)
GITREPO="${2}"
shift 2
;;
--gitref)
GITREF="${2}"
shift 2
;;
--)
shift
break
;;
*)
err "Invalid option: ${1}"
;;
esac
done

OPT_DEPSPEC+=("${@}")


# ----


for dep in "${!DEPS[@]}"; do
command -v "${dep}" >/dev/null 2>&1 || err "Missing dependency: ${DEPS["${dep}"]}"
Expand Down

0 comments on commit 0a5840e

Please sign in to comment.