Skip to content

Commit

Permalink
Release 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanzhang Zeng (Roger) committed Nov 14, 2020
1 parent 31d8bb8 commit 79e1055
Show file tree
Hide file tree
Showing 3,392 changed files with 1,208,599 additions and 337 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
672 changes: 335 additions & 337 deletions .gitignore

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lib/constants/authentication_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationType = void 0;
var AuthenticationType;
(function (AuthenticationType) {
AuthenticationType[AuthenticationType["Rbac"] = 1] = "Rbac";
AuthenticationType[AuthenticationType["Scm"] = 2] = "Scm";
})(AuthenticationType = exports.AuthenticationType || (exports.AuthenticationType = {}));
20 changes: 20 additions & 0 deletions lib/constants/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigurationConstant = void 0;
class ConfigurationConstant {
}
exports.ConfigurationConstant = ConfigurationConstant;
ConfigurationConstant.ParamInAppName = 'app-name';
ConfigurationConstant.ParamInPackagePath = 'package';
ConfigurationConstant.ParamInSlot = 'slot-name';
ConfigurationConstant.ParamInPublishProfile = 'publish-profile';
ConfigurationConstant.ParamOutResultName = 'app-url';
ConfigurationConstant.ActionName = 'DeployFunctionAppToAzure';
ConfigurationConstant.BlobContainerName = 'github-actions-deploy';
ConfigurationConstant.BlobNamePrefix = 'Functionapp';
ConfigurationConstant.BlobServiceTimeoutMs = 3 * 1000;
ConfigurationConstant.BlobUploadTimeoutMs = 30 * 60 * 1000;
ConfigurationConstant.BlobUploadBlockSizeByte = 4 * 1024 * 1024;
ConfigurationConstant.BlobUplaodBlockParallel = 4;
ConfigurationConstant.BlobPermission = 'r';
ConfigurationConstant.ProductionSlotName = 'production';
27 changes: 27 additions & 0 deletions lib/constants/function_runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionRuntimeUtil = exports.FunctionRuntimeConstant = void 0;
const exceptions_1 = require("../exceptions");
var FunctionRuntimeConstant;
(function (FunctionRuntimeConstant) {
FunctionRuntimeConstant[FunctionRuntimeConstant["None"] = 1] = "None";
FunctionRuntimeConstant[FunctionRuntimeConstant["Dotnet"] = 2] = "Dotnet";
FunctionRuntimeConstant[FunctionRuntimeConstant["Node"] = 3] = "Node";
FunctionRuntimeConstant[FunctionRuntimeConstant["Powershell"] = 4] = "Powershell";
FunctionRuntimeConstant[FunctionRuntimeConstant["Java"] = 5] = "Java";
FunctionRuntimeConstant[FunctionRuntimeConstant["Python"] = 6] = "Python";
})(FunctionRuntimeConstant = exports.FunctionRuntimeConstant || (exports.FunctionRuntimeConstant = {}));
class FunctionRuntimeUtil {
static FromString(language) {
if (language === undefined) {
return FunctionRuntimeConstant.None;
}
const key = language.charAt(0).toUpperCase() + language.toLowerCase().slice(1);
const result = FunctionRuntimeConstant[key];
if (result === undefined) {
throw new exceptions_1.UnexpectedConversion('FunctionRuntimeConstant', language);
}
return result;
}
}
exports.FunctionRuntimeUtil = FunctionRuntimeUtil;
22 changes: 22 additions & 0 deletions lib/constants/function_sku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionSkuUtil = exports.FunctionSkuConstant = void 0;
var FunctionSkuConstant;
(function (FunctionSkuConstant) {
FunctionSkuConstant[FunctionSkuConstant["Consumption"] = 1] = "Consumption";
FunctionSkuConstant[FunctionSkuConstant["Dedicated"] = 2] = "Dedicated";
FunctionSkuConstant[FunctionSkuConstant["ElasticPremium"] = 3] = "ElasticPremium";
})(FunctionSkuConstant = exports.FunctionSkuConstant || (exports.FunctionSkuConstant = {}));
class FunctionSkuUtil {
static FromString(sku) {
const skuLowercasedString = sku.trim().toLowerCase();
if (skuLowercasedString.startsWith('dynamic')) {
return FunctionSkuConstant.Consumption;
}
if (skuLowercasedString.startsWith('elasticpremium')) {
return FunctionSkuConstant.ElasticPremium;
}
return FunctionSkuConstant.Dedicated;
}
}
exports.FunctionSkuUtil = FunctionSkuUtil;
10 changes: 10 additions & 0 deletions lib/constants/publish_method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublishMethodConstant = void 0;
var PublishMethodConstant;
(function (PublishMethodConstant) {
// Using api/zipdeploy endpoint in scm site
PublishMethodConstant[PublishMethodConstant["ZipDeploy"] = 1] = "ZipDeploy";
// Setting WEBSITE_RUN_FROM_PACKAGE app setting
PublishMethodConstant[PublishMethodConstant["WebsiteRunFromPackageDeploy"] = 2] = "WebsiteRunFromPackageDeploy";
})(PublishMethodConstant = exports.PublishMethodConstant || (exports.PublishMethodConstant = {}));
24 changes: 24 additions & 0 deletions lib/constants/runtime_stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuntimeStackUtil = exports.RuntimeStackConstant = void 0;
const exceptions_1 = require("../exceptions");
var RuntimeStackConstant;
(function (RuntimeStackConstant) {
RuntimeStackConstant[RuntimeStackConstant["Unknown"] = 0] = "Unknown";
RuntimeStackConstant[RuntimeStackConstant["Windows"] = 1] = "Windows";
RuntimeStackConstant[RuntimeStackConstant["Linux"] = 2] = "Linux";
})(RuntimeStackConstant = exports.RuntimeStackConstant || (exports.RuntimeStackConstant = {}));
class RuntimeStackUtil {
static FromString(osType) {
if (!osType) {
return RuntimeStackConstant.Unknown;
}
const key = osType.charAt(0).toUpperCase() + osType.toLowerCase().slice(1);
const result = RuntimeStackConstant[key];
if (result === undefined) {
throw new exceptions_1.UnexpectedConversion("RuntimeStackConstant", osType);
}
return result;
}
}
exports.RuntimeStackUtil = RuntimeStackUtil;
22 changes: 22 additions & 0 deletions lib/constants/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StateConstant = void 0;
var StateConstant;
(function (StateConstant) {
// State when initialize Github Action
StateConstant[StateConstant["Initialize"] = 1] = "Initialize";
// Get & Check the parameter from action.yml
StateConstant[StateConstant["ValidateParameter"] = 2] = "ValidateParameter";
// Get & Check if the resources does exist
StateConstant[StateConstant["ValidateAzureResource"] = 3] = "ValidateAzureResource";
// Zip content and choose the proper deployment method
StateConstant[StateConstant["PreparePublishContent"] = 4] = "PreparePublishContent";
// Publish content to Azure Functionapps
StateConstant[StateConstant["PublishContent"] = 5] = "PublishContent";
// Validate if the content has been published successfully
StateConstant[StateConstant["ValidatePublishedContent"] = 6] = "ValidatePublishedContent";
// End state with success
StateConstant[StateConstant["Succeeded"] = 7] = "Succeeded";
// End state with failure
StateConstant[StateConstant["Failed"] = 8] = "Failed";
})(StateConstant = exports.StateConstant || (exports.StateConstant = {}));
105 changes: 105 additions & 0 deletions lib/exceptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AzureResourceError = exports.WebRequestError = exports.FileIOError = exports.ValidationError = exports.ChangeContextException = exports.ChangeParamsException = exports.InvocationException = exports.ExecutionException = exports.UnexpectedConversion = exports.UnexpectedExitException = exports.NotImplementedException = exports.BaseException = void 0;
const state_1 = require("./constants/state");
class BaseException extends Error {
constructor(message = undefined, innerException = undefined) {
super();
this._innerException = innerException ? innerException : undefined;
this.message = message ? message : "";
}
GetInnerException() {
return this._innerException;
}
GetTraceback() {
let errorMessages = [this.message];
let innerException = this._innerException;
while (innerException !== undefined && innerException instanceof BaseException) {
errorMessages.push(innerException.message);
innerException = innerException._innerException;
}
if (innerException !== undefined && innerException instanceof Error) {
errorMessages.push(innerException.message);
errorMessages.push(innerException.stack);
}
else if (innerException !== undefined) {
errorMessages.push(String(innerException));
}
return errorMessages;
}
PrintTraceback(printer) {
const traceback = this.GetTraceback();
for (let i = 0; i < traceback.length; i++) {
const prefix = " ".repeat(i * 2);
printer(`${prefix}${traceback[i]}`);
}
}
}
exports.BaseException = BaseException;
class NotImplementedException extends BaseException {
}
exports.NotImplementedException = NotImplementedException;
class UnexpectedExitException extends BaseException {
constructor(state = state_1.StateConstant.Failed) {
super(state_1.StateConstant[state]);
}
}
exports.UnexpectedExitException = UnexpectedExitException;
class UnexpectedConversion extends BaseException {
constructor(constantField, value) {
super(`Failed to convert ${value} to ${constantField}`);
}
}
exports.UnexpectedConversion = UnexpectedConversion;
class ExecutionException extends BaseException {
constructor(state, executionStage, innerException) {
let errorMessage = `Execution Exception (state: ${state_1.StateConstant[state]})`;
if (executionStage !== undefined) {
errorMessage += ` (step: ${executionStage})`;
}
super(errorMessage, innerException);
}
}
exports.ExecutionException = ExecutionException;
class InvocationException extends ExecutionException {
constructor(state, innerException) {
super(state, "Invocation", innerException);
}
}
exports.InvocationException = InvocationException;
class ChangeParamsException extends ExecutionException {
constructor(state, innerException) {
super(state, "ChangeParams", innerException);
}
}
exports.ChangeParamsException = ChangeParamsException;
class ChangeContextException extends ExecutionException {
constructor(state, innerException) {
super(state, "ChangeContext", innerException);
}
}
exports.ChangeContextException = ChangeContextException;
class ValidationError extends BaseException {
constructor(state, field, expectation, innerException) {
super(`At ${state_1.StateConstant[state]}, ${field} : ${expectation}.`, innerException);
}
}
exports.ValidationError = ValidationError;
class FileIOError extends BaseException {
constructor(state, action, message, innerException) {
super(`When performing file operation at ${state_1.StateConstant[state]}, ${action} : ${message}`, innerException);
}
}
exports.FileIOError = FileIOError;
class WebRequestError extends BaseException {
constructor(url, verb, message, innerException) {
super(`When [${verb}] ${url}, error: ${message}`, innerException);
}
}
exports.WebRequestError = WebRequestError;
class AzureResourceError extends BaseException {
constructor(state, action, message, innerException) {
super(`When request Azure resource at ${state_1.StateConstant[state]}, ${action} : ${message}`, innerException);
}
}
exports.AzureResourceError = AzureResourceError;
99 changes: 99 additions & 0 deletions lib/handlers/contentPreparer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentPreparer = void 0;
const utility_js_1 = require("azure-actions-utility/utility.js");
const ziputility_js_1 = require("azure-actions-utility/ziputility.js");
const packageUtility_1 = require("azure-actions-utility/packageUtility");
const state_1 = require("../constants/state");
const exceptions_1 = require("../exceptions");
const publish_method_1 = require("../constants/publish_method");
const function_sku_1 = require("../constants/function_sku");
const runtime_stack_1 = require("../constants/runtime_stack");
const utils_1 = require("../utils");
const authentication_type_1 = require("../constants/authentication_type");
class ContentPreparer {
invoke(state, params, context) {
return __awaiter(this, void 0, void 0, function* () {
this.validatePackageType(state, context.package);
this._packageType = context.package.getPackageType();
this._publishContentPath = yield this.generatePublishContent(state, params.packagePath, this._packageType);
this._publishMethod = this.derivePublishMethod(state, this._packageType, context.os, context.sku, context.authenticationType);
try {
yield context.kuduServiceUtil.warmpUp();
}
catch (expt) {
throw new exceptions_1.AzureResourceError(state, "Warmup", `Failed to warmup ${params.appName}`, expt);
}
return state_1.StateConstant.PublishContent;
});
}
changeContext(_0, _1, context) {
return __awaiter(this, void 0, void 0, function* () {
context.packageType = this._packageType;
context.publishContentPath = this._publishContentPath;
context.publishMethod = this._publishMethod;
return context;
});
}
validatePackageType(state, pkg) {
const packageType = pkg.getPackageType();
switch (packageType) {
case packageUtility_1.PackageType.zip:
case packageUtility_1.PackageType.folder:
break;
default:
throw new exceptions_1.ValidationError(state, "validatePackageType", "only accepts zip or folder");
}
}
generatePublishContent(state, packagePath, packageType) {
return __awaiter(this, void 0, void 0, function* () {
switch (packageType) {
case packageUtility_1.PackageType.zip:
utils_1.Logger.Log(`Will directly deploy ${packagePath} as function app content`);
return packagePath;
case packageUtility_1.PackageType.folder:
const tempoaryFilePath = utility_js_1.generateTemporaryFolderOrZipPath(process.env.RUNNER_TEMP, false);
utils_1.Logger.Log(`Will archive ${packagePath} into ${tempoaryFilePath} as function app content`);
try {
return yield ziputility_js_1.archiveFolder(packagePath, "", tempoaryFilePath);
}
catch (expt) {
throw new exceptions_1.FileIOError(state, "Generate Publish Content", `Failed to archive ${packagePath}`, expt);
}
default:
throw new exceptions_1.ValidationError(state, "Generate Publish Content", "only accepts zip or folder");
}
});
}
derivePublishMethod(state, packageType, osType, sku, authenticationType) {
// Uses api/zipdeploy endpoint if scm credential is provided
if (authenticationType == authentication_type_1.AuthenticationType.Scm) {
utils_1.Logger.Log('Will use api/zipdeploy to deploy (scm credential)');
return publish_method_1.PublishMethodConstant.ZipDeploy;
}
// Linux Consumption sets WEBSITE_RUN_FROM_PACKAGE app settings when scm credential is not available
if (osType === runtime_stack_1.RuntimeStackConstant.Linux && sku === function_sku_1.FunctionSkuConstant.Consumption) {
utils_1.Logger.Log('Will use WEBSITE_RUN_FROM_PACKAGE to deploy');
return publish_method_1.PublishMethodConstant.WebsiteRunFromPackageDeploy;
}
// Rest Skus which support api/zipdeploy endpoint
switch (packageType) {
case packageUtility_1.PackageType.zip:
case packageUtility_1.PackageType.folder:
utils_1.Logger.Log('Will use api/zipdeploy to deploy (rbac authentication)');
return publish_method_1.PublishMethodConstant.ZipDeploy;
default:
throw new exceptions_1.ValidationError(state, "Derive Publish Method", "only accepts zip or folder");
}
}
}
exports.ContentPreparer = ContentPreparer;
34 changes: 34 additions & 0 deletions lib/handlers/contentPublisher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentPublisher = void 0;
const state_1 = require("../constants/state");
const publish_method_1 = require("../constants/publish_method");
const exceptions_1 = require("../exceptions");
const publishers_1 = require("../publishers");
class ContentPublisher {
invoke(state, _1, context) {
return __awaiter(this, void 0, void 0, function* () {
switch (context.publishMethod) {
case publish_method_1.PublishMethodConstant.ZipDeploy:
yield publishers_1.ZipDeploy.execute(state, context);
break;
case publish_method_1.PublishMethodConstant.WebsiteRunFromPackageDeploy:
yield publishers_1.WebsiteRunFromPackageDeploy.execute(state, context);
break;
default:
throw new exceptions_1.ValidationError(state, "publisher", "can only performs ZipDeploy and WebsiteRunFromPackageDeploy");
}
return state_1.StateConstant.ValidatePublishedContent;
});
}
}
exports.ContentPublisher = ContentPublisher;
Loading

0 comments on commit 79e1055

Please sign in to comment.