Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #905 from microsoft/update-azure-pipeline-to-master
Browse files Browse the repository at this point in the history
Move from travis ci to azure pipeline in master branch
  • Loading branch information
dilin-MS2 authored Jan 9, 2020
2 parents 244cbca + 81485eb commit e657fe9
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 89 deletions.
140 changes: 96 additions & 44 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,119 @@
trigger:
- master
jobs:
- job: Windows
pool:
name: Hosted VS2017
demands: npm
steps:
branches:
include:
- master
- develop
tags:
include:
- v*

strategy:
matrix:
linux:
imageName: "ubuntu-16.04"
mac:
imageName: "macos-10.13"
windows:
imageName: "vs2017-win2016"

pool:
vmImage: $(imageName)
demands: npm

variables:
nightly_build_id: iotdevexbuild.test-owl-project-nightly
rc_id: iotdevexbuild.test-owl-project

steps:

- task: UseNode@1
displayName: 'Install node version >=12.0.0'
inputs:
version: '>=12.0.0'

- task: Npm@1
displayName: 'Install dependencies'
inputs:
verbose: false

- script: node node_modules/gts/build/src/cli.js check
displayName: 'check gts error'
failOnStderr: True

- task: Npm@1
displayName: 'Compile sources'
inputs:
command: custom
verbose: false
customCommand: 'run compile'

- bash: |
is_prod_tag=^refs\/tags\/v?[0-9]+\.[0-9]+\.[0-9]+$
is_test_tag=^refs\/tags\/v?[0-9]+\.[0-9]+\.[0-9]+-[rR][cC]
[[ $BUILD_SOURCEBRANCH =~ $is_prod_tag ]] && is_prod=true
[[ $BUILD_SOURCEBRANCH =~ $is_test_tag ]] && is_test=true
[[ $BUILD_SOURCEBRANCH =~ $is_prod_tag || $BUILD_SOURCEBRANCH =~ $is_test_tag || "$BUILD_REASON" == "Schedule" ]] && deploy_to_marketplace=true
# Set job variable
echo "##vso[task.setvariable variable=is_prod]$is_prod"
echo "##vso[task.setvariable variable=is_test]$is_test"
echo "##vso[task.setvariable variable=deploy_to_marketplace]$deploy_to_marketplace"
displayName: 'Define runtime variable'
- script: npm install -g vsce
displayName: 'install vsce'
- script: gts check
displayName: 'check gts error'
failOnStderr: True
- script: node updateDynamicResourceLink.js
displayName: 'Update link for code generator'
condition: and(succeeded(), eq(variables['deploy_to_marketplace'], 'true'))

- script: node scripts/updateConfig.js
displayName: 'Update configuration'
condition: and(succeeded(), eq(variables['deploy_to_marketplace'], 'true'))

- script: vsce package
displayName: 'Build VSIX package'
condition: and(succeeded(), eq(variables['deploy_to_marketplace'], 'true'))

- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: |
**\*.vsix
**/*.vsix
TargetFolder: '$(Build.ArtifactStagingDirectory)'
condition: and(succeeded(), eq(variables['deploy_to_marketplace'], 'true'))

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop1
- job: macOS
pool:
name: Hosted macOS
demands: npm
steps:
- task: Npm@1
displayName: 'Install dependencies'
inputs:
verbose: false
- task: Npm@1
displayName: 'Compile sources'
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: $(Agent.OS)-drop
condition: and(succeeded(), eq(variables['deploy_to_marketplace'], 'true'))

- task: GitHubRelease@0
displayName: 'Deploy production or RC candidate to GitHub Release'
inputs:
command: custom
verbose: false
customCommand: 'run compile'
- job: Linux
pool:
name: Hosted Ubuntu 1604
demands: npm
steps:
- task: Npm@1
displayName: 'Install dependencies'
inputs:
verbose: false
- task: Npm@1
displayName: 'Compile sources'
inputs:
command: custom
verbose: false
customCommand: 'run compile'
gitHubConnection: 'pat_for_github_release_deployment'
repositoryName: '$(Build.Repository.Name)'
action: 'create'
target: '$(Build.SourceVersion)'
isPreRelease: $(is_test)
condition: and(succeeded(), eq(variables['deploy_to_marketplace'], 'true'), ne(variables['Build.reason'], 'Schedule'), eq(variables['Agent.OS'], 'Linux'))

- bash: vsce publish -p $MARKETPLACE_TOKEN --packagePath *.vsix
workingDirectory: '$(Build.ArtifactStagingDirectory)'
displayName: 'Deploy production candidate to marketplace'
condition: and(succeeded(), eq(variables['is_prod'], 'true'), eq(variables['Agent.OS'], 'Linux'))
env:
MARKETPLACE_TOKEN: $(vsciot_marketplace_token)

- bash: yes | vsce unpublish -p $MARKETPLACE_TOKEN $(rc_id) && vsce publish -p $MARKETPLACE_TOKEN --packagePath *.vsix
workingDirectory: '$(Build.ArtifactStagingDirectory)'
displayName: 'Deploy RC candidate to marketplace'
condition: and(succeeded(), eq(variables['is_test'], 'true'), eq(variables['Agent.OS'], 'Linux'))
env:
MARKETPLACE_TOKEN: $(iotdevexbuild_marketplace_token)

- bash: yes | vsce unpublish -p $MARKETPLACE_TOKEN $(nightly_build_id) && vsce publish -p $MARKETPLACE_TOKEN --packagePath *.vsix
workingDirectory: '$(Build.ArtifactStagingDirectory)'
displayName: 'Deploy nightly build candidate to marketplace'
condition: and(succeeded(), eq(variables['Build.reason'], 'Schedule'), eq(variables['Agent.OS'], 'Linux'))
env:
MARKETPLACE_TOKEN: $(iotdevexbuild_marketplace_token)
82 changes: 37 additions & 45 deletions scripts/updateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,62 @@ const fs = require('fs');
* TRAVIS_TAG =~ /^v?[0-9]+\.[0-9]+\.[0-9]+$/: Production release (eg. v0.10.18)
* TRAVIS_TAG =~ /^v?[0-9]+\.[0-9]+\.[0-9]+-[rR][cC]/: RC release (eg. v0.10.18-rc, v0.10.18-rc2, etc.)
*/
if (process.env.TRAVIS_EVENT_TYPE === "cron" || process.env.TRAVIS_TAG) {
const packageJson = JSON.parse(fs.readFileSync('package.json'));
const packageJson = JSON.parse(fs.readFileSync('package.json'));

// Nightly Build
if (process.env.TRAVIS_EVENT_TYPE === "cron") {
const nightlyBuildName = "test-owl-project-nightly";
const nightlyBuildDisplayName = "Test OWL Project (Nightly)";
const nightlyBuildPublisher = "IoTDevExBuild";
modifyPackageJsonForNonProduction(packageJson, nightlyBuildName, nightlyBuildDisplayName, nightlyBuildPublisher);
} else if (process.env.TRAVIS_TAG) {
const isProduction = /^v?[0-9]+\.[0-9]+\.[0-9]+$/.test(process.env.TRAVIS_TAG || '');
const isTestVersion = /^v?[0-9]+\.[0-9]+\.[0-9]+-[rR][cC]/.test(process.env.TRAVIS_TAG || '');
// Nightly Build
if (process.env.BUILD_REASON === "Schedule") {
const nightlyBuildName = "test-owl-project-nightly";
const nightlyBuildDisplayName = "Test OWL Project (Nightly)";
updateConfigForNonProduction(packageJson, nightlyBuildName, nightlyBuildDisplayName);
} else if (process.env.IS_PROD) {
// Update resource link
const codeGenUrl = "https://aka.ms/iot-codegen-cli-for-workbench";
packageJson.codeGenConfigUrl = codeGenUrl;

if (isProduction) {
// Update resource link
const codeGenUrl = "https://aka.ms/iot-codegen-cli-for-workbench";
packageJson.codeGenConfigUrl = codeGenUrl;

// Update production AI Key
packageJson.aiKey = process.env['PROD_AIKEY'];
} else if (isTestVersion) {
const testName = "test-owl-project";
const testDisplayName = "Test OWL Project RC";
const testPublisher = "IoTDevExBuild";
modifyPackageJsonForNonProduction(packageJson, testName, testDisplayName, testPublisher);

// Modify extensionId in template files
const extensionIdPattern = /vsciot-vscode.vscode-iot-workbench/g;
const rcExtensionId = 'iotdevexbuild.test-owl-project';

const arm7DevcontainerJsonFile = "resources/templates/arm7/devcontainer.json";
const arm8DevcontainerJsonFile = "resources/templates/arm8/devcontainer.json";
const x86DevcontainerJsonFile = "resources/templates/x86/devcontainer.json";
const files = [arm7DevcontainerJsonFile, arm8DevcontainerJsonFile, x86DevcontainerJsonFile];
files.forEach(filePath => {
const originalJsonFile = fs.readFileSync(filePath).toString();
const replaceJson = originalJsonFile.replace(extensionIdPattern, rcExtensionId);
fs.writeFileSync(filePath, replaceJson);
});
}
}

fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2) + '\n');
// Update production AI Key
packageJson.aiKey = process.env.PROD_AIKEY;
} else if (process.env.IS_TEST) {
const testName = "test-owl-project";
const testDisplayName = "Test OWL Project RC";
updateConfigForNonProduction(packageJson, testName, testDisplayName);
}

fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2) + '\n');

/**
* Update package.json with test name, displayName, publisher, ai aky.
* Trim version number. Delete extension icon.
* Update extension id in template files.
* @param {*} packageJson package json oject
* @param {*} testName test extension name
* @param {*} testDisplayName test extension displate name
* @param {*} testPublisher test publisher
*/
function modifyPackageJsonForNonProduction(packageJson, testName, testDisplayName, testPublisher) {
function updateConfigForNonProduction(packageJson, testName, testDisplayName) {
// Update package.json
packageJson.name = testName;
packageJson.displayName = testDisplayName;
packageJson.publisher = testPublisher;
packageJson.publisher = "IoTDevExBuild";

packageJson.aiKey = process.env['TEST_AIKEY'];
packageJson.aiKey = process.env.TEST_AIKEY;

const indexOfDash = packageJson.version.indexOf('-');
if (indexOfDash > 0) {
packageJson.version = packageJson.version.substring(0, indexOfDash);
}

delete packageJson.icon;

// Modify extensionId in template files
const extensionIdPattern = /vsciot-vscode.vscode-iot-workbench/g;
const testExtensionId = 'iotdevexbuild.' + testName;

const arm7DevcontainerJsonFile = "resources/templates/arm7/devcontainer.json";
const arm8DevcontainerJsonFile = "resources/templates/arm8/devcontainer.json";
const x86DevcontainerJsonFile = "resources/templates/x86/devcontainer.json";
const files = [arm7DevcontainerJsonFile, arm8DevcontainerJsonFile, x86DevcontainerJsonFile];
files.forEach(filePath => {
const originalJsonFile = fs.readFileSync(filePath).toString();
const replaceJson = originalJsonFile.replace(extensionIdPattern, testExtensionId.toLowerCase());
fs.writeFileSync(filePath, replaceJson);
});
}

0 comments on commit e657fe9

Please sign in to comment.