Compare commits

...

5 Commits

Author SHA1 Message Date
Frostebite
92eaa73a2d fix 2025-06-11 15:56:27 +01:00
Frostebite
b662a6fa0e Refactor URL configuration in RemoteClient for token-based authentication
- Updated comments for clarity regarding the purpose of URL configuration changes.
- Simplified the git configuration commands by removing redundant lines while maintaining functionality for HTTPS token-based authentication.
- This change enhances the readability and maintainability of the RemoteClient class's git setup process.
2025-06-10 20:09:34 +01:00
Frostebite
9ed94b241f fix 2025-06-10 01:21:45 +01:00
Frostebite
36503e30c0 Update git configuration commands in RemoteClient to ensure robust URL unsetting
- Modified the git configuration commands to append '|| true' to prevent errors if the specified URLs do not exist.
- This change enhances the reliability of the URL clearing process in the RemoteClient class, ensuring smoother execution during token-based authentication setups.
2025-06-10 00:52:48 +01:00
Frostebite
01bbef7a89 Update GitHub Actions to use GIT_PRIVATE_TOKEN for GITHUB_TOKEN in CI pipeline
- Replaced instances of GITHUB_TOKEN with GIT_PRIVATE_TOKEN in the cloud-runner CI pipeline configuration.
- This change ensures consistent use of token-based authentication across various jobs in the workflow, enhancing security and functionality.
2025-06-09 23:26:35 +01:00
10 changed files with 40 additions and 37 deletions

View File

@ -77,5 +77,13 @@
"unicorn/prefer-spread": "off", "unicorn/prefer-spread": "off",
// Temp disable to prevent mixing changes with other PRs // Temp disable to prevent mixing changes with other PRs
"i18n-text/no-en": "off" "i18n-text/no-en": "off"
} },
"overrides": [
{
"files": ["jest.setup.js"],
"rules": {
"import/no-commonjs": "off"
}
}
]
} }

View File

@ -80,7 +80,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }} GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }}
k8sTests: k8sTests:
name: K8s Tests name: K8s Tests
if: github.event.event_type != 'pull_request_target' if: github.event.event_type != 'pull_request_target'
@ -162,7 +162,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }} GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }}
buildTargetTests: buildTargetTests:
name: Local Build Target Tests name: Local Build Target Tests
@ -198,7 +198,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }} GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }}
with: with:
cloudRunnerTests: true cloudRunnerTests: true
versioning: None versioning: None

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -25,6 +25,6 @@ module.exports = {
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
modulePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/dist/'], modulePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/dist/'],
// A list of paths to modules that run some code to configure or set up the testing framework before each test // Use jest.setup.js to polyfill fetch for all tests
setupFilesAfterEnv: ['<rootDir>/src/jest.setup.ts'], setupFiles: ['<rootDir>/jest.setup.js'],
}; };

2
jest.setup.js Normal file
View File

@ -0,0 +1,2 @@
const fetch = require('node-fetch');
global.fetch = fetch;

View File

@ -74,6 +74,7 @@
"jest-fail-on-console": "^3.0.2", "jest-fail-on-console": "^3.0.2",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"lefthook": "^1.6.1", "lefthook": "^1.6.1",
"node-fetch": "2",
"prettier": "^2.5.1", "prettier": "^2.5.1",
"ts-jest": "^27.1.3", "ts-jest": "^27.1.3",
"ts-node": "10.8.1", "ts-node": "10.8.1",
@ -84,4 +85,4 @@
"node": "20.5.1", "node": "20.5.1",
"yarn": "1.22.19" "yarn": "1.22.19"
} }
} }

View File

