Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ variables:
jobs:
- job: Android
pool:
vmImage: 'macOS-10.13'
vmImage: 'macOS-10.15'
steps:
- task: FlutterInstall@0
- task: FlutterBuild@0
Expand Down
Empty file modified publish.sh
100644 → 100755
Empty file.
43 changes: 27 additions & 16 deletions tasks/install/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const os = require("os");
const request = require("request-promise");
const task = require("vsts-task-lib/task");
const tool = require("vsts-task-tool-lib/tool");
const task = require("azure-pipelines-task-lib/task");
const tool = require("azure-pipelines-tool-lib/tool");
const FLUTTER_TOOL_NAME = 'Flutter';
const FLUTTER_EXE_RELATIVEPATH = 'flutter/bin';
const FLUTTER_TOOL_PATH_ENV_VAR = 'FlutterToolPath';
let storageHostType = 'china';
let storageHosts = {
'original': 'storage.googleapis.com',
'china': 'storage.flutter-io.cn',
};
function main() {
return __awaiter(this, void 0, void 0, function* () {
// 1. Getting current platform identifier
Expand All @@ -27,19 +33,24 @@ function main() {
if (version === 'latest' || semVer === "")
semVer = yield findLatestSdkVersion(channel, arch);
let versionSpec = `${semVer}-${channel}`;
const storageHostParam = task.getInput('storageHost', false);
console.log(`storageHostParam: ${storageHostParam}`);
if (storageHostParam === 'china') {
storageHostType = storageHostParam;
}
// 3. Check if already available
task.debug(`Trying to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
console.log(`Trying to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
let toolPath = tool.findLocalTool(FLUTTER_TOOL_NAME, versionSpec, arch);
if (!toolPath) {
// 4.1. Downloading SDK
yield downloadAndCacheSdk(versionSpec, channel, arch);
// 4.2. Verifying that tool is now available
task.debug(`Trying again to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
console.log(`Trying again to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
toolPath = tool.findLocalTool(FLUTTER_TOOL_NAME, versionSpec, arch);
}
// 5. Creating the environment variable
let fullFlutterPath = path.join(toolPath, FLUTTER_EXE_RELATIVEPATH);
task.debug(`Set ${FLUTTER_TOOL_PATH_ENV_VAR} with '${fullFlutterPath}'`);
console.log(`Set ${FLUTTER_TOOL_PATH_ENV_VAR} with '${fullFlutterPath}'`);
task.setVariable(FLUTTER_TOOL_PATH_ENV_VAR, fullFlutterPath);
task.setResult(task.TaskResult.Succeeded, "Installed");
});
Expand All @@ -54,29 +65,29 @@ function findArchitecture() {
function downloadAndCacheSdk(versionSpec, channel, arch) {
return __awaiter(this, void 0, void 0, function* () {
// 1. Download SDK archive
let downloadUrl = `https://storage.googleapis.com/flutter_infra/releases/${channel}/${arch}/flutter_${arch}_v${versionSpec}.zip`;
task.debug(`Starting download archive from '${downloadUrl}'`);
let downloadUrl = `https://${storageHosts[storageHostType]}/flutter_infra/releases/${channel}/${arch}/flutter_${arch}_${versionSpec}.zip`;
console.log(`Starting download archive from '${downloadUrl}'`);
var bundleZip = yield tool.downloadTool(downloadUrl);
task.debug(`Succeeded to download '${bundleZip}' archive from '${downloadUrl}'`);
console.log(`Succeeded to download '${bundleZip}' archive from '${downloadUrl}'`);
// 2. Extracting SDK bundle
task.debug(`Extracting '${downloadUrl}' archive`);
console.log(`Extracting '${downloadUrl}' archive`);
var bundleDir = yield tool.extractZip(bundleZip);
task.debug(`Extracted to '${bundleDir}' '${downloadUrl}' archive`);
console.log(`Extracted to '${bundleDir}' '${downloadUrl}' archive`);
// 3. Adding SDK bundle to cache
task.debug(`Adding '${bundleDir}' to cache (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch})`);
console.log(`Adding '${bundleDir}' to cache (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch})`);
tool.cacheDir(bundleDir, FLUTTER_TOOL_NAME, versionSpec, arch);
});
}
function findLatestSdkVersion(channel, arch) {
return __awaiter(this, void 0, void 0, function* () {
var releasesUrl = `https://storage.googleapis.com/flutter_infra/releases/releases_${arch}.json`;
task.debug(`Finding latest version from '${releasesUrl}'`);
var releasesUrl = `https://${storageHosts[storageHostType]}/flutter_infra/releases/releases_${arch}.json`;
console.log(`Finding latest version from '${releasesUrl}'`);
var body = yield request.get(releasesUrl);
var json = JSON.parse(body);
var currentHash = json.current_release[channel];
task.debug(`Last version hash '${currentHash}'`);
console.log(`Last version hash '${currentHash}'`);
var current = json.releases.find((item) => item.hash === currentHash);
return current.version.substring(1); // removing leading 'v'
return current.version;
});
}
main().catch(error => {
Expand Down
44 changes: 28 additions & 16 deletions tasks/install/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import * as path from 'path';
import * as os from 'os';
import * as request from 'request-promise';
import * as task from "vsts-task-lib/task";
import * as tool from 'vsts-task-tool-lib/tool';
import * as task from "azure-pipelines-task-lib/task";
import * as tool from 'azure-pipelines-tool-lib/tool';

const FLUTTER_TOOL_NAME: string = 'Flutter';
const FLUTTER_EXE_RELATIVEPATH = 'flutter/bin';
const FLUTTER_TOOL_PATH_ENV_VAR: string = 'FlutterToolPath';

type StorageHostType = 'original' | 'china';
let storageHostType: StorageHostType = 'china';
let storageHosts: { [key: string]: string } = {
'original': 'storage.googleapis.com',
'china': 'storage.flutter-io.cn', // https://flutter.dev/community/china
};

async function main(): Promise<void> {
// 1. Getting current platform identifier
let arch = findArchitecture();
Expand All @@ -19,23 +26,28 @@ async function main(): Promise<void> {
if (version === 'latest' || semVer === "")
semVer = await findLatestSdkVersion(channel, arch);
let versionSpec = `${semVer}-${channel}`;
const storageHostParam = task.getInput('storageHost', false) as StorageHostType;
console.log(`storageHostParam: ${storageHostParam}`);
if (storageHostParam === 'china') {
storageHostType = storageHostParam;
}

// 3. Check if already available
task.debug(`Trying to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
console.log(`Trying to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
let toolPath = tool.findLocalTool(FLUTTER_TOOL_NAME, versionSpec, arch);

if (!toolPath) {
// 4.1. Downloading SDK
await downloadAndCacheSdk(versionSpec, channel, arch);

// 4.2. Verifying that tool is now available
task.debug(`Trying again to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
console.log(`Trying again to get (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch}) tool from local cache`);
toolPath = tool.findLocalTool(FLUTTER_TOOL_NAME, versionSpec, arch);
}

// 5. Creating the environment variable
let fullFlutterPath: string = path.join(toolPath, FLUTTER_EXE_RELATIVEPATH);
task.debug(`Set ${FLUTTER_TOOL_PATH_ENV_VAR} with '${fullFlutterPath}'`);
console.log(`Set ${FLUTTER_TOOL_PATH_ENV_VAR} with '${fullFlutterPath}'`);
task.setVariable(FLUTTER_TOOL_PATH_ENV_VAR, fullFlutterPath);
task.setResult(task.TaskResult.Succeeded, "Installed");
}
Expand All @@ -50,32 +62,32 @@ function findArchitecture() {

async function downloadAndCacheSdk(versionSpec: string, channel: string, arch: string): Promise<void> {
// 1. Download SDK archive
let downloadUrl = `https://storage.googleapis.com/flutter_infra/releases/${channel}/${arch}/flutter_${arch}_v${versionSpec}.zip`;
task.debug(`Starting download archive from '${downloadUrl}'`);
let downloadUrl = `https://${storageHosts[storageHostType]}/flutter_infra/releases/${channel}/${arch}/flutter_${arch}_${versionSpec}.zip`;
console.log(`Starting download archive from '${downloadUrl}'`);
var bundleZip = await tool.downloadTool(downloadUrl);
task.debug(`Succeeded to download '${bundleZip}' archive from '${downloadUrl}'`);
console.log(`Succeeded to download '${bundleZip}' archive from '${downloadUrl}'`);

// 2. Extracting SDK bundle
task.debug(`Extracting '${downloadUrl}' archive`);
console.log(`Extracting '${downloadUrl}' archive`);
var bundleDir = await tool.extractZip(bundleZip);
task.debug(`Extracted to '${bundleDir}' '${downloadUrl}' archive`);
console.log(`Extracted to '${bundleDir}' '${downloadUrl}' archive`);

// 3. Adding SDK bundle to cache
task.debug(`Adding '${bundleDir}' to cache (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch})`);
console.log(`Adding '${bundleDir}' to cache (${FLUTTER_TOOL_NAME},${versionSpec}, ${arch})`);
tool.cacheDir(bundleDir, FLUTTER_TOOL_NAME, versionSpec, arch);
}

async function findLatestSdkVersion(channel: string, arch: string): Promise<string> {
var releasesUrl = `https://storage.googleapis.com/flutter_infra/releases/releases_${arch}.json`;
task.debug(`Finding latest version from '${releasesUrl}'`);
var releasesUrl = `https://${storageHosts[storageHostType]}/flutter_infra/releases/releases_${arch}.json`;
console.log(`Finding latest version from '${releasesUrl}'`);
var body = await request.get(releasesUrl);
var json = JSON.parse(body);
var currentHash = json.current_release[channel];
task.debug(`Last version hash '${currentHash}'`);
console.log(`Last version hash '${currentHash}'`);
var current = json.releases.find((item) => item.hash === currentHash);
return current.version.substring(1); // removing leading 'v'
return current.version;
}

main().catch(error => {
task.setResult(task.TaskResult.Failed, error);
});
});
Loading