|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Build MiSTer_Zaparoo from upstream master HEAD (the "unstable" tip). |
| 3 | +# |
| 4 | +# Mirrors stable-build.sh but skips the releases/MiSTer_* lookup. Builds in a |
| 5 | +# temporary worktree at upstream HEAD with the Zaparoo commits cherry-picked on |
| 6 | +# top, so the current checkout stays untouched. |
| 7 | + |
| 8 | +set -euo pipefail |
| 9 | + |
| 10 | +UPSTREAM_REPO="https://github.com/MiSTer-devel/Main_MiSTer.git" |
| 11 | +UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}" |
| 12 | +UPSTREAM_BRANCH="${UPSTREAM_BRANCH:-master}" |
| 13 | +OUTPUT_DIR="${UNSTABLE_BUILD_OUTPUT_DIR:-bin}" |
| 14 | +METADATA_FILE="${UNSTABLE_BUILD_METADATA_FILE:-}" |
| 15 | +PINNED_UNSTABLE_COMMIT="${UNSTABLE_BUILD_UNSTABLE_COMMIT:-}" |
| 16 | + |
| 17 | +cd "$(dirname "$0")" |
| 18 | + |
| 19 | +FORK_HEAD=$(git rev-parse HEAD) |
| 20 | +FORK_SHORT_SHA=$(git rev-parse --short HEAD) |
| 21 | + |
| 22 | +if ! git remote get-url "${UPSTREAM_REMOTE}" >/dev/null 2>&1; then |
| 23 | + git remote add "${UPSTREAM_REMOTE}" "${UPSTREAM_REPO}" |
| 24 | +elif [ "${UPSTREAM_REMOTE}" = "upstream" ]; then |
| 25 | + UPSTREAM_URL=$(git remote get-url "${UPSTREAM_REMOTE}") |
| 26 | + if [ "${UPSTREAM_URL}" != "${UPSTREAM_REPO}" ] && [ "${UPSTREAM_URL}" != "git@github.com:MiSTer-devel/Main_MiSTer.git" ] && [ "${UPSTREAM_URL}" != "ssh://git@github.com/MiSTer-devel/Main_MiSTer.git" ]; then |
| 27 | + echo "error: upstream remote points to ${UPSTREAM_URL}, expected ${UPSTREAM_REPO}" >&2 |
| 28 | + echo " set UPSTREAM_REMOTE to use a custom remote intentionally" >&2 |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +fi |
| 32 | + |
| 33 | +git fetch --no-tags --prune --no-recurse-submodules "${UPSTREAM_REMOTE}" \ |
| 34 | + "+refs/heads/${UPSTREAM_BRANCH}:refs/remotes/${UPSTREAM_REMOTE}/${UPSTREAM_BRANCH}" |
| 35 | + |
| 36 | +UPSTREAM_REF="${UPSTREAM_REMOTE}/${UPSTREAM_BRANCH}" |
| 37 | +UNSTABLE_COMMIT=${PINNED_UNSTABLE_COMMIT} |
| 38 | +if [ -z "${UNSTABLE_COMMIT}" ]; then |
| 39 | + UNSTABLE_COMMIT=$(git rev-parse "${UPSTREAM_REF}") |
| 40 | +fi |
| 41 | +if [ -z "${UNSTABLE_COMMIT}" ]; then |
| 42 | + echo "error: could not resolve upstream HEAD" >&2 |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | +if ! git merge-base --is-ancestor "${UNSTABLE_COMMIT}" "${UPSTREAM_REF}"; then |
| 46 | + echo "error: unstable commit ${UNSTABLE_COMMIT} is not reachable from ${UPSTREAM_REF}" >&2 |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +UNSTABLE_SHORT_SHA=$(git rev-parse --short=8 "${UNSTABLE_COMMIT}") |
| 51 | +UNSTABLE_DATE=$(TZ=UTC git log -1 --format=%cd --date=format-local:%Y%m%d "${UNSTABLE_COMMIT}") |
| 52 | +UNSTABLE_NAME="MiSTer_unstable_${UNSTABLE_DATE}_${UNSTABLE_SHORT_SHA}" |
| 53 | +FORK_COMMITS=$(git rev-list --reverse --no-merges "${UPSTREAM_REF}..${FORK_HEAD}") |
| 54 | + |
| 55 | +if [ -n "${METADATA_FILE}" ]; then |
| 56 | + cat >"${METADATA_FILE}" <<EOF |
| 57 | +UNSTABLE_NAME=${UNSTABLE_NAME} |
| 58 | +UNSTABLE_DATE=${UNSTABLE_DATE} |
| 59 | +UNSTABLE_COMMIT=${UNSTABLE_COMMIT} |
| 60 | +UNSTABLE_SHORT_SHA=${UNSTABLE_SHORT_SHA} |
| 61 | +FORK_SHORT_SHA=${FORK_SHORT_SHA} |
| 62 | +EOF |
| 63 | +fi |
| 64 | + |
| 65 | +if [ "${UNSTABLE_BUILD_METADATA_ONLY:-false}" = "true" ]; then |
| 66 | + echo "==> Upstream master HEAD is ${UNSTABLE_NAME}" |
| 67 | + exit 0 |
| 68 | +fi |
| 69 | + |
| 70 | +TMP_WORKTREE=$(mktemp -d "${TMPDIR:-/tmp}/mister-zaparoo-unstable.XXXXXX") |
| 71 | +cleanup() { |
| 72 | + git worktree remove --force "${TMP_WORKTREE}" >/dev/null 2>&1 || true |
| 73 | +} |
| 74 | +trap cleanup EXIT |
| 75 | + |
| 76 | +echo "==> Building from upstream ${UNSTABLE_NAME} with Zaparoo ${FORK_SHORT_SHA}" |
| 77 | +git worktree add --detach "${TMP_WORKTREE}" "${UNSTABLE_COMMIT}" >/dev/null |
| 78 | + |
| 79 | +if [ -n "${FORK_COMMITS}" ]; then |
| 80 | + git -C "${TMP_WORKTREE}" cherry-pick --no-commit ${FORK_COMMITS} |
| 81 | +fi |
| 82 | + |
| 83 | +"${TMP_WORKTREE}/docker-build.sh" "$@" |
| 84 | + |
| 85 | +mkdir -p "${OUTPUT_DIR}" |
| 86 | +cp "${TMP_WORKTREE}/bin/MiSTer_Zaparoo" "${OUTPUT_DIR}/MiSTer_Zaparoo" |
| 87 | +cp "${TMP_WORKTREE}/bin/MiSTer_Zaparoo.elf" "${OUTPUT_DIR}/MiSTer_Zaparoo.elf" |
| 88 | + |
| 89 | +echo "==> Built ${OUTPUT_DIR}/MiSTer_Zaparoo from ${UNSTABLE_NAME}" |
0 commit comments