Skip to content

Commit

Permalink
Merge pull request microsoft#161640 from microsoft/build-integrated-cli
Browse files Browse the repository at this point in the history
Update build process to include integrated CLI
  • Loading branch information
connor4312 authored Oct 12, 2022
2 parents bf220dd + b42f25b commit 6353f80
Show file tree
Hide file tree
Showing 85 changed files with 7,441 additions and 6,527 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
"editor.insertSpaces": true
},
"typescript.tsc.autoDetect": "off",
"testing.autoRun.mode": "rerun",
Expand Down
50 changes: 50 additions & 0 deletions build/azure-pipelines/cli/cli-compile-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
parameters:
- name: VSCODE_CLI_TARGET
type: string
- name: VSCODE_CLI_ARTIFACT
type: string
- name: VSCODE_CLI_ENV
type: object
default: {}

steps:
- script: cargo build --release --target ${{ parameters.VSCODE_CLI_TARGET }} --bin=code-tunnel
displayName: Compile ${{ parameters.VSCODE_CLI_TARGET }}
workingDirectory: $(Build.SourcesDirectory)/cli
env:
VSCODE_CLI_VERSION: $(VSCODE_CLI_VERSION)
VSCODE_CLI_REMOTE_LICENSE_TEXT: $(VSCODE_CLI_REMOTE_LICENSE_TEXT)
VSCODE_CLI_REMOTE_LICENSE_PROMPT: $(VSCODE_CLI_REMOTE_LICENSE_PROMPT)
VSCODE_CLI_ASSET_NAME: ${{ parameters.VSCODE_CLI_ARTIFACT }}
VSCODE_CLI_AI_KEY: $(VSCODE_CLI_AI_KEY)
VSCODE_CLI_AI_ENDPOINT: $(VSCODE_CLI_AI_ENDPOINT)
${{ each pair in parameters.VSCODE_CLI_ENV }}:
${{ pair.key }}: ${{ pair.value }}

- ${{ if or(contains(parameters.VSCODE_CLI_TARGET, '-windows-'), contains(parameters.VSCODE_CLI_TARGET, '-darwin')) }}:
- task: ArchiveFiles@2
inputs:
${{ if contains(parameters.VSCODE_CLI_TARGET, '-windows-') }}:
rootFolderOrFile: $(Build.SourcesDirectory)/cli/target/${{ parameters.VSCODE_CLI_TARGET }}/release/code-tunnel.exe
${{ if contains(parameters.VSCODE_CLI_TARGET, '-darwin') }}:
rootFolderOrFile: $(Build.SourcesDirectory)/cli/target/${{ parameters.VSCODE_CLI_TARGET }}/release/code-tunnel
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/${{ parameters.VSCODE_CLI_ARTIFACT }}.zip

- publish: $(Build.ArtifactStagingDirectory)/${{ parameters.VSCODE_CLI_ARTIFACT }}.zip
artifact: ${{ parameters.VSCODE_CLI_ARTIFACT }}
displayName: Publish ${{ parameters.VSCODE_CLI_ARTIFACT }} artifact

- ${{ else }}:
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/cli/target/${{ parameters.VSCODE_CLI_TARGET }}/release/code-tunnel
includeRootFolder: false
archiveType: tar
tarCompression: gz
archiveFile: $(Build.ArtifactStagingDirectory)/${{ parameters.VSCODE_CLI_ARTIFACT }}.tar.gz

- publish: $(Build.ArtifactStagingDirectory)/${{ parameters.VSCODE_CLI_ARTIFACT }}.tar.gz
artifact: ${{ parameters.VSCODE_CLI_ARTIFACT }}
displayName: Publish ${{ parameters.VSCODE_CLI_ARTIFACT }} artifact
40 changes: 40 additions & 0 deletions build/azure-pipelines/cli/cli-darwin-sign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
parameters:
- name: VSCODE_CLI_ARTIFACTS
type: object
default: []

steps:
- task: UseDotNet@2
inputs:
version: 2.x

- task: EsrpClientTool@1
displayName: Download ESRPClient

- ${{ each target in parameters.VSCODE_CLI_ARTIFACTS }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ target }}
inputs:
artifact: ${{ target }}
path: $(Build.ArtifactStagingDirectory)/pkg/${{ target }}

- script: |
set -e
node build/azure-pipelines/common/sign "$(esrpclient.toolpath)/$(esrpclient.toolname)" darwin-sign $(ESRP-PKI) $(esrp-aad-username) $(esrp-aad-password) $(Build.ArtifactStagingDirectory)/pkg "*.zip"
displayName: Codesign
- script: |
set -e
node build/azure-pipelines/common/sign "$(esrpclient.toolpath)/$(esrpclient.toolname)" darwin-notarize $(ESRP-PKI) $(esrp-aad-username) $(esrp-aad-password) $(Build.ArtifactStagingDirectory)/pkg "*.zip"
displayName: Notarize
- ${{ each target in parameters.VSCODE_CLI_ARTIFACTS }}:
- script: |
set -e
ASSET_ID=$(echo "${{ target }}" | sed "s/unsigned_//")
mv $(Build.ArtifactStagingDirectory)/pkg/${{ target }}/${{ target }}.zip $(Build.ArtifactStagingDirectory)/pkg/${{ target }}/$ASSET_ID.zip
echo "##vso[task.setvariable variable=ASSET_ID]$ASSET_ID"
displayName: Set asset id variable
- publish: $(Build.ArtifactStagingDirectory)/pkg/${{ target }}/$(ASSET_ID).zip
artifact: $(ASSET_ID)
65 changes: 65 additions & 0 deletions build/azure-pipelines/cli/cli-win32-sign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
parameters:
- name: VSCODE_CLI_ARTIFACTS
type: object
default: []

