You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.9 KiB
Bash
99 lines
2.9 KiB
Bash
5 years ago
|
#!/usr/bin/env bash
|
||
|
# vim:ts=4:sts=4:sw=4:et
|
||
|
#
|
||
|
# Author: Hari Sekhon
|
||
|
# Date: 2020-04-08 22:15:59 +0100 (Wed, 08 Apr 2020)
|
||
|
#
|
||
2 years ago
|
# https://github.com/HariSekhon/DevOps-Bash-tools
|
||
5 years ago
|
#
|
||
|
# License: see accompanying Hari Sekhon LICENSE file
|
||
|
#
|
||
|
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
|
||
|
#
|
||
2 years ago
|
# https://www.linkedin.com/in/HariSekhon
|
||
5 years ago
|
#
|
||
|
|
||
|
set -euo pipefail
|
||
4 years ago
|
[ -n "${DEBUG:-}" ] && set -x
|
||
|
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
5 years ago
|
|
||
1 year ago
|
# shellcheck disable=SC1090,SC1091
|
||
4 years ago
|
. "$srcdir/lib/utils.sh"
|
||
|
|
||
1 year ago
|
# shellcheck disable=SC1090,SC1091
|
||
4 years ago
|
. "$srcdir/.bash.d/git.sh"
|
||
5 years ago
|
|
||
|
# shellcheck disable=SC2034
|
||
|
usage_description="
|
||
3 years ago
|
Downloads, configures and runs GitHub Actions Runner to run on the local machine
|
||
|
|
||
3 years ago
|
# XXX: WARNING: GitHub advises self-hosted runners only be used for Private repos to prevent arbitrary code execution on your runners via Pull Requests (or you can set 'Allow local actions only' in the Actions Runners configuration in the repo or org)
|
||
|
|
||
3 years ago
|
Repo URL can be supplied via \$GITHUB_ACTIONS_REPO, otherwise attempts to infer from the local checkout's git remote url
|
||
5 years ago
|
|
||
3 years ago
|
Token can be supplied as either first argument or via environment variable \$GITHUB_ACTIONS_RUNNER_TOKEN
|
||
|
|
||
|
Version can be specified via the environment variable \$GITHUB_ACTIONS_RUNNER_VERSION
|
||
5 years ago
|
"
|
||
|
|
||
4 years ago
|
# used by usage() in lib/utils.sh
|
||
|
# shellcheck disable=SC2034
|
||
|
usage_args="[<GITHUB_ACTIONS_RUNNER_TOKEN>]"
|
||
5 years ago
|
|
||
5 years ago
|
help_usage "$@"
|
||
|
|
||
3 years ago
|
VERSION="${GITHUB_ACTIONS_RUNNER_VERSION:-${GITHUB_ACTIONS_VERSION:-${VERSION:-2.284.0}}}"
|
||
4 years ago
|
|
||
5 years ago
|
GITHUB_ACTIONS_RUNNER_TOKEN="${1:-${GITHUB_ACTIONS_RUNNER_TOKEN:-}}"
|
||
|
|
||
5 years ago
|
check_env_defined GITHUB_ACTIONS_RUNNER_TOKEN
|
||
|
|
||
|
github_repo="${GITHUB_ACTIONS_REPO:-}"
|
||
|
if [ -z "$github_repo" ]; then
|
||
|
echo "GITHUB_ACTIONS_REPO not defined, inferring from local repository"
|
||
4 years ago
|
github_repo_url="$(git remote -v | awk '/github/{print $2}' | head -n 1 | git_repo_strip_auth)"
|
||
5 years ago
|
if [ -z "$github_repo_url" ]; then
|
||
|
echo "Failed to infer github repo url from local git repository"
|
||
|
exit 1
|
||
|
fi
|
||
5 years ago
|
github_repo_url="${github_repo_url#ssh://}"
|
||
|
github_repo_url="${github_repo_url/://}"
|
||
|
if ! [[ "$github_repo_url" =~ https?:// ]]; then
|
||
|
github_repo_url="https://$github_repo_url"
|
||
|
fi
|
||
|
echo "inferred github repo url as: $github_repo_url"
|
||
5 years ago
|
fi
|
||
|
|
||
|
cd "$srcdir"
|
||
|
|
||
|
dir=".github_actions_runner"
|
||
|
|
||
|
mkdir -pv "$dir"
|
||
|
|
||
|
cd "$dir"
|
||
|
|
||
|
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||
|
if [ "$os" = darwin ]; then
|
||
|
os=osx
|
||
|
fi
|
||
|
|
||
|
tar="actions-runner-$os-x64-$VERSION.tar.gz"
|
||
|
|
||
|
if ! [ -f "$tar" ]; then
|
||
|
url="https://github.com/actions/runner/releases/download/v$VERSION/actions-runner-$os-x64-$VERSION.tar.gz"
|
||
|
curl -O -L "$url"
|
||
|
fi
|
||
|
|
||
|
if ! [ -f config.sh ]; then
|
||
2 years ago
|
tar xzf "$tar" || rm -fv -- "$tar"
|
||
5 years ago
|
fi
|
||
|
|
||
|
if ! [ -f .credentials ] ||
|
||
|
! [ -f .runner ]; then
|
||
|
./config.sh remove || :
|
||
5 years ago
|
set +o pipefail
|
||
5 years ago
|
yes "" | ./config.sh --url "$github_repo_url" --token "$GITHUB_ACTIONS_RUNNER_TOKEN"
|
||
|
fi
|
||
|
|
||
|
./run.sh
|