Skip to content

Commit

Permalink
Merge pull request #49 from snyk/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
maxjeffos authored Apr 23, 2020
2 parents d6582f9 + 01562a0 commit 78dbdf8
Show file tree
Hide file tree
Showing 25 changed files with 439 additions and 231 deletions.
12 changes: 10 additions & 2 deletions scripts/ci-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ fi
PWD=$(pwd)
echo "PWD: ${PWD}"

echo "Installing tfx-cli globally..."
sudo npm install -g [email protected]
set +e
# check if tfx is installed and if not, install it
tfx version >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Installing tfx-cli globally..."
sudo npm install -g [email protected]
else
echo "tfx-cli already installed"
fi
set -e

# Build project
"${PWD}/scripts/ci-build.sh" "prod"
Expand Down
44 changes: 31 additions & 13 deletions scripts/share-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AZ_EXT_NEW_VERSION="$1"
AZ_ORG="$2"

# Check if AZ Cli is already installed. If not installed it.
# Check if the Azure CLI is already installed. If not, install it.
az -v >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Intalling AZ Cli..."
Expand All @@ -31,13 +31,14 @@ if [[ ! $? -eq 0 ]]; then
fi
fi

# Unistall the extinsion if it has been already installed in this organization
echo "Uninstall extension..."
az devops extension uninstall \
--publisher-name $AZ_PUBLISHER \
--extension-name $AZ_EXTENSION_ID \
--organization "https://dev.azure.com/${AZ_ORG}/" --yes
echo "Extension uninstalled"
echo "About to deploy to dev environment using:"
echo "AZ_EXT_NEW_VERSION: ${AZ_EXT_NEW_VERSION}"
echo "AZ_PUBLISHER: ${AZ_PUBLISHER}"
echo "AZ_EXTENSION_ID: ${AZ_EXTENSION_ID}"
echo "AZ_TASK_NAME: ${AZ_TASK_NAME}"
echo "AZ_TASK_FRIENDLY_NAME: ${AZ_TASK_FRIENDLY_NAME}"
echo "AZ_ORG: ${AZ_ORG}"
echo "AZ_DEV_TASK_ID: ${AZ_DEV_TASK_ID}"

# Updating version in task.json file
node "${PWD}/scripts/update-task-json-dev.js" ${AZ_EXT_NEW_VERSION}
Expand All @@ -46,24 +47,41 @@ node "${PWD}/scripts/update-task-json-dev.js" ${AZ_EXT_NEW_VERSION}
OVERRIDE_JSON="{ \"name\": \"${AZ_EXTENSION_NAME}\", \"version\": \"${AZ_EXT_NEW_VERSION}\" }"

# Sharing extension
echo "Sharing extension..."
echo "Publishing and sharing extension..."
echo "OVERRIDE_JSON: ${OVERRIDE_JSON}"

tfx extension publish --manifest-globs vss-extension-dev.json \
--version $AZ_EXT_NEW_VERSION \
--share-with $AZ_ORG \
--extension-id $AZ_EXTENSION_ID \
--publisher $AZ_PUBLISHER \
--override $OVERRIDE_JSON \
--token $AZURE_DEVOPS_EXT_PAT
echo "Extension shared"

# Install extension in the organization after it was shared with the same organization
echo "Installing extension..."
az devops extension install \
publish_exit_code=$?
if [[ publish_exit_code -eq 0 ]]; then
echo "Extension published and shared with Azure org"
else
echo "Extension failed to pubish with exit code ${publish_exit_code}"
exit ${publish_exit_code}
fi

# echo "See if the extension is installed..."
az devops extension show \
--publisher-name $AZ_PUBLISHER \
--extension-name $AZ_EXTENSION_ID \
--organization "https://dev.azure.com/${AZ_ORG}/"

if [[ $? -eq 0 ]]; then
echo "Extension already installed in org ${AZ_ORG}"
else
echo "Extension not already installed."
echo "Installing extension..."
az devops extension install \
--publisher-name $AZ_PUBLISHER \
--extension-name $AZ_EXTENSION_ID \
--organization "https://dev.azure.com/${AZ_ORG}/"
fi

# Updating version in task.json file
node "${PWD}/scripts/recovery-task-json-dev.js"
Expand Down
21 changes: 12 additions & 9 deletions scripts/update-task-json-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ if (!version.match(/[0-9]+\.[0-9]+\.[0-9]+/)) {
process.exitCode = 1;
process.exit();
}
const taskId = process.env.AZ_EXTENSION_ID;
const taskFriendlyName = process.env.AZ_EXTENSION_NAME

const taskId = process.env.AZ_DEV_TASK_ID; // don't use the production GUID for dev/test deploys
const taskName = process.env.AZ_TASK_NAME;
const taskFriendlyName = process.env.AZ_TASK_FRIENDLY_NAME;