steps:
- task: AzureKeyVault@1
displayName: "Azure Key Vault: Get Secrets"
inputs:
azureSubscription: "vscode-builds-subscription"
KeyVaultName: vscode
SecretsFilter: "ESRP-PKI,esrp-aad-username,esrp-aad-password"

- task: UseDotNet@2
displayName: "Use .NET"
inputs:
version: 3.x

- task: EsrpClientTool@1
displayName: "Use ESRP client"

- ${{ each target in parameters.VSCODE_CLI_ARTIFACTS }}:
- task: DownloadPipelineArtifact@2
displayName: Download artifacts
inputs:
artifact: ${{ target }}
path: $(Build.ArtifactStagingDirectory)/pkg/${{ target }}

- task: ExtractFiles@1
inputs:
archiveFilePatterns: $(Build.ArtifactStagingDirectory)/pkg/${{ target }}/*.zip
destinationFolder: $(Build.ArtifactStagingDirectory)/sign/${{ target }}

- powershell: |
. build/azure-pipelines/win32/exec.ps1
$ErrorActionPreference = "Stop"
$EsrpClientTool = (gci -directory -filter EsrpClientTool_* $(Agent.RootDirectory)\_tasks | Select-Object -last 1).FullName
$EsrpCliZip = (gci -recurse -filter esrpcli.*.zip $EsrpClientTool | Select-Object -last 1).FullName
mkdir -p $(Agent.TempDirectory)\esrpcli
Expand-Archive -Path $EsrpCliZip -DestinationPath $(Agent.TempDirectory)\esrpcli
$EsrpCliDllPath = (gci -recurse -filter esrpcli.dll $(Agent.TempDirectory)\esrpcli | Select-Object -last 1).FullName
echo "##vso[task.setvariable variable=EsrpCliDllPath]$EsrpCliDllPath"
displayName: Find ESRP CLI
- powershell: |
. build/azure-pipelines/win32/exec.ps1
$ErrorActionPreference = "Stop"
exec { node build\azure-pipelines\common\sign $env:EsrpCliDllPath windows $(ESRP-PKI) $(esrp-aad-username) $(esrp-aad-password) $(Build.ArtifactStagingDirectory)/sign "*.exe" }
displayName: "Code sign"
- ${{ each target in parameters.VSCODE_CLI_ARTIFACTS }}:
- powershell: |
$ASSET_ID = "${{ target }}".replace("unsigned_", "");
echo "##vso[task.setvariable variable=ASSET_ID]$ASSET_ID"
displayName: Set asset id variable
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)/sign/${{ target }}/code-tunnel.exe
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(ASSET_ID).zip

- publish: $(Build.ArtifactStagingDirectory)/$(ASSET_ID).zip
artifact: $(ASSET_ID)
37 changes: 37 additions & 0 deletions build/azure-pipelines/cli/install-rust-posix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameters:
- name: channel
type: string
default: stable
- name: targets
default: []
type: object

# Todo: use 1ES pipeline once extension is installed in ADO

steps:
- script: |
set -e
curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain $RUSTUP_TOOLCHAIN
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
env:
RUSTUP_TOOLCHAIN: ${{ parameters.channel }}
displayName: "Install Rust"
- script: |
set -e
rustup default $RUSTUP_TOOLCHAIN
rustup update $RUSTUP_TOOLCHAIN
env:
RUSTUP_TOOLCHAIN: ${{ parameters.channel }}
displayName: "Set Rust version"
- ${{ each target in parameters.targets }}:
- script: rustup target add ${{ target }}
displayName: "Adding Rust target '${{ target }}'"

- script: |
set -e
rustc --version
cargo --version
rustup --version
displayName: "Check Rust versions"
38 changes: 38 additions & 0 deletions build/azure-pipelines/cli/install-rust-win32.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
parameters:
- name: channel
type: string
default: stable
- name: targets
default: []
type: object

# Todo: use 1ES pipeline once extension is installed in ADO

steps:
- powershell: |
. build/azure-pipelines/win32/exec.ps1
exec { curl -sSf -o rustup-init.exe https://win.rustup.rs }
exec { rustup-init.exe -y --profile minimal --default-toolchain %RUSTUP_TOOLCHAIN% --default-host x86_64-pc-windows-msvc }
echo "##vso[task.prependpath]$env:USERPROFILE\.cargo\bin"
env:
RUSTUP_TOOLCHAIN: ${{ parameters.channel }}
displayName: "Install Rust"
- powershell: |
. build/azure-pipelines/win32/exec.ps1
exec { rustup default $RUSTUP_TOOLCHAIN }
exec { rustup update $RUSTUP_TOOLCHAIN }
env:
RUSTUP_TOOLCHAIN: ${{ parameters.channel }}
displayName: "Set Rust version"
- ${{ each target in parameters.targets }}:
- script: rustup target add ${{ target }}
displayName: "Adding Rust target '${{ target }}'"

- powershell: |
. build/azure-pipelines/win32/exec.ps1
exec { rustc --version }
exec { cargo --version }
exec { rustup --version }
displayName: "Check Rust versions"
32 changes: 32 additions & 0 deletions build/azure-pipelines/cli/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
const getVersion_1 = require("../../lib/getVersion");
const fs = require("fs");
const path = require("path");
const packageJson = require("../../../package.json");
const root = path.dirname(path.dirname(path.dirname(__dirname)));
const product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8'));
const commit = (0, getVersion_1.getVersion)(root);
/**
* Sets build environment variables for the CLI for current contextual info.
*/
const setLauncherEnvironmentVars = () => {
const vars = new Map([
['VSCODE_CLI_REMOTE_LICENSE_TEXT', product.serverLicense],
['VSCODE_CLI_REMOTE_LICENSE_PROMPT', product.serverLicensePrompt],
['VSCODE_CLI_VERSION', packageJson.version],
['VSCODE_CLI_COMMIT', commit],
]);
for (const [key, value] of vars) {
if (value) {
console.log(`##vso[task.setvariable variable=${key}]${value}`);
}
}
};
if (require.main === module) {
setLauncherEnvironmentVars();
}
35 changes: 35 additions & 0 deletions build/azure-pipelines/cli/prepare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { getVersion } from '../../lib/getVersion';
import * as fs from 'fs';
import * as path from 'path';
import * as packageJson from '../../../package.json';

