Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/index.mjs

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions src/task/src/git/gitInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class GitInvoker {
this._logger.logDebug("* GitInvoker.isGitRepo()");

try {
await this.invokeGit("rev-parse --is-inside-work-tree");
await this.invokeGit(["rev-parse", "--is-inside-work-tree"]);
return true;
} catch {
return false;
Expand All @@ -198,9 +198,11 @@ export default class GitInvoker {
this.initialize();

try {
await this.invokeGit(
`rev-parse --branch origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
);
await this.invokeGit([
"rev-parse",
"--branch",
`origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
]);
return true;
} catch {
return false;
Expand All @@ -215,9 +217,12 @@ export default class GitInvoker {
this._logger.logDebug("* GitInvoker.getDiffSummary()");

this.initialize();
return this.invokeGit(
`diff --numstat --ignore-all-space origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
);
return this.invokeGit([
"diff",
"--numstat",
"--ignore-all-space",
`origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
]);
}

private initialize(): void {
Expand All @@ -238,7 +243,7 @@ export default class GitInvoker {
this._isInitialized = true;
}

private async invokeGit(parameters: string): Promise<string> {
private async invokeGit(parameters: string[]): Promise<string> {
this._logger.logDebug("* GitInvoker.invokeGit()");

const result: ExecOutput = await this._runnerInvoker.exec(
Expand Down
29 changes: 21 additions & 8 deletions src/task/src/repos/tokenManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,17 @@ export default class TokenManager {
this._runnerInvoker.setSecret(federatedToken);

// Sign in to Azure using the federated token.
const signInResult: ExecOutput = await this._runnerInvoker.exec(
"az",
`login --service-principal -u ${servicePrincipalId} --tenant ${tenantId} --allow-no-subscriptions --federated-token ${federatedToken}`,
);
const signInResult: ExecOutput = await this._runnerInvoker.exec("az", [
"login",
"--service-principal",
"-u",
servicePrincipalId,
"--tenant",
tenantId,
"--allow-no-subscriptions",
"--federated-token",
federatedToken,
]);
if (signInResult.exitCode !== 0) {
throw new Error(signInResult.stderr);
}
Expand All @@ -135,10 +142,16 @@ export default class TokenManager {
* 499b84ac-1321-427f-aa17-267ca6975798, as documented at https://learn.microsoft.com/rest/api/azure/devops/tokens/
* and https://learn.microsoft.com/azure/devops/integrate/get-started/authentication/service-principal-managed-identity.
*/
const accessTokenResult: ExecOutput = await this._runnerInvoker.exec(
"az",
"account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv",
);
const accessTokenResult: ExecOutput = await this._runnerInvoker.exec("az", [
"account",
"get-access-token",
"--query",
"accessToken",
"--resource",
"499b84ac-1321-427f-aa17-267ca6975798",
"-o",
"tsv",
]);
if (accessTokenResult.exitCode !== 0) {
throw new Error(accessTokenResult.stderr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/task/src/runners/azurePipelinesRunnerInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class AzurePipelinesRunnerInvoker implements RunnerInvokerInterfa
this._azurePipelinesRunnerWrapper = azurePipelinesRunnerWrapper;
}

public async exec(tool: string, args: string): Promise<ExecOutput> {
public async exec(tool: string, args: string[]): Promise<ExecOutput> {
const options: IExecOptions = {
failOnStdErr: true,
silent: true,
Expand Down
2 changes: 1 addition & 1 deletion src/task/src/runners/gitHubRunnerInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class GitHubRunnerInvoker implements RunnerInvokerInterface {
this._gitHubRunnerWrapper = gitHubRunnerWrapper;
}

public async exec(tool: string, args: string): Promise<ExecOutput> {
public async exec(tool: string, args: string[]): Promise<ExecOutput> {
const options: actionsExec.ExecOptions = {
failOnStdErr: true,
silent: true,
Expand Down
2 changes: 1 addition & 1 deletion src/task/src/runners/runnerInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class RunnerInvoker implements RunnerInvokerInterface {
return this._runnerInvoker;
}

public async exec(tool: string, args: string): Promise<ExecOutput> {
public async exec(tool: string, args: string[]): Promise<ExecOutput> {
return this.runner.exec(tool, args);
}

Expand Down
2 changes: 1 addition & 1 deletion src/task/src/runners/runnerInvokerInterface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default interface RunnerInvokerInterface {
* @param args The arguments to pass to the tool.
* @returns A promise containing the result of the execution.
*/
exec: (tool: string, args: string) => Promise<ExecOutput>;
exec: (tool: string, args: string[]) => Promise<ExecOutput>;

/**
* Gets the value of an input.
Expand Down
2 changes: 1 addition & 1 deletion src/task/src/wrappers/azurePipelinesRunnerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class AzurePipelinesRunnerWrapper {
*/
public execSync(
tool: string,
args: string,
args: string[],
options: IExecOptions,
): IExecSyncResult {
return taskLib.execSync(tool, args, options);
Expand Down
4 changes: 2 additions & 2 deletions src/task/src/wrappers/gitHubRunnerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export default class GitHubRunnerWrapper {
*/
public async exec(
tool: string,
args: string,
args: string[],
options: actionsExec.ExecOptions,
): Promise<actionsExec.ExecOutput> {
return actionsExec.getExecOutput(tool, args.split(" "), options);
return actionsExec.getExecOutput(tool, args, options);
}

/**
Expand Down
38 changes: 31 additions & 7 deletions src/task/tests/git/gitInvoker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import * as AssertExtensions from "../testUtilities/assertExtensions.js";
import { instance, mock, verify, when } from "ts-mockito";
import { deepEqual, instance, mock, verify, when } from "ts-mockito";
import type { ExecOutput } from "@actions/exec";
import GitInvoker from "../../src/git/gitInvoker.js";
import Logger from "../../src/utilities/logger.js";
Expand All @@ -26,7 +26,11 @@ describe("gitInvoker.ts", (): void => {
when(
runnerInvoker.exec(
"git",
"rev-parse --branch origin/develop...pull/12345/merge",
deepEqual([
"rev-parse",
"--branch",
"origin/develop...pull/12345/merge",
]),
),
).thenCall(async (): Promise<ExecOutput> => {
const testCommitId = "7235cb16e5e6ac83e3cbecae66bab557e9e2cee6";
Expand All @@ -39,7 +43,12 @@ describe("gitInvoker.ts", (): void => {
when(
runnerInvoker.exec(
"git",
"diff --numstat --ignore-all-space origin/develop...pull/12345/merge",
deepEqual([
"diff",
"--numstat",
"--ignore-all-space",
"origin/develop...pull/12345/merge",
]),
),
).thenCall(
async (): Promise<ExecOutput> =>
Expand Down Expand Up @@ -397,7 +406,10 @@ describe("gitInvoker.ts", (): void => {
it(`should return true when called from a Git repo returning '${response.replace(/\n/gu, "\\n")}'`, async (): Promise<void> => {
// Arrange
when(
runnerInvoker.exec("git", "rev-parse --is-inside-work-tree"),
runnerInvoker.exec(
"git",
deepEqual(["rev-parse", "--is-inside-work-tree"]),
),
).thenCall(
async (): Promise<ExecOutput> =>
Promise.resolve({
Expand Down Expand Up @@ -425,7 +437,10 @@ describe("gitInvoker.ts", (): void => {
it("should return false when not called from a Git repo", async (): Promise<void> => {
// Arrange
when(
runnerInvoker.exec("git", "rev-parse --is-inside-work-tree"),
runnerInvoker.exec(
"git",
deepEqual(["rev-parse", "--is-inside-work-tree"]),
),
).thenCall(
async (): Promise<ExecOutput> =>
Promise.resolve({
Expand Down Expand Up @@ -797,7 +812,11 @@ describe("gitInvoker.ts", (): void => {
when(
runnerInvoker.exec(
"git",
"rev-parse --branch origin/develop...pull/12345/merge",
deepEqual([
"rev-parse",
"--branch",
"origin/develop...pull/12345/merge",
]),
),
).thenCall(
async (): Promise<ExecOutput> =>
Expand Down Expand Up @@ -993,7 +1012,12 @@ describe("gitInvoker.ts", (): void => {
when(
runnerInvoker.exec(
"git",
"diff --numstat --ignore-all-space origin/develop...pull/12345/merge",
deepEqual([
"diff",
"--numstat",
"--ignore-all-space",
"origin/develop...pull/12345/merge",
]),
),
).thenCall(
async (): Promise<ExecOutput> =>
Expand Down
46 changes: 42 additions & 4 deletions src/task/tests/repos/tokenManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ describe("tokenManager.ts", (): void => {
when(
runnerInvoker.exec(
"az",
`login --service-principal -u ${servicePrincipalId} --tenant ${tenantId} --allow-no-subscriptions --federated-token OidcToken`,
deepEqual([
"login",
"--service-principal",
"-u",
servicePrincipalId,
"--tenant",
tenantId,
"--allow-no-subscriptions",
"--federated-token",
"OidcToken",
]),
),
).thenResolve({
exitCode: 0,
Expand All @@ -101,7 +111,16 @@ describe("tokenManager.ts", (): void => {
when(
runnerInvoker.exec(
"az",
"account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv",
deepEqual([
"account",
"get-access-token",
"--query",
"accessToken",
"--resource",
"499b84ac-1321-427f-aa17-267ca6975798",
"-o",
"tsv",
]),
),
).thenResolve({
exitCode: 0,
Expand Down Expand Up @@ -556,7 +575,17 @@ describe("tokenManager.ts", (): void => {
when(
runnerInvoker.exec(
"az",
`login --service-principal -u ${servicePrincipalId} --tenant ${tenantId} --allow-no-subscriptions --federated-token OidcToken`,
deepEqual([
"login",
"--service-principal",
"-u",
servicePrincipalId,
"--tenant",
tenantId,
"--allow-no-subscriptions",
"--federated-token",
"OidcToken",
]),
),
).thenResolve({
exitCode: 1,
Expand Down Expand Up @@ -592,7 +621,16 @@ describe("tokenManager.ts", (): void => {
when(
runnerInvoker.exec(
"az",
"account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv",
deepEqual([
"account",
"get-access-token",
"--query",
"accessToken",
"--resource",
"499b84ac-1321-427f-aa17-267ca6975798",
"-o",
"tsv",
]),
),
).thenResolve({
exitCode: 1,
Expand Down
6 changes: 3 additions & 3 deletions src/task/tests/runners/azurePipelinesRunnerInvoker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ describe("azurePipelinesRunnerInvoker.ts", (): void => {
when(
azurePipelinesRunnerWrapper.execSync(
"TOOL",
"Argument1 Argument2",
deepEqual(["Argument1", "Argument2"]),
any(),
),
).thenReturn(execResult);

// Act
const result: ExecOutput = await azurePipelinesRunnerInvoker.exec(
"TOOL",
"Argument1 Argument2",
["Argument1", "Argument2"],
);

// Assert
Expand All @@ -60,7 +60,7 @@ describe("azurePipelinesRunnerInvoker.ts", (): void => {
verify(
azurePipelinesRunnerWrapper.execSync(
"TOOL",
"Argument1 Argument2",
deepEqual(["Argument1", "Argument2"]),
deepEqual(options),
),
).once();
Expand Down
16 changes: 10 additions & 6 deletions src/task/tests/runners/gitHubRunnerInvoker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ describe("gitHubRunnerInvoker.js", (): void => {
stdout: "Output",
};
when(
gitHubRunnerWrapper.exec("TOOL", "Argument1 Argument2", any()),
gitHubRunnerWrapper.exec(
"TOOL",
deepEqual(["Argument1", "Argument2"]),
any(),
),
).thenResolve(execResult);

// Act
const result: ExecOutput = await gitHubRunnerInvoker.exec(
"TOOL",
"Argument1 Argument2",
);
const result: ExecOutput = await gitHubRunnerInvoker.exec("TOOL", [
"Argument1",
"Argument2",
]);

// Assert
assert.equal(result.exitCode, 1);
Expand All @@ -65,7 +69,7 @@ describe("gitHubRunnerInvoker.js", (): void => {
verify(
gitHubRunnerWrapper.exec(
"TOOL",
"Argument1 Argument2",
deepEqual(["Argument1", "Argument2"]),
deepEqual(options),
),
).once();
Expand Down
Loading
Loading