1
1
import { Octokit } from '@octokit/rest' ;
2
+ import { Endpoints } from '@octokit/types' ;
2
3
import { createChildLogger } from '@aws-github-runner/aws-powertools-util' ;
3
4
import moment from 'moment' ;
4
5
@@ -9,19 +10,12 @@ import { GhRunners, githubCache } from './cache';
9
10
import { ScalingDownConfig , getEvictionStrategy , getIdleRunnerCount } from './scale-down-config' ;
10
11
import { metricGitHubAppRateLimit } from '../github/rate-limit' ;
11
12
import { getGitHubEnterpriseApiUrl } from './scale-up' ;
12
- import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types/dist-types/GetResponseTypeFromEndpointMethod' ;
13
13
14
14
const logger = createChildLogger ( 'scale-down' ) ;
15
15
16
- type OrgRunnerList = GetResponseDataTypeFromEndpointMethod <
17
- typeof Octokit . prototype . actions . listSelfHostedRunnersForOrg
18
- > ;
19
-
20
- type RepoRunnerList = GetResponseDataTypeFromEndpointMethod <
21
- typeof Octokit . prototype . actions . listSelfHostedRunnersForRepo
22
- > ;
23
-
24
- type RunnerState = ( OrgRunnerList | RepoRunnerList ) [ 'runners' ] [ number ] ;
16
+ type OrgRunnerList = Endpoints [ "GET /orgs/{org}/actions/runners" ] [ "response" ] [ "data" ] [ "runners" ] ;
17
+ type RepoRunnerList = Endpoints [ "GET /repos/{owner}/{repo}/actions/runners" ] [ "response" ] [ "data" ] [ "runners" ] ;
18
+ type RunnerState = OrgRunnerList [ number ] | RepoRunnerList [ number ] ;
25
19
26
20
async function getOrCreateOctokit ( runner : RunnerInfo ) : Promise < Octokit > {
27
21
const key = runner . owner ;
@@ -73,20 +67,23 @@ async function getGitHubSelfHostedRunnerState(
73
67
owner : ec2runner . owner . split ( '/' ) [ 0 ] ,
74
68
repo : ec2runner . owner . split ( '/' ) [ 1 ] ,
75
69
} ) ;
70
+ metricGitHubAppRateLimit ( state . headers ) ;
76
71
77
72
return {
78
73
id : state . data . id ,
79
74
name : state . data . name ,
80
75
busy : state . data . busy ,
81
76
status : state . data . status ,
82
- headers : state . headers ,
77
+ os : state . data . os ,
78
+ labels : state . data . labels ,
79
+ runner_group_id : state . data . runner_group_id ,
80
+ ephemeral : state . data . ephemeral ,
83
81
} ;
84
82
}
85
83
86
84
async function getGitHubRunnerBusyState ( client : Octokit , ec2runner : RunnerInfo , runnerId : number ) : Promise < boolean > {
87
85
const state = await getGitHubSelfHostedRunnerState ( client , ec2runner , runnerId ) ;
88
86
logger . info ( `Runner '${ ec2runner . instanceId } ' - GitHub Runner ID '${ runnerId } ' - Busy: ${ state . busy } ` ) ;
89
- metricGitHubAppRateLimit ( state . headers ) ;
90
87
return state . busy ;
91
88
}
92
89
@@ -226,7 +223,7 @@ async function markOrphan(instanceId: string): Promise<void> {
226
223
227
224
async function lastChanceCheckOrphanRunner ( runner : RunnerList ) : Promise < void > {
228
225
const client = await getOrCreateOctokit ( runner as RunnerInfo ) ;
229
- const runnerId = parseInt ( runner . runnerId ) ;
226
+ const runnerId = parseInt ( runner . runnerId || '0' ) ;
230
227
const ec2Instance = runner as RunnerInfo ;
231
228
const state = await getGitHubSelfHostedRunnerState ( client , ec2Instance , runnerId ) ;
232
229
logger . debug ( `Runner is currently '${ runner . instanceId } ' state: ${ JSON . stringify ( state ) } ` ) ;
0 commit comments