@ -232,20 +232,14 @@ export class RemoteClient {
} }
// Clear any existing URL configurations // Clear any existing URL configurations
await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`); await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf || true`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`); await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf || true`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`); await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf || true`);
// Set new URL configuration with token // Set new URL configuration with token for HTTPS
await CloudRunnerSystem.Run( await CloudRunnerSystem.Run(
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`, `git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`,
); );
await CloudRunnerSystem.Run(
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "ssh://git@github.com/"`,
);
await CloudRunnerSystem.Run(
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "git@github.com"`,
);
await CloudRunnerSystem.Run(`git lfs pull`); await CloudRunnerSystem.Run(`git lfs pull`);
RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`); RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`);
@ -262,20 +256,14 @@ export class RemoteClient {
} }
// Clear any existing URL configurations // Clear any existing URL configurations
await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`); await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf || true`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`); await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf || true`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`); await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf || true`);
// Set new URL configuration with token // Set new URL configuration with token for HTTPS
await CloudRunnerSystem.Run( await CloudRunnerSystem.Run(
`git config --global url."https://${githubToken}@github.com/".insteadOf "https://github.com/"`, `git config --global url."https://${githubToken}@github.com/".insteadOf "https://github.com/"`,
); );
await CloudRunnerSystem.Run(
`git config --global url."https://${githubToken}@github.com/".insteadOf "ssh://git@github.com/"`,
);
await CloudRunnerSystem.Run(
`git config --global url."https://${githubToken}@github.com/".insteadOf "git@github.com"`,
);
await CloudRunnerSystem.Run(`git lfs pull`); await CloudRunnerSystem.Run(`git lfs pull`);
RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN fallback`); RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN fallback`);

View File

@ -3,6 +3,7 @@ import CloudRunner from './cloud-runner/cloud-runner';
import CloudRunnerOptions from './cloud-runner/options/cloud-runner-options'; import CloudRunnerOptions from './cloud-runner/options/cloud-runner-options';
import * as core from '@actions/core'; import * as core from '@actions/core';
import { Octokit } from '@octokit/core'; import { Octokit } from '@octokit/core';
import fetch from 'node-fetch';
class GitHub { class GitHub {
private static readonly asyncChecksApiWorkflowName = `Async Checks API`; private static readonly asyncChecksApiWorkflowName = `Async Checks API`;
@ -15,11 +16,13 @@ class GitHub {
private static get octokitDefaultToken() { private static get octokitDefaultToken() {
return new Octokit({ return new Octokit({
auth: process.env.GITHUB_TOKEN, auth: process.env.GITHUB_TOKEN,
request: { fetch },
}); });
} }
private static get octokitPAT() { private static get octokitPAT() {
return new Octokit({ return new Octokit({
auth: CloudRunner.buildParameters.gitPrivateToken, auth: CloudRunner.buildParameters.gitPrivateToken,
request: { fetch },
}); });
} }
private static get sha() { private static get sha() {
@ -163,11 +166,10 @@ class GitHub {
core.info(JSON.stringify(workflows)); core.info(JSON.stringify(workflows));
throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`); throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`);
} }
await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, { await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflowId}/dispatches`, {
owner: GitHub.owner, owner: GitHub.owner,
repo: GitHub.repo, repo: GitHub.repo,
// eslint-disable-next-line camelcase workflowId: selectedId,
workflow_id: selectedId,
ref: CloudRunnerOptions.branch, ref: CloudRunnerOptions.branch,
inputs: { inputs: {
checksObject: JSON.stringify({ data, mode }), checksObject: JSON.stringify({ data, mode }),
@ -198,11 +200,10 @@ class GitHub {
core.info(JSON.stringify(workflows)); core.info(JSON.stringify(workflows));
throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`); throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`);
} }
await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, { await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflowId}/dispatches`, {
owner: GitHub.owner, owner: GitHub.owner,
repo: GitHub.repo, repo: GitHub.repo,
// eslint-disable-next-line camelcase workflowId: selectedId,
workflow_id: selectedId,
ref: CloudRunnerOptions.branch, ref: CloudRunnerOptions.branch,
inputs: { inputs: {
buildGuid: CloudRunner.buildParameters.buildGuid, buildGuid: CloudRunner.buildParameters.buildGuid,
@ -213,10 +214,6 @@ class GitHub {
core.info(`github workflow complete hook not found`); core.info(`github workflow complete hook not found`);
} }
} }
public static async getCheckStatus() {
return await GitHub.octokitDefaultToken.request(`GET /repos/{owner}/{repo}/check-runs/{check_run_id}`);
}
} }
export default GitHub; export default GitHub;

View File

@ -6242,6 +6242,13 @@ no-case@^3.0.4:
lower-case "^2.0.2" lower-case "^2.0.2"
tslib "^2.0.3" tslib "^2.0.3"
node-fetch@2:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"
node-fetch@^2.6.7: node-fetch@^2.6.7:
version "2.6.12" version "2.6.12"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.12.tgz#02eb8e22074018e3d5a83016649d04df0e348fba" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.12.tgz#02eb8e22074018e3d5a83016649d04df0e348fba"