Skip to content

Commit

Permalink
onboard to v0.2.3 🚀 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyAyushh authored Feb 7, 2022
1 parent 1ce8932 commit 206ae9f
Show file tree
Hide file tree
Showing 37 changed files with 567 additions and 55 deletions.
25 changes: 17 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Change Log

All notable changes to the 'vscode-anchor' extension will be documented in this file.

## Version 0.2.2 [current]
### Added

All notable changes to the 'vscode-anchor' extension will be documented in this file.

## Version 0.2.3 [current]
### Added
- Added Help Commands to your favourite docs site.
- Analyze your code with Soteria, Cargo Audit, and clippy.
- Fixed Build Verifiable Command.

---
## Version 0.2.2
### Added
- Anchor cli commands to vscode.
- Install anchor cli if not found.
- Anchor container view with programs and tests.
## Version 0.1.0
### Added
- Anchor container view with programs and tests.

---
## Version 0.1.0
### Added

- Initialised extension
- Scaffolded Structure
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions assets/dark/verified.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions assets/light/verified.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
59 changes: 40 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"displayName": "Anchor",
"publisher": "Ayushh",
"description": "vscode extension for Anchor (Solana's Sealevel runtime Framework)",
"version": "0.2.2",
"icon": "static/marketplace-logo.png",
"version": "0.2.3",
"icon": "assets/marketplace-logo.png",
"homepage": "https://github.com/microsoft/vscode-anchor/blob/main/README.md",
"galleryBanner": {
"color": "#1d1d1d",
Expand Down Expand Up @@ -35,7 +35,7 @@
{
"id": "vscode-anchor-view",
"title": "Anchor",
"icon": "static/anchor-wave.svg"
"icon": "assets/anchor-wave.svg"
}
]
},
Expand All @@ -59,18 +59,26 @@
]
},
"commands": [
{
"command": "vscode-anchor.analyze",
"title": "Anchor: Analyze and Scan for vulnerabilities"
},
{
"command": "vscode-anchor.build",
"title": "Anchor: Build"
},
{
"command": "vscode-anchor.buildVerifiable",
"title": "Anchor: Build Verifiable"
"title": "Anchor: Verifiable Build all Programs"
},
{
"command": "vscode-anchor.deploy",
"title": "Anchor: Deploy"
},
{
"command": "vscode-anchor.help",
"title": "Anchor: Help !!"
},
{
"command": "vscode-anchor.install",
"title": "Anchor: Install CLI"
Expand All @@ -81,7 +89,7 @@
},
{
"command": "vscode-anchor.removeDockerImage",
"title": "Anchor: remove Docker Image (in new workspace)"
"title": "Anchor: remove build Docker Image"
},
{
"command": "vscode-anchor.scaffold",
Expand Down Expand Up @@ -111,56 +119,64 @@
"command": "vscode-anchor-view-programs.refreshEntry",
"title": "Refresh",
"icon": {
"light": "static/light/refresh.svg",
"dark": "static/dark/refresh.svg"
"light": "assets/light/refresh.svg",
"dark": "assets/dark/refresh.svg"
}
},
{
"command": "vscode-anchor-view-programs.addEntry",
"title": "Add",
"icon": {
"light": "static/light/add.svg",
"dark": "static/dark/add.svg"
"light": "assets/light/add.svg",
"dark": "assets/dark/add.svg"
}
},
{
"command": "vscode-anchor-view-programs.editEntry",
"title": "Edit",
"icon": {
"light": "static/light/edit.svg",
"dark": "static/dark/edit.svg"
"light": "assets/light/edit.svg",
"dark": "assets/dark/edit.svg"
}
},
{
"command": "vscode-anchor-view-programs.build",
"title": "Build Programs",
"icon": {
"light": "static/light/build.svg",
"dark": "static/dark/build.svg"
"light": "assets/light/build.svg",
"dark": "assets/dark/build.svg"
}
},
{
"command": "vscode-anchor-view-programs.buildVerifiableItem",
"title": "build verifiable",
"icon": {
"light": "assets/light/verified.svg",
"dark": "assets/dark/verified.svg"
}
},
{
"command": "vscode-anchor-view-tests.test",
"title": "Start Tests",
"icon": {
"light": "static/light/beaker.svg",
"dark": "static/dark/beaker.svg"
"light": "assets/light/beaker.svg",
"dark": "assets/dark/beaker.svg"
}
},
{
"command": "vscode-anchor-view-tests.refreshEntry",
"title": "Refresh",
"icon": {
"light": "static/light/refresh.svg",
"dark": "static/dark/refresh.svg"
"light": "assets/light/refresh.svg",
"dark": "assets/dark/refresh.svg"
}
},
{
"command": "vscode-anchor-view-tests.editEntry",
"title": "Edit",
"icon": {
"light": "static/light/edit.svg",
"dark": "static/dark/edit.svg"
"light": "assets/light/edit.svg",
"dark": "assets/dark/edit.svg"
}
}
],
Expand Down Expand Up @@ -198,6 +214,11 @@
"when": "view == vscode-anchor-view-programs && viewItem == program",
"group": "inline"
},
{
"command": "vscode-anchor-view-programs.buildVerifiableItem",
"when": "view == vscode-anchor-view-programs && viewItem == program",
"group": "inline"
},
{
"command": "vscode-anchor-view-tests.editEntry",
"when": "view == vscode-anchor-view-tests && viewItem == test",
Expand Down
142 changes: 142 additions & 0 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { spawnChan } from "../helpers/spawnExec";
import * as vscode from 'vscode';
import { EXT_NAME, WORKSPACE_PATH } from "../config";
import chan, { appendChan } from "../helpers/outputChannel";
import path = require("path");
import { getDirectories } from "../helpers/util";
import * as os from 'os';

const installSoteriaCli = async () => {
const isSoteriaCliSupported = () => os.arch() === 'x64' && os.type() === 'Linux';
if (isSoteriaCliSupported()) {
try {
await spawnChan('sh', ['-c', '"$(curl -k https://supercompiler.xyz/install)"'], 'soteria install', WORKSPACE_PATH());
await spawnChan('export', ['PATH=$PWD/soteria-linux-develop/bin/:$PATH'], 'soteria install', WORKSPACE_PATH(), true);
} catch (err) {
if (err instanceof Error) {
appendChan('ERROR', err.message);
chan.show(true);
}
vscode.window.showErrorMessage('Installing soteria failed ;c ');
}
} else {
// Install using docker
try {
await spawnChan('docker', ['run', '-v', WORKSPACE_PATH(), '-it', 'greencorelab/soteria:0.1.0', '/bin/bash'], 'build anchor cli from source');
} catch (err) {
if (err instanceof Error) {

}
}
}
};

const anchorAnalyze = () => vscode.commands.registerCommand(
`${EXT_NAME}.analyze`,
async () => {
vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: "Analyzing Anchor ⚓ Project ...",
cancellable: false
}, async (progress, token) => {
if (!vscode.workspace.workspaceFolders) {
vscode.window.showErrorMessage(
"No workspace folder is open. Please open a workspace folder."
);
return;
}

const isSoteriaCliSupported = () => os.arch() === 'x64' && os.type() === 'Linux';

const programsPath = path.join(WORKSPACE_PATH(), 'programs');
const directories = getDirectories(programsPath);

chan.show(true);

chan.appendLine('*****************************************');
chan.appendLine('*****************************************');
chan.appendLine('Analyze: Cargo Audit has been started!');
chan.appendLine('*****************************************');
chan.appendLine('*****************************************');

try {
await spawnChan('cargo', ['audit'], 'Cargo Audit', WORKSPACE_PATH(), true);
} catch(err) {
await spawnChan('cargo', ['install', 'audit'], 'Cargo Audit Install', WORKSPACE_PATH(), true);
await spawnChan('cargo', ['audit'], 'Cargo Audit', WORKSPACE_PATH(), true);
}

chan.appendLine('*****************************************');
chan.appendLine('*****************************************');
chan.appendLine('Analyze: Cargo Clippy has been started!');
chan.appendLine('*****************************************');
chan.appendLine('*****************************************');

for (const directory of directories) {
const programDirectory = path.join(programsPath, directory);
await spawnChan('cargo', ['clippy'], `cargo clippy ${directory}`, programDirectory, true);
}

if (isSoteriaCliSupported()) {
try {
await spawnChan('soteria', ['-v'], '', '', true);

chan.clear();
chan.show(true);
chan.appendLine('*****************************************');
chan.appendLine('*****************************************');
chan.appendLine('Analyze: Soteria has been started!');
chan.appendLine('*****************************************');
chan.appendLine('*****************************************');

for (const directory of directories) {
const programDirectory = path.join(programsPath, directory);
await spawnChan('soteria', ['.'], `soteria analyze ${directory}`, programDirectory, true);
}

vscode.window.showInformationMessage(`Anchor ⚓: Analyzing and Scan code has been completed!`);
} catch (err) {
if (!(err instanceof Error)) {
throw new Error('Unexpected error');
}

if (err.message === 'spawn soteria ENOENT') {
const selection = await vscode
.window
.showWarningMessage(
"Soteria CLI was not found!",
"Install it",
"Ignuwu"
);

if (selection === "Install it") {
await installSoteriaCli();
vscode.commands.executeCommand(`${EXT_NAME}.analyze`);
} else {
chan.appendLine("Soteria CLI was not found and not Installed! ngmi");
};
}
}
} else {
const terminal = vscode.window.createTerminal(`Soteria Analyze`);
terminal.sendText('docker run -v ' + WORKSPACE_PATH() + '/programs:/workspace -it greencorelab/soteria:0.1.0 /bin/bash');

terminal.show();
vscode.window.showInformationMessage(`run 'soteria -analyzeAll .' inside every program directory.`);

vscode.window.onDidCloseTerminal(async (terminal) => {
if (terminal.name === 'Soteria Analyze') {
await spawnChan(`docker ps -a | grep "soteria" | awk '{print $1}' | xargs docker rm -f`, [], '', '', true);
chan.clear();
}
});
}

vscode.window.showInformationMessage('Analyzing and Scan code has been completed!');
});
}
);

export {
anchorAnalyze
};
Loading

0 comments on commit 206ae9f

Please sign in to comment.