Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .NET custom command #497

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
21 changes: 16 additions & 5 deletions tasks/JFrogDotnet/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,27 @@
},
"options": {
"restore": "restore",
"push": "NuGet push"
"push": "NuGet push",
"custom": "custom"
}
},
{
"name": "customCommand",
"type": "string",
"label": "Custom command",
"defaultValue": "",
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
"helpMarkDown": "The custom command which will be passed to .NET Core CLI for execution. Note that commands that require deploying are not supported, and that build-info collection is not available for custom commands.",
"required": true,
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
"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.",
"required": false,
"visibleRule": "command = restore"
"visibleRule": "command=restore || command=custom"
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
},
{
"name": "artifactoryConnection",
Expand All @@ -65,7 +75,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 +109,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 +160,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 +205,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
Loading