// Break version and create the JSON to be replaced
const metaVersion = version.split(".");
Expand All @@ -24,13 +26,14 @@ console.log("taskVersion: ", taskVersion);
// Replace version in the snykTask/task.json file
const filePath = "./snykTask/task.json";
const fileBakPath = "./snykTask/task.json.bak";
const taskJSON_File = JSON.parse(fs.readFileSync(filePath, "utf8"));
fs.writeFileSync(fileBakPath, JSON.stringify(taskJSON_File, null, 2), "utf8");
const taskJsonFileObj = JSON.parse(fs.readFileSync(filePath, "utf8"));
fs.writeFileSync(fileBakPath, JSON.stringify(taskJsonFileObj, null, 2), "utf8");

// update information
taskJSON_File["version"] = taskVersion;
taskJSON_File["id"] = taskId;
taskJSON_File["name"] = `Dev-${taskJSON_File["name"]}-${taskId}`;
taskJSON_File["friendlyName"] = taskFriendlyName;
fs.writeFileSync(filePath, JSON.stringify(taskJSON_File, null, 2), "utf8");
taskJsonFileObj["version"] = taskVersion;
taskJsonFileObj["id"] = taskId;
taskJsonFileObj["name"] = taskName;
taskJsonFileObj["friendlyName"] = taskFriendlyName;
fs.writeFileSync(filePath, JSON.stringify(taskJsonFileObj, null, 2), "utf8");

console.log("Version replaced in snykTask/task.json file");
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -47,19 +48,15 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --docker myImage --file=Dockerfile --someAdditionalArgs --json": {
"/usr/bin/snyk test --docker myImage --file=Dockerfile --someAdditionalArgs --json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor --docker myImage --file=Dockerfile --org=some-snyk-org --project-name=some-projectName --someAdditionalArgs": {
"/usr/bin/snyk monitor --docker myImage --file=Dockerfile --org=some-snyk-org --project-name=some-projectName --someAdditionalArgs": {
code: 0,
stdout: "No issues found"
}
Expand Down
13 changes: 5 additions & 8 deletions snykTask/src/__tests__/_test-mock-config-basic-smoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -45,19 +46,15 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --someAdditionalArgs --json": {
"/usr/bin/snyk test --someAdditionalArgs --json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor --org=some-snyk-org --project-name=some-projectName --someAdditionalArgs": {
"/usr/bin/snyk monitor --org=some-snyk-org --project-name=some-projectName --someAdditionalArgs": {
code: 0,
stdout: "No issues found"
}
Expand Down
13 changes: 5 additions & 8 deletions snykTask/src/__tests__/_test-mock-config-monitorOnBuild-false.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -45,19 +46,15 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --json": {
"/usr/bin/snyk test --json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor --org=some-snyk-org": {
"/usr/bin/snyk monitor --org=some-snyk-org": {
code: 0,
stdout: "No issues found"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -43,19 +44,15 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --json": {
"/usr/bin/snyk test --json": {
code: 1,
stdout: "Issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor --project-name=someProjectName": {
"/usr/bin/snyk monitor --project-name=someProjectName": {
code: 0,
stdout: "No issues found"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -43,19 +44,15 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --json": {
"/usr/bin/snyk test --json": {
code: 1,
stdout: "Issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor": {
"/usr/bin/snyk monitor": {
code: 0,
stdout: "No issues found"
}
Expand Down
13 changes: 7 additions & 6 deletions snykTask/src/__tests__/_test-mock-config-no-organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -39,23 +40,23 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Ok"
},
"/usr/bin/snyk auth some-authToken": {
"/usr/bin/auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
"/usr/bin/snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --json": {
"/usr/bin/snyk test --json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor": {
"/usr/bin/snyk monitor": {
code: 0,
stdout: "No issues found"
}
Expand Down
13 changes: 5 additions & 8 deletions snykTask/src/__tests__/_test-mock-config-no-projectName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const answers: ma.TaskLibAnswers = {
ls: "/bin/ls",
npm: "/usr/bin/npm",
snyk: "/usr/bin/snyk",
sudo: "/usr/bin/sudo"
sudo: "/usr/bin/sudo",
"snyk-to-html": "/usr/bin/snyk-to-html"
},
exec: {
"/bin/ls -la": {
Expand All @@ -46,19 +47,15 @@ const answers: ma.TaskLibAnswers = {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk auth some-authToken": {
code: 0,
stdout: "Snyk CLI authorized!"
},
"/usr/bin/sudo snyk test --json": {
"/usr/bin/snyk test --json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk-to-html -i null/report.json": {
"/usr/bin/snyk-to-html -i null/report.json": {
code: 0,
stdout: "No issues found"
},
"/usr/bin/sudo snyk monitor --org=some-snyk-org": {
"/usr/bin/snyk monitor --org=some-snyk-org": {
code: 0,
stdout: "No issues found"
}
Expand Down
Loading

0 comments on commit 78dbdf8

Please sign in to comment.