Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit e110318

Browse files
committed
fix: upgrade runner module to support upgrade octokit auth-app (#786)
1 parent 3ac69a8 commit e110318

File tree

3 files changed

+684
-522
lines changed

3 files changed

+684
-522
lines changed

Diff for: modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { Octokit } from '@octokit/rest';
22
import { request } from '@octokit/request';
33
import { createAppAuth } from '@octokit/auth-app';
4-
import { Authentication, StrategyOptions } from '@octokit/auth-app/dist-types/types';
4+
import {
5+
Authentication,
6+
StrategyOptions,
7+
AppAuthentication,
8+
InstallationAccessTokenAuthentication,
9+
} from '@octokit/auth-app/dist-types/types';
510
import { OctokitOptions } from '@octokit/core/dist-types/types';
611
import { decrypt } from './kms';
712

@@ -20,7 +25,7 @@ export async function createGithubAuth(
2025
installationId: number | undefined,
2126
authType: 'app' | 'installation',
2227
ghesApiUrl = '',
23-
): Promise<Authentication> {
28+
): Promise<AppAuthentication> {
2429
const clientSecret = await decrypt(
2530
process.env.GITHUB_APP_CLIENT_SECRET as string,
2631
process.env.KMS_KEY_ID as string,
@@ -54,5 +59,11 @@ export async function createGithubAuth(
5459
baseUrl: ghesApiUrl,
5560
});
5661
}
57-
return await createAppAuth(authOptions)({ type: authType });
62+
const result = (await createAppAuth(authOptions)({ type: authType })) as AppAuthentication;
63+
return result;
64+
// if (result.type == 'oauth-app') {
65+
// return result;
66+
// } else {
67+
// throw Error(`Authentication type ${authType} is not`);
68+
// }
5869
}

Diff for: modules/runners/lambdas/runners/src/scale-runners/scale-up.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
4242
).data.id;
4343
}
4444

45-
4645
const ghAuth = await createGithubAuth(installationId, 'installation', ghesApiUrl);
46+
4747
const githubInstallationClient = await createOctoClient(ghAuth.token, ghesApiUrl);
4848
const checkRun = await githubInstallationClient.checks.get({
4949
check_run_id: payload.id,
@@ -60,9 +60,10 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
6060
repoName: repoName,
6161
});
6262
console.info(
63-
`${enableOrgLevel
64-
? `Organization ${payload.repositoryOwner}`
65-
: `Repo ${payload.repositoryOwner}/${payload.repositoryName}`
63+
`${
64+
enableOrgLevel
65+
? `Organization ${payload.repositoryOwner}`
66+
: `Repo ${payload.repositoryOwner}/${payload.repositoryName}`
6667
} has ${currentRunners.length}/${maximumRunners} runners`,
6768
);
6869

@@ -71,9 +72,9 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
7172
const registrationToken = enableOrgLevel
7273
? await githubInstallationClient.actions.createRegistrationTokenForOrg({ org: payload.repositoryOwner })
7374
: await githubInstallationClient.actions.createRegistrationTokenForRepo({
74-
owner: payload.repositoryOwner,
75-
repo: payload.repositoryName,
76-
});
75+
owner: payload.repositoryOwner,
76+
repo: payload.repositoryName,
77+
});
7778
const token = registrationToken.data.token;
7879

7980
const labelsArgument = runnerExtraLabels !== undefined ? `--labels ${runnerExtraLabels}` : '';
@@ -84,7 +85,7 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
8485
runnerConfig: enableOrgLevel
8586
? `--url ${configBaseUrl}/${payload.repositoryOwner} --token ${token} ${labelsArgument}${runnerGroupArgument}`
8687
: `--url ${configBaseUrl}/${payload.repositoryOwner}/${payload.repositoryName} ` +
87-
`--token ${token} ${labelsArgument}`,
88+
`--token ${token} ${labelsArgument}`,
8889
orgName: orgName,
8990
repoName: repoName,
9091
});

0 commit comments

Comments
 (0)