+12








fcd7c979df
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
106 lines
2.6 KiB
Bash
106 lines
2.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
mode="${1:-all}"
|
|
case "$mode" in
|
|
fast) job="fast-gate" ;;
|
|
docker) job="container" ;;
|
|
all) job="" ;;
|
|
cleanup) job="cleanup" ;;
|
|
*)
|
|
echo "Usage: $0 {fast|docker|all|cleanup}" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
command -v act >/dev/null 2>&1 || {
|
|
echo "act is required: https://nektosact.com/installation/index.html" >&2
|
|
exit 1
|
|
}
|
|
|
|
docker info >/dev/null 2>&1 || {
|
|
echo "Docker is not running" >&2
|
|
exit 1
|
|
}
|
|
|
|
if [[ -z "${DOCKER_HOST:-}" ]]; then
|
|
DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null || true)
|
|
export DOCKER_HOST
|
|
fi
|
|
|
|
head_sha=$(git rev-parse HEAD)
|
|
base_sha=$(git rev-parse HEAD~1 2>/dev/null || echo "$head_sha")
|
|
head_ref=$(git branch --show-current)
|
|
head_ref=${head_ref:-act-local}
|
|
event_file=$(mktemp "${TMPDIR:-/tmp}/homarr-act-event.XXXXXX")
|
|
trap 'rm -f "$event_file"' EXIT
|
|
|
|
json_escape() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g; s/\t/\\t/g'; }
|
|
|
|
if [[ "$mode" == "cleanup" ]]; then
|
|
event_name="workflow_dispatch"
|
|
cat >"$event_file" <<EOF
|
|
{
|
|
"inputs": { "operation": "cleanup", "pr_number": "1", "ref": "" },
|
|
"repository": { "full_name": "homarr-labs/homarr" }
|
|
}
|
|
EOF
|
|
elif [[ "$mode" == "docker" ]]; then
|
|
event_name="workflow_dispatch"
|
|
cat >"$event_file" <<EOF
|
|
{
|
|
"inputs": { "operation": "validate", "ref": "$head_sha" },
|
|
"repository": { "full_name": "homarr-labs/homarr" }
|
|
}
|
|
EOF
|
|
else
|
|
event_name="pull_request"
|
|
safe_ref=$(json_escape "$head_ref")
|
|
cat >"$event_file" <<EOF
|
|
{
|
|
"action": "synchronize",
|
|
"number": 1,
|
|
"repository": { "full_name": "homarr-labs/homarr" },
|
|
"pull_request": {
|
|
"number": 1,
|
|
"draft": false,
|
|
"base": { "sha": "$base_sha", "ref": "dev" },
|
|
"head": {
|
|
"sha": "$head_sha",
|
|
"ref": "$safe_ref",
|
|
"repo": { "full_name": "homarr-labs/homarr" }
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
runner_image="${ACT_RUNNER_IMAGE:-catthehacker/ubuntu:act-latest}"
|
|
args=(
|
|
"$event_name"
|
|
--workflows .github/workflows/ci.yml
|
|
--eventpath "$event_file"
|
|
--platform "ubuntu-latest=$runner_image"
|
|
--container-architecture linux/amd64
|
|
--bind
|
|
)
|
|
|
|
if [[ -n "$job" ]]; then
|
|
args+=(--job "$job")
|
|
fi
|
|
|
|
git_common_dir=$(cd "$(git rev-parse --git-common-dir)" && pwd)
|
|
container_options="--volume homarr-act-node-modules:$PWD/node_modules --volume homarr-act-pnpm-store:$PWD/.pnpm-store"
|
|
case "$git_common_dir" in
|
|
"$PWD" | "$PWD"/*) ;;
|
|
*) container_options="$container_options --volume $git_common_dir:$git_common_dir:ro" ;;
|
|
esac
|
|
args+=(--container-options "$container_options")
|
|
|
|
if [[ -n "${ACT_SECRET_FILE:-}" ]]; then
|
|
args+=(--secret-file "$ACT_SECRET_FILE")
|
|
fi
|
|
|
|
exec act "${args[@]}"
|