@@ -62811,7 +62811,7 @@ function buildUserDataScript(githubRegistrationToken, label) {
62811
62811
'#!/bin/bash',
62812
62812
`cd "${config.input.runnerHomeDir}"`,
62813
62813
'export RUNNER_ALLOW_RUNASROOT=1',
62814
- `./config.sh --url https://github.com/ ${config.githubContext.owner}/${config.githubContext.repo } --token ${githubRegistrationToken} --labels ${label}`,
62814
+ `./config.sh --url ${config.githubConfig.url } --token ${githubRegistrationToken} --labels ${label}`,
62815
62815
'./run.sh',
62816
62816
];
62817
62817
} else {
@@ -62822,7 +62822,7 @@ function buildUserDataScript(githubRegistrationToken, label) {
62822
62822
'curl -O -L https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-${RUNNER_ARCH}-2.299.1.tar.gz',
62823
62823
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.299.1.tar.gz',
62824
62824
'export RUNNER_ALLOW_RUNASROOT=1',
62825
- `./config.sh --url https://github.com/ ${config.githubContext.owner}/${config.githubContext.repo } --token ${githubRegistrationToken} --labels ${label}`,
62825
+ `./config.sh --url ${config.githubConfig.url } --token ${githubRegistrationToken} --labels ${label}`,
62826
62826
'./run.sh',
62827
62827
];
62828
62828
}
@@ -62918,6 +62918,21 @@ class Config {
62918
62918
ec2InstanceId: core.getInput('ec2-instance-id'),
62919
62919
iamRoleName: core.getInput('iam-role-name'),
62920
62920
runnerHomeDir: core.getInput('runner-home-dir'),
62921
+ scope: core.getInput('scope'),
62922
+ };
62923
+
62924
+ this.GITHUB_SCOPES = {
62925
+ organization: {
62926
+ url: `https://github.com/${github.context.repo.owner}`,
62927
+ context: { owner: github.context.repo.owner }
62928
+ },
62929
+ repository: {
62930
+ url: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}`,
62931
+ context: {
62932
+ owner: github.context.repo.owner,
62933
+ repo: github.context.repo.repo
62934
+ }
62935
+ }
62921
62936
};
62922
62937
62923
62938
const tags = JSON.parse(core.getInput('aws-resource-tags'));
@@ -62926,13 +62941,10 @@ class Config {
62926
62941
this.tagSpecifications = [{ResourceType: 'instance', Tags: tags}, {ResourceType: 'volume', Tags: tags}];
62927
62942
}
62928
62943
62929
- // the values of github.context.repo.owner and github.context.repo.repo are taken from
62930
- // the environment variable GITHUB_REPOSITORY specified in "owner/repo" format and
62931
- // provided by the GitHub Action on the runtime
62932
- this.githubContext = {
62933
- owner: github.context.repo.owner,
62934
- repo: github.context.repo.repo,
62935
- };
62944
+ this.githubConfig = this.GITHUB_SCOPES[this.input.scope];
62945
+ if (!this.githubConfig) {
62946
+ throw new Error(`The 'scope' input is not valid`);
62947
+ }
62936
62948
62937
62949
//
62938
62950
// validate input
@@ -62959,8 +62971,12 @@ class Config {
62959
62971
}
62960
62972
}
62961
62973
62962
- generateUniqueLabel() {
62963
- return Math.random().toString(36).substr(2, 5);
62974
+ generateLabel() {
62975
+ if (!this.input.label) {
62976
+ return Math.random().toString(36).substr(2, 5);
62977
+ }
62978
+
62979
+ return this.input.label
62964
62980
}
62965
62981
}
62966
62982
@@ -62988,7 +63004,7 @@ async function getRunner(label) {
62988
63004
const octokit = github.getOctokit(config.input.githubToken);
62989
63005
62990
63006
try {
62991
- const runners = await octokit.paginate('GET /repos/{owner}/{repo}/actions/runners', config.githubContext );
63007
+ const runners = await octokit.paginate('GET /repos/{owner}/{repo}/actions/runners', config.githubConfig.context );
62992
63008
const foundRunners = _.filter(runners, { labels: [{ name: label }] });
62993
63009
return foundRunners.length > 0 ? foundRunners[0] : null;
62994
63010
} catch (error) {
@@ -63001,7 +63017,7 @@ async function getRegistrationToken() {
63001
63017
const octokit = github.getOctokit(config.input.githubToken);
63002
63018
63003
63019
try {
63004
- const response = await octokit.request('POST /repos/{owner}/{repo}/actions/runners/registration-token', config.githubContext );
63020
+ const response = await octokit.request('POST /repos/{owner}/{repo}/actions/runners/registration-token', config.githubConfig.context );
63005
63021
core.info('GitHub Registration Token is received');
63006
63022
return response.data.token;
63007
63023
} catch (error) {
@@ -63021,7 +63037,7 @@ async function removeRunner() {
63021
63037
}
63022
63038
63023
63039
try {
63024
- await octokit.request('DELETE /repos/{owner}/{repo}/actions/runners/{runner_id}', _.merge(config.githubContext , { runner_id: runner.id }));
63040
+ await octokit.request('DELETE /repos/{owner}/{repo}/actions/runners/{runner_id}', _.merge(config.githubConfig.context , { runner_id: runner.id }));
63025
63041
core.info(`GitHub self-hosted runner ${runner.name} is removed`);
63026
63042
return;
63027
63043
} catch (error) {
@@ -63085,7 +63101,7 @@ function setOutput(label, ec2InstanceId) {
63085
63101
}
63086
63102
63087
63103
async function start() {
63088
- const label = config.generateUniqueLabel ();
63104
+ const label = config.generateLabel ();
63089
63105
const githubRegistrationToken = await gh.getRegistrationToken();
63090
63106
const ec2InstanceId = await aws.startEc2Instance(label, githubRegistrationToken);
63091
63107
setOutput(label, ec2InstanceId);
0 commit comments