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

chore: vendor pro binary with vscode #164

Merged
merged 27 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
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
48 changes: 39 additions & 9 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
on:
push:
tags:
- "*"
release:
types: [published]
workflow_dispatch:
inputs:
preRelease:
description: "Is this a pre-release?"
type: boolean
required: false
default: false
dryRun:
description: "Is this a dry run?"
type: boolean
required: false
default: false

name: Deploy Extension
jobs:
deploy:
vsce-test:
strategy:
matrix:
target: [linux-x64, linux-arm64, darwin-x64, darwin-arm64]
name: Deploy Extension
ajbt200128 marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4.0.3
with:
node-version: 16
node-version: lts/*
- run: npm ci
- uses: "aws-actions/[email protected]"
with:
role-to-assume: "arn:aws:iam::338683922796:role/semgrep-ide-integration-deploy-role"
role-duration-seconds: 900,
role-session-name: "semgrep-ide-integration-deploy"
aws-region: "us-west-2"
- name: download osemgrep pro
run: ./download-osemgrep-pro.sh ${{ matrix.target }}
- name: Publish to Open VSX Registry
uses: HaaLeo/publish-vscode-extension@v1
uses: HaaLeo/publish-vscode-extension@v1.6.2
id: publishToOpenVSX
with:
# Tied to austin@, lives in 1password, does not expire
pat: ${{ secrets.OPEN_VSX_TOKEN }}
target: ${{ matrix.target }} # only for specific platforms
# release pre-release if that's the event
preRelease: ${{github.event.release.prerelease || inputs.preRelease}}
dryRun: "${{ inputs.dryRun }}"
ajbt200128 marked this conversation as resolved.
Show resolved Hide resolved
- name: Publish to Visual Studio Marketplace
uses: HaaLeo/publish-vscode-extension@v1
uses: HaaLeo/publish-vscode-extension@v1.6.2
with:
# Tied to bence@, lives in 1password expires in may 2024
pat: ${{ secrets.VS_MARKETPLACE_TOKEN }}
registryUrl: https://marketplace.visualstudio.com
extensionFile: ${{ steps.publishToOpenVSX.outputs.vsixPath }}
target: ${{ matrix.target }}
# release pre-release if that's the event
preRelease: ${{github.event.release.prerelease || inputs.preRelease}}
dryRun: "${{ inputs.dryRun }}"
24 changes: 18 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ jobs:
- name: Install Semgrep
run: python -m pip install semgrep
- name: Setup
uses: actions/setup-node@v1
uses: actions/setup-node@v4.0.3
with:
node-version: 16.x
node-version: lts/*
- name: install dependencies
run: npm ci
- uses: "aws-actions/[email protected]"
with:
role-to-assume: "arn:aws:iam::338683922796:role/semgrep-ide-integration-deploy-role"
role-duration-seconds: 900,
role-session-name: "semgrep-ide-integration-deploy"
aws-region: "us-west-2"
- if: matrix.os == 'macos-latest'
name: download osemgrep pro
run: ./download-osemgrep-pro.sh darwin-arm64
- if: matrix.os == 'ubuntu-latest'
name: download osemgrep pro
run: ./download-osemgrep-pro.sh linux-x64
- name: pretest
run: npm run pretest
- name: run native tests (Linux)
Expand Down Expand Up @@ -58,9 +70,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup
uses: actions/setup-node@v1
uses: actions/setup-node@v4.0.3
with:
node-version: 16.x
node-version: lts/*
- name: install dependencies
run: npm ci
# This is needed so download-lspjs.sh can run
Expand All @@ -83,8 +95,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4.0.3
with:
node-version: 16
node-version: lts/*
- run: npm ci
- run: npm run vscode:prepublish
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ node_modules

# Misc
.DS_Store
lspjs
dist/*
# From testing
*_results.json

Expand Down
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"recommendations": ["Semgrep.semgrep", "Tobermory.es6-string-html"]
"recommendations": [
"Semgrep.semgrep",
"Tobermory.es6-string-html",
"connor4312.esbuild-problem-matchers"
]
}
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"preLaunchTask": "watch-build"
"preLaunchTask": "watch"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Server",
"port": 6009,
"port": 9229,
"restart": true,
"outFiles": [
"${workspaceRoot}/lspjs/out/**/*.js",
Expand All @@ -34,7 +34,7 @@
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"preLaunchTask": {
"type": "npm",
"script": "test-compile"
"script": "esbuild"
}
}
]
Expand Down
46 changes: 21 additions & 25 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,39 @@
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"group": "build",
"label": "watch",
"dependsOn": ["npm: watch:tsc", "npm: watch:esbuild"],
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": ["$tsc"]
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"label": "watch-build",
"script": "esbuild-watch",
"label": "npm: watch:esbuild",
"script": "watch:esbuild",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"fileLocation": "relative",
"pattern": {
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
},
"background": {
"activeOnStart": true,
"beginsPattern": "\\[watch\\] build started.*",
"endsPattern": "\\[watch\\] build finished.*"
}
"problemMatcher": "$esbuild-watch",
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
},
}
},
{
"type": "npm",
"script": "watch:tsc",
"group": "build",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"label": "npm: watch:tsc",
"presentation": {
"panel": "dedicated",
"group": "watch",
"reveal": "never"
}
}
Expand Down
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
.vscode/**
.vscode-test/**
out/test/**
out/semgrep-lsp.js
src/**
node_modules/**
.pre-commit-config.yaml
build.mjs
download-lspjs.sh
download-osemgrep-pro.sh
eslint.config.js
images/**
.github/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
Expand Down
40 changes: 34 additions & 6 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
async function buildSentrySourceMap() {
esbuild.build({
sourcemap: true, // Source map generation must be turned on
bundle: true,
platform: "node",
plugins: [
// Put the Sentry esbuild plugin after all other plugins
sentryEsbuildPlugin({
Expand All @@ -16,7 +18,8 @@ async function buildSentrySourceMap() {
],
});
}
async function buildExtension(watch) {

async function buildExtension(watch, sourcemap, minify) {
const options = {
logLevel: "info",
entryPoints: ["./src/extension.ts"],
Expand All @@ -25,7 +28,9 @@ async function buildExtension(watch) {
platform: "node",
format: "cjs",
external: ["vscode"],
sourcemap: isSourcemap,
sourcemap,
plugins: [esbuildProblemMatcherPlugin],
minify,
};
if (watch) {
let ctx = await esbuild.context(options);
Expand All @@ -34,14 +39,16 @@ async function buildExtension(watch) {
await esbuild.build(options);
}
}
async function buildWebview(watch) {
async function buildWebview(watch, sourcemap, minify) {
let options = {
logLevel: "info",
entryPoints: ["./src/webview-ui/index.tsx"],
outfile: "./out/webview.js",
bundle: true,
platform: "node",
plugins: [cssModulesPlugin()],
sourcemap: isSourcemap,
sourcemap,
minify,
};
if (watch) {
let ctx = await esbuild.context(options);
Expand All @@ -53,9 +60,30 @@ async function buildWebview(watch) {

const isWatch = process.argv.includes("--watch");
const isSourcemap = process.argv.includes("--sourcemap");
const isMinify = process.argv.includes("--minify");
/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: "esbuild-problem-matcher",

setup(build) {
build.onStart(() => {
console.log("[watch] build started");
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(
` ${location.file}:${location.line}:${location.column}:`,
);
});
console.log("[watch] build finished");
});
},
};
await Promise.all([
buildExtension(isWatch, isSourcemap),
buildWebview(isWatch, isSourcemap),
buildExtension(isWatch, isSourcemap, isMinify),
buildWebview(isWatch, isSourcemap, isMinify),
buildSentrySourceMap(),
]);
11 changes: 7 additions & 4 deletions download-lspjs.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env bash
set -eu
# Check if lspjs exists and if its a symlink then exit
if [ -L lspjs ]; then
if [ -L dist/lspjs ]; then
echo "lspjs symlink exists, not downloading as you are most likely using a local version"
exit 0
fi
mkdir -p lspjs/dist
for var in "$@"
mkdir -p dist/lspjs
echo "Downloading lspjs from S3 for version $(cat ./semgrep-version)"
ajbt200128 marked this conversation as resolved.
Show resolved Hide resolved
for var in Main.bc.js language-server-wasm.js semgrep-lsp-bindings.js semgrep-lsp.js
ajbt200128 marked this conversation as resolved.
Show resolved Hide resolved
do
curl https://static.semgrep.dev/static/turbo/$(cat ./semgrep-version)/language_server/dist/$var -o ./lspjs/dist/$var
echo "Downloading $var"
curl "https://static.semgrep.dev/static/turbo/$(cat ./semgrep-version)/language_server/dist/$var" -o "./dist/lspjs/$var"
done
echo "Downloaded lspjs"
24 changes: 24 additions & 0 deletions download-osemgrep-pro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -eu
uname=$1
case "${uname}" in
linux-x64*) machine=manylinux;;
linux-arm64*) machine=linux-arm64;;
darwin-x64*) machine=osx;;
darwin-arm64) machine=osx-m1;;
*) machine=manylinux;;
esac
# NOT the same as the semgrep version!!!!
OSEMGREP_PRO_VERSION=$(cat ./osemgrep-pro-version)
BINARY=semgrep-core-proprietary-${machine}-${OSEMGREP_PRO_VERSION}
# Check if osemgrep-pro exists and if its a symlink then exit
if [ -L dist/osemgrep-pro ]; then
echo "osemgrep-pro symlink exists, not downloading as you are most likely using a local version"
exit 0
fi
mkdir -p dist
echo "Downloading osemgrep-pro binary from S3 for version ${machine}-${OSEMGREP_PRO_VERSION}"
aws s3 cp s3://deep-semgrep-artifacts/${BINARY} dist/osemgrep-pro
echo "Downloaded osemgrep-pro binary"
echo "Making osemgrep-pro binary executable"
chmod +x dist/osemgrep-pro
1 change: 1 addition & 0 deletions osemgrep-pro-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.149.0
Loading
Loading