This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
87 lines (79 loc) · 3.58 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Refresh Runner
description: Creates/Refreshes self hosted runner.
inputs:
## Required Parameters
org-name:
description: Target organization name. Either org-name or repo-name must be specified.
default: ""
required: false
repo-name:
description: |
Target repository name. Repository name must include owner: `{owner}/{repo}`.
Either org-name or repo-name must be specified.
default: ""
required: false
github-access-token:
description: Github access token to use. Token should be personal access token or Github Apps generated token.
required: true
## Optional Parameters
runner-version:
description: |
Version of Github Self Hosted Runner.
If not specified, it will use the version of the running runner. (NOTE: Architecture is fixed to "linux-x64")
required: false
default: ''
runner-name:
description: Name of the dummy runner to be created/refreshed.
required: false
default: managed-dummy-runner
runs:
using: "composite"
steps:
- name: Run dummy runner
shell: bash
run: |
# Exit on error
set -eu
if [ "${{ inputs.org-name }}" != "" ] && [ "${{ inputs.repo-name }}" != "" ]; then
echo "Error: Can't specify both org-name and repo-name."
exit 1
fi
if [ "${{ inputs.org-name }}" = "" ] && [ "${{ inputs.repo-name }}" = "" ]; then
echo "Error: Required to specify either org-name or repo-name."
exit 1
fi
# Prepare dummy runner files
mkdir actions-runner && cd actions-runner
if [ "${{ inputs.runner-version }}" = "" ]; then
RUNNER_PATH=$(dirname $(dirname $RUNNER_TEMP))
echo "### Copy runner files from the running runner:"
echo " - runner_path: $RUNNER_PATH"
# We need to exclude temp/state related files when copying the existing runner files.
rsync --copy-links -a ${RUNNER_PATH}/ . --exclude "_*" --exclude ".*"
else
DOWNLOAD_URL="https://github.com/actions/runner/releases/download/v${{ inputs.runner-version }}/actions-runner-linux-x64-${{ inputs.runner-version }}.tar.gz"
echo "### Download runner files:"
echo " - download_url: $DOWNLOAD_URL"
curl -s -O -L https://github.com/actions/runner/releases/download/v${{ inputs.runner-version }}/actions-runner-linux-x64-${{ inputs.runner-version }}.tar.gz
tar xzf ./actions-runner-linux-x64-${{ inputs.runner-version }}.tar.gz
fi
echo "Prepared dummy runner version: $(./config.sh --version)"
echo "### Configure dummy runner"
if [ "${{ inputs.org-name }}" != "" ]; then
echo "target org: ${{ inputs.org-name }}"
RUNNER_TOKEN=$(bash ${{ github.action_path }}/script/get-org-runner-token.sh ${{ inputs.github-access-token }} ${GITHUB_API_URL} ${{ inputs.org-name }} )
TARGET_NAME=${{ inputs.org-name }}
else
echo "target repository: ${{ inputs.repo-name }}"
RUNNER_TOKEN=$(bash ${{ github.action_path }}/script/get-repo-runner-token.sh ${{ inputs.github-access-token }} ${GITHUB_API_URL} ${{ inputs.repo-name }} )
TARGET_NAME=${{ inputs.repo-name }}
fi
./config.sh \
--name ${{ inputs.runner-name }} \
--url ${GITHUB_SERVER_URL}/${TARGET_NAME} \
--token ${RUNNER_TOKEN} \
--labels dummy-runner \
--replace \
--unattended
echo "### Run dummy runner"
python -u ${{ github.action_path }}/script/run-dummy-runner.py