const root = path.dirname(path.dirname(path.dirname(__dirname)));
const product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8'));
const commit = getVersion(root);

/**
* Sets build environment variables for the CLI for current contextual info.
*/
const setLauncherEnvironmentVars = () => {
const vars = new Map([
['VSCODE_CLI_REMOTE_LICENSE_TEXT', product.serverLicense],
['VSCODE_CLI_REMOTE_LICENSE_PROMPT', product.serverLicensePrompt],
['VSCODE_CLI_VERSION', packageJson.version],
['VSCODE_CLI_COMMIT', commit],
]);

for (const [key, value] of vars) {
if (value) {
console.log(`##vso[task.setvariable variable=${key}]${value}`);
}
}
};

if (require.main === module) {
setLauncherEnvironmentVars();
}
21 changes: 21 additions & 0 deletions build/azure-pipelines/cli/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parameters:
- name: VSCODE_CLI_TARGETS
default: []
type: object
- name: VSCODE_CLI_RUST_CHANNEL
type: string
default: stable

steps:
- template: ./install-rust.yml
parameters:
targets: []
channel: ${{ parameters.VSCODE_CLI_RUST_CHANNEL }}

- script: rustup component add clippy && cargo clippy -- -D warnings
workingDirectory: cli
displayName: Clippy lint

- script: cargo test
workingDirectory: cli
displayName: Run unit tests
1 change: 1 addition & 0 deletions build/azure-pipelines/cli/vcpkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vcpkg_installed
9 changes: 9 additions & 0 deletions build/azure-pipelines/cli/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "vscode-cli",
"dependencies": [
{
"name": "openssl"
}
],
"builtin-baseline": "23cc58477e200bb54c293ad76f3ce438dbabc86c"
}
8 changes: 8 additions & 0 deletions build/azure-pipelines/common/createAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function getPlatform(product, os, arch, type) {
throw new Error(`Unrecognized: ${product} ${os} ${arch} ${type}`);
}
return arch === 'ia32' ? 'server-win32-web' : `server-win32-${arch}-web`;
case 'cli':
return `cli-win32-${arch}`;
default:
throw new Error(`Unrecognized: ${product} ${os} ${arch} ${type}`);
}
Expand All @@ -52,6 +54,8 @@ function getPlatform(product, os, arch, type) {
return `server-alpine-${arch}`;
case 'web':
return `server-alpine-${arch}-web`;
case 'cli':
return `cli-alpine-${arch}`;
default:
throw new Error(`Unrecognized: ${product} ${os} ${arch} ${type}`);
}
Expand All @@ -74,6 +78,8 @@ function getPlatform(product, os, arch, type) {
return `linux-deb-${arch}`;
case 'rpm-package':
return `linux-rpm-${arch}`;
case 'cli':
return `cli-linux-${arch}`;
default:
throw new Error(`Unrecognized: ${product} ${os} ${arch} ${type}`);
}
Expand All @@ -94,6 +100,8 @@ function getPlatform(product, os, arch, type) {
return 'server-darwin-web';
}
return `server-darwin-${arch}-web`;
case 'cli':
return `cli-darwin-${arch}`;
default:
throw new Error(`Unrecognized: ${product} ${os} ${arch} ${type}`);
}
Expand Down
Loading

0 comments on commit 6353f80

Please sign in to comment.