-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
520 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const tl = require('azure-pipelines-task-lib/task'); | ||
const fs = require('fs-extra'); | ||
const utils = require('artifactory-tasks-utils'); | ||
const path = require('path'); | ||
|
||
const cliGoNativeCommand = "rt go"; | ||
const cliGoPublishCommand = "rt gp"; | ||
let configuredServerId; | ||
|
||
function RunTaskCbk(cliPath) { | ||
let defaultWorkDir = tl.getVariable('System.DefaultWorkingDirectory'); | ||
if (!defaultWorkDir) { | ||
tl.setResult(tl.TaskResult.Failed, "Failed getting default working directory."); | ||
return; | ||
} | ||
|
||
// Determine working directory for the cli. | ||
let inputWorkingDirectory = tl.getInput("workingDirectory", false); | ||
let requiredWorkDir = utils.determineCliWorkDir(defaultWorkDir, inputWorkingDirectory); | ||
if (!fs.existsSync(requiredWorkDir) || !fs.lstatSync(requiredWorkDir).isDirectory()) { | ||
tl.setResult(tl.TaskResult.Failed, "Provided 'Working Directory': " + requiredWorkDir + " neither exists nor a directory."); | ||
return; | ||
} | ||
|
||
// Determine go command and run cli. | ||
let inputCommand = tl.getInput("command", true); | ||
switch(inputCommand) { | ||
// Fall-through if command is build / test / get | ||
case 'build': | ||
case 'test': | ||
case 'get': | ||
performGoNativeCommand(inputCommand, cliPath, requiredWorkDir); | ||
break; | ||
case 'custom': | ||
let customCommand = tl.getInput("customCommand", true); | ||
performGoNativeCommand(customCommand, cliPath, requiredWorkDir); | ||
break; | ||
case 'publish': | ||
performGoPublishCommand(cliPath, requiredWorkDir); | ||
break; | ||
} | ||
} | ||
|
||
function performGoNativeCommand(goCommand, cliPath, requiredWorkDir) { | ||
// Create config file and configure cli server | ||
let configPath = path.join(requiredWorkDir, ".jfrog", "projects", "go.yaml"); | ||
try { | ||
createGoConfigFile(configPath, cliPath, requiredWorkDir); | ||
} catch (ex) { | ||
tl.setResult(tl.TaskResult.Failed, ex); | ||
return; | ||
} | ||
|
||
// Build go command with arguments and execute. | ||
let cliCommand = utils.cliJoin(cliPath, cliGoNativeCommand, goCommand); | ||
let goArguments = tl.getInput("goArguments", false); | ||
if (goArguments) { | ||
cliCommand = utils.cliJoin(cliCommand, goArguments); | ||
} | ||
executeGoCliCommand(cliCommand, cliPath, requiredWorkDir); | ||
} | ||
|
||
function createGoConfigFile(configPath, cliPath, requiredWorkDir) { | ||
configureGoCliServer(cliPath, requiredWorkDir, "resolver"); | ||
let resolutionRepo = tl.getInput("resolutionRepo", true); | ||
let resolverObj = {serverId: configuredServerId, repo: resolutionRepo}; | ||
utils.createBuildToolConfigFile(configPath, 'go', resolverObj, {}); | ||
} | ||
|
||
function performGoPublishCommand(cliPath, requiredWorkDir) { | ||
try { | ||
configureGoCliServer(cliPath, requiredWorkDir, "deployer"); | ||
} catch (ex) { | ||
tl.setResult(tl.TaskResult.Failed, ex); | ||
return; | ||
} | ||
|
||
// Build go publish command and execute | ||
let targetRepo = tl.getInput("targetRepo", true); | ||
let version = tl.getInput("version", false); | ||
let cliCommand = utils.cliJoin(cliPath, cliGoPublishCommand, targetRepo, version); | ||
executeGoCliCommand(cliCommand, cliPath, requiredWorkDir); | ||
} | ||
|
||
function executeGoCliCommand(cliCommand, cliPath, requiredWorkDir) { | ||
// Add build info collection. | ||
cliCommand = utils.appendBuildFlagsToCliCommand(cliCommand); | ||
|
||
// Execute cli. | ||
try { | ||
utils.executeCliCommand(cliCommand, requiredWorkDir, null); | ||
} catch (ex) { | ||
tl.setResult(tl.TaskResult.Failed, ex); | ||
} finally { | ||
cleanup(cliPath, requiredWorkDir); | ||
} | ||
// Ignored if the build's result was previously set to 'Failed'. | ||
tl.setResult(tl.TaskResult.Succeeded, "Build Succeeded.") | ||
} | ||
|
||
function configureGoCliServer(cliPath, buildDir, serverType) { | ||
configuredServerId = utils.assembleBuildToolServerId('go', serverType); | ||
let artifactoryService = tl.getInput("artifactoryService", false); | ||
utils.configureCliServer(artifactoryService, configuredServerId, cliPath, buildDir); | ||
} | ||
|
||
function cleanup(cliPath, workDir) { | ||
// Delete servers. | ||
try { | ||
utils.deleteCliServers(cliPath, workDir, [configuredServerId]); | ||
} catch (deleteServersException) { | ||
tl.setResult(tl.TaskResult.Failed, deleteServersException); | ||
} | ||
} | ||
|
||
utils.executeCliTask(RunTaskCbk); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "artifactory-go", | ||
"version": "1.0.0", | ||
"author": "JFrog", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
"main": "goBuild.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^7.0.0", | ||
"azure-pipelines-task-lib": "^2.7.1", | ||
"artifactory-tasks-utils": "file:../../artifactory-tasks-utils/artifactory-tasks-utils-1.0.0.tgz" | ||
} | ||
} |
Oops, something went wrong.