Skip to content

Commit

Permalink
Support .NET custom command (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored Jun 18, 2024
1 parent 5bcc72c commit 8751b88
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ Use the following commands to run from terminal:
```

Note: If you are running tests via your IDE, make sure you are registering tests with
ts-node: `mocha -r ts-node/register tests.ts -t 600000`.
ts-node: `mocha -r ts-node/register tests.ts -t 1000000`.

#### Skipping Tests

Expand Down
14 changes: 13 additions & 1 deletion tasks/JFrogDotnet/dotnetBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ function RunTaskCbk(cliPath) {
case 'push':
performDotnetNugetPush(cliPath);
break;
case 'custom':
performDotnetCustomCommand(cliPath);
break;
}
}

function performDotnetRestore(cliPath) {
performDotnetCommand(cliPath, cliDotnetCoreRestoreCommand);
}

function performDotnetCommand(cliPath, commandName) {
let sourcesPattern = tl.getInput('rootPath');
let filesList = solutionPathUtil.resolveFilterSpec(sourcesPattern, tl.getVariable('System.DefaultWorkingDirectory') || process.cwd());
// A source file is a solution or csproj file.
Expand All @@ -33,11 +40,16 @@ function performDotnetRestore(cliPath) {
}
let resolverServerId = performDotnetConfig(cliPath, sourcePath, 'targetResolveRepo');
let dotnetArguments = buildDotnetCliArgs();
let dotnetCommand = utils.cliJoin(cliPath, cliDotnetCoreRestoreCommand, dotnetArguments);
let dotnetCommand = utils.cliJoin(cliPath, commandName, dotnetArguments);
executeCliCommand(dotnetCommand, sourcePath, cliPath, [resolverServerId]);
});
}

function performDotnetCustomCommand(cliPath) {
let customCommand = tl.getInput('customCommand');
performDotnetCommand(cliPath, 'dotnet ' + customCommand);
}

function performDotnetNugetPush(cliPath) {
let buildDir = tl.getVariable('System.DefaultWorkingDirectory');
let targetPath = tl.getInput('targetDeployRepo', true);
Expand Down
22 changes: 16 additions & 6 deletions tasks/JFrogDotnet/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,26 @@
},
"options": {
"restore": "restore",
"push": "NuGet push"
"push": "NuGet push",
"custom": "custom"
}
},
{
"name": "customCommand",
"type": "string",
"label": "Custom command",
"helpMarkDown": "The custom command which will be passed to .NET Core CLI for execution (for example: 'pack'). Note that commands that require deployment are not supported, and that build-info collection is not available for custom commands.",
"required": true,
"visibleRule": "command=custom"
},
{
"name": "arguments",
"type": "string",
"label": "Arguments",
"defaultValue": "",
"helpMarkDown": "The arguments which will be passed to .NET Core CLI for execution. Arguments should be quoted, and space separated.",
"helpMarkDown": "The arguments which will be passed to .NET Core CLI for execution (for example: '--no-restore' '--v:d'). Arguments should be quoted, and space separated.",
"required": false,
"visibleRule": "command = restore"
"visibleRule": "command=restore || command=custom"
},
{
"name": "artifactoryConnection",
Expand All @@ -65,7 +74,7 @@
"label": "Resolution repository",
"defaultValue": "",
"required": true,
"visibleRule": "command = restore",
"visibleRule": "command=restore || command=custom",
"helpMarkDown": "Sets the resolution repository.",
"properties": {
"EditableOptions": "True"
Expand Down Expand Up @@ -99,7 +108,7 @@
"defaultValue": "**/*.sln",
"helpMarkDown": "Path to the root directory of a solution/project file to use. If the directory includes more than one sln files, then the first argument passed in the Arguments field should be the name (not the path) of the sln file. Accepts Ant-style patterns.",
"required": "true",
"visibleRule": "command = restore"
"visibleRule": "command=restore || command=custom"
},
{
"name": "pathToNupkg",
Expand Down Expand Up @@ -150,6 +159,7 @@
"label": "Collect build info",
"defaultValue": "false",
"required": false,
"visibleRule": "command=restore || command=push",
"helpMarkDown": "Select to collect build info."
},
{
Expand Down Expand Up @@ -194,7 +204,7 @@
"label": "NuGet protocol version",
"required": false,
"defaultValue": "v3",
"visibleRule": "command = restore",
"visibleRule": "command=restore || command=custom",
"options": {
"v2": "v2",
"v3": "v3"
Expand Down
4 changes: 2 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"main": "testUtils.ts",
"dependencies": {
"@jfrog/tasks-utils": "file:../jfrog-tasks-utils/jfrog-tasks-utils-1.0.0.tgz",
"azure-pipelines-task-lib": "^4.4.0",
"azure-pipelines-task-lib": "4.12.0",
"fs-extra": "^11.1.1",
"js-yaml": "^4.1.0",
"path": "^0.12.7"
Expand All @@ -26,6 +26,6 @@
"ts-node": "^10.9.1"
},
"scripts": {
"test": "npm i && mocha -r ts-node/register tests.ts -t 600000"
"test": "npm i && mocha -r ts-node/register tests.ts -t 1000000"
}
}
1 change: 1 addition & 0 deletions tests/resources/conanTask/conanConfigInstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const testUtils = require('../../testUtils');
const join = require('path').join;
const basename = require('path').basename;

const TEST_NAME = basename(__dirname);
const BUILD_NAME = TEST_NAME;
Expand Down
15 changes: 15 additions & 0 deletions tests/resources/dotnet/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const testUtils = require('../../testUtils');
const join = require('path').join;
const TEST_NAME = testUtils.getTestName(__dirname);

let inputs = {
command: 'custom',
customCommand: 'restore',
arguments: '"--build-name=DotNET Test" "--build-number=7"',
rootPath: join(testUtils.getLocalTestDir(TEST_NAME)),
targetResolveRepo: testUtils.getRepoKeys().nugetVirtualRepo,
nugetProtocolVersion: "v3"
};

testUtils.copyTestFilesToTestWorkDir(TEST_NAME, 'restore');
testUtils.runArtifactoryTask(testUtils.dotnet, {}, inputs);
14 changes: 13 additions & 1 deletion tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,18 @@ describe('JFrog Artifactory Extension Tests', (): void => {
},
TestUtils.isSkipTest('dotnet'),
);
// Run a restore using the custom command task.
runSyncTest(
'Dotnet custom restore',
(): void => {
const testDir: string = 'dotnet';
mockTask(testDir, 'custom');
mockTask(testDir, 'publish');
getAndAssertBuild('DotNET Test', '7');
deleteBuild('DotNET Test');
},
TestUtils.isSkipTest('dotnet'),
);
});

describe('Docker Tests', (): void => {
Expand Down Expand Up @@ -968,7 +980,7 @@ function runSyncTest(description: string, testFunc: () => void, skip?: boolean):
it(description, (done): void => {
testFunc();
done();
}).timeout(600000); // 6 minutes
}).timeout(1000000); // 10 minutes
}

/**
Expand Down

0 comments on commit 8751b88

Please sign in to comment.