Skip to content

Commit 5a2ec20

Browse files
authored
Merge pull request #9 from arceos-hypervisor/multi
feat: 支持基于上下文动态生成 Runner 配置文件与前缀
2 parents 093d887 + 868d809 commit 5a2ec20

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

runner.sh

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,53 @@ shell_get_org_and_pat() {
211211

212212
export ORG GH_PAT REPO
213213

214+
# Recalculate RUNNER_NAME_PREFIX if it was auto-generated (not explicitly set by user)
215+
# Same logic as COMPOSE_FILE etc.: check if empty or equals default value (hostname only)
216+
local default_prefix
217+
default_prefix="$(hostname)-"
218+
if [[ -z "${RUNNER_NAME_PREFIX:-}" ]] || [[ "$RUNNER_NAME_PREFIX" == "$default_prefix" ]]; then
219+
if [[ -n "${ORG:-}" && -n "${REPO:-}" ]]; then
220+
RUNNER_NAME_PREFIX="$(hostname)-${ORG}-${REPO}-"
221+
elif [[ -n "${ORG:-}" ]]; then
222+
RUNNER_NAME_PREFIX="$(hostname)-${ORG}-"
223+
else
224+
RUNNER_NAME_PREFIX="$default_prefix"
225+
fi
226+
export RUNNER_NAME_PREFIX
227+
fi
228+
229+
# Recalculate file paths based on newly obtained ORG/REPO
230+
if [[ -z "${COMPOSE_FILE:-}" ]] || [[ "$COMPOSE_FILE" == "docker-compose.yml" ]]; then
231+
if [[ -n "${ORG:-}" && -n "${REPO:-}" ]]; then
232+
COMPOSE_FILE="docker-compose.${ORG}.${REPO}.yml"
233+
elif [[ -n "${ORG:-}" ]]; then
234+
COMPOSE_FILE="docker-compose.${ORG}.yml"
235+
else
236+
COMPOSE_FILE="docker-compose.yml"
237+
fi
238+
export COMPOSE_FILE
239+
fi
240+
if [[ -z "${DOCKERFILE_HASH_FILE:-}" ]] || [[ "$DOCKERFILE_HASH_FILE" == ".dockerfile.sha256" ]]; then
241+
if [[ -n "${ORG:-}" && -n "${REPO:-}" ]]; then
242+
DOCKERFILE_HASH_FILE=".dockerfile.${ORG}.${REPO}.sha256"
243+
elif [[ -n "${ORG:-}" ]]; then
244+
DOCKERFILE_HASH_FILE=".dockerfile.${ORG}.sha256"
245+
else
246+
DOCKERFILE_HASH_FILE=".dockerfile.sha256"
247+
fi
248+
export DOCKERFILE_HASH_FILE
249+
fi
250+
if [[ -z "${REG_TOKEN_CACHE_FILE:-}" ]] || [[ "$REG_TOKEN_CACHE_FILE" == ".reg_token.cache" ]]; then
251+
if [[ -n "${ORG:-}" && -n "${REPO:-}" ]]; then
252+
REG_TOKEN_CACHE_FILE=".reg_token.cache.${ORG}.${REPO}"
253+
elif [[ -n "${ORG:-}" ]]; then
254+
REG_TOKEN_CACHE_FILE=".reg_token.cache.${ORG}"
255+
else
256+
REG_TOKEN_CACHE_FILE=".reg_token.cache"
257+
fi
258+
export REG_TOKEN_CACHE_FILE
259+
fi
260+
214261
# Persist to .env (ENV_FILE) if values were entered interactively
215262
if [[ $wrote_env -eq 1 ]]; then
216263
local env_file="$ENV_FILE" tmp
@@ -930,7 +977,7 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
930977
RUNNER_IMAGE="$(shell_prepare_runner_image)";
931978

932979
if [[ "${RUNNER_BOARD}" -gt 0 ]]; then
933-
shell_info "Generating $COMPOSE_FILE with $count generic runners and board-specific runners."
980+
shell_info "Generating $COMPOSE_FILE with $count generic runners and ${RUNNER_BOARD} board-specific runners."
934981
else
935982
shell_info "Generating $COMPOSE_FILE with $count generic runners."
936983
fi
@@ -958,7 +1005,7 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
9581005
generic_count=$cont_count
9591006
fi
9601007
if [[ "${RUNNER_BOARD}" -gt 0 ]]; then
961-
shell_info "Regenerating $COMPOSE_FILE with ${generic_count} existing runners and board-specific runners."
1008+
shell_info "Regenerating $COMPOSE_FILE with ${generic_count} existing runners and ${RUNNER_BOARD} board-specific runners."
9621009
else
9631010
shell_info "Regenerating $COMPOSE_FILE with ${generic_count} existing runners."
9641011
fi

0 commit comments

Comments
 (0)