Skip to content

Commit 79e1055

Browse files
author
Hanzhang Zeng (Roger)
committed
Release 1.1.7
1 parent 31d8bb8 commit 79e1055

File tree

3,392 files changed

+1208599
-337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,392 files changed

+1208599
-337
lines changed

.gitignore

+335-337
Large diffs are not rendered by default.

lib/constants/authentication_type.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.AuthenticationType = void 0;
4+
var AuthenticationType;
5+
(function (AuthenticationType) {
6+
AuthenticationType[AuthenticationType["Rbac"] = 1] = "Rbac";
7+
AuthenticationType[AuthenticationType["Scm"] = 2] = "Scm";
8+
})(AuthenticationType = exports.AuthenticationType || (exports.AuthenticationType = {}));

lib/constants/configuration.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.ConfigurationConstant = void 0;
4+
class ConfigurationConstant {
5+
}
6+
exports.ConfigurationConstant = ConfigurationConstant;
7+
ConfigurationConstant.ParamInAppName = 'app-name';
8+
ConfigurationConstant.ParamInPackagePath = 'package';
9+
ConfigurationConstant.ParamInSlot = 'slot-name';
10+
ConfigurationConstant.ParamInPublishProfile = 'publish-profile';
11+
ConfigurationConstant.ParamOutResultName = 'app-url';
12+
ConfigurationConstant.ActionName = 'DeployFunctionAppToAzure';
13+
ConfigurationConstant.BlobContainerName = 'github-actions-deploy';
14+
ConfigurationConstant.BlobNamePrefix = 'Functionapp';
15+
ConfigurationConstant.BlobServiceTimeoutMs = 3 * 1000;
16+
ConfigurationConstant.BlobUploadTimeoutMs = 30 * 60 * 1000;
17+
ConfigurationConstant.BlobUploadBlockSizeByte = 4 * 1024 * 1024;
18+
ConfigurationConstant.BlobUplaodBlockParallel = 4;
19+
ConfigurationConstant.BlobPermission = 'r';
20+
ConfigurationConstant.ProductionSlotName = 'production';

lib/constants/function_runtime.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.FunctionRuntimeUtil = exports.FunctionRuntimeConstant = void 0;
4+
const exceptions_1 = require("../exceptions");
5+
var FunctionRuntimeConstant;
6+
(function (FunctionRuntimeConstant) {
7+
FunctionRuntimeConstant[FunctionRuntimeConstant["None"] = 1] = "None";
8+
FunctionRuntimeConstant[FunctionRuntimeConstant["Dotnet"] = 2] = "Dotnet";
9+
FunctionRuntimeConstant[FunctionRuntimeConstant["Node"] = 3] = "Node";
10+
FunctionRuntimeConstant[FunctionRuntimeConstant["Powershell"] = 4] = "Powershell";
11+
FunctionRuntimeConstant[FunctionRuntimeConstant["Java"] = 5] = "Java";
12+
FunctionRuntimeConstant[FunctionRuntimeConstant["Python"] = 6] = "Python";
13+
})(FunctionRuntimeConstant = exports.FunctionRuntimeConstant || (exports.FunctionRuntimeConstant = {}));
14+
class FunctionRuntimeUtil {
15+
static FromString(language) {
16+
if (language === undefined) {
17+
return FunctionRuntimeConstant.None;
18+
}
19+
const key = language.charAt(0).toUpperCase() + language.toLowerCase().slice(1);
20+
const result = FunctionRuntimeConstant[key];
21+
if (result === undefined) {
22+
throw new exceptions_1.UnexpectedConversion('FunctionRuntimeConstant', language);
23+
}
24+
return result;
25+
}
26+
}
27+
exports.FunctionRuntimeUtil = FunctionRuntimeUtil;

lib/constants/function_sku.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.FunctionSkuUtil = exports.FunctionSkuConstant = void 0;
4+
var FunctionSkuConstant;
5+
(function (FunctionSkuConstant) {
6+
FunctionSkuConstant[FunctionSkuConstant["Consumption"] = 1] = "Consumption";
7+
FunctionSkuConstant[FunctionSkuConstant["Dedicated"] = 2] = "Dedicated";
8+
FunctionSkuConstant[FunctionSkuConstant["ElasticPremium"] = 3] = "ElasticPremium";
9+
})(FunctionSkuConstant = exports.FunctionSkuConstant || (exports.FunctionSkuConstant = {}));
10+
class FunctionSkuUtil {
11+
static FromString(sku) {
12+
const skuLowercasedString = sku.trim().toLowerCase();
13+
if (skuLowercasedString.startsWith('dynamic')) {
14+
return FunctionSkuConstant.Consumption;
15+
}
16+
if (skuLowercasedString.startsWith('elasticpremium')) {
17+
return FunctionSkuConstant.ElasticPremium;
18+
}
19+
return FunctionSkuConstant.Dedicated;
20+
}
21+
}
22+
exports.FunctionSkuUtil = FunctionSkuUtil;

lib/constants/publish_method.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.PublishMethodConstant = void 0;
4+
var PublishMethodConstant;
5+
(function (PublishMethodConstant) {
6+
// Using api/zipdeploy endpoint in scm site
7+
PublishMethodConstant[PublishMethodConstant["ZipDeploy"] = 1] = "ZipDeploy";
8+
// Setting WEBSITE_RUN_FROM_PACKAGE app setting
9+
PublishMethodConstant[PublishMethodConstant["WebsiteRunFromPackageDeploy"] = 2] = "WebsiteRunFromPackageDeploy";
10+
})(PublishMethodConstant = exports.PublishMethodConstant || (exports.PublishMethodConstant = {}));

lib/constants/runtime_stack.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.RuntimeStackUtil = exports.RuntimeStackConstant = void 0;
4+
const exceptions_1 = require("../exceptions");
5+
var RuntimeStackConstant;
6+
(function (RuntimeStackConstant) {
7+
RuntimeStackConstant[RuntimeStackConstant["Unknown"] = 0] = "Unknown";
8+
RuntimeStackConstant[RuntimeStackConstant["Windows"] = 1] = "Windows";
9+
RuntimeStackConstant[RuntimeStackConstant["Linux"] = 2] = "Linux";
10+
})(RuntimeStackConstant = exports.RuntimeStackConstant || (exports.RuntimeStackConstant = {}));
11+
class RuntimeStackUtil {
12+
static FromString(osType) {
13+
if (!osType) {
14+
return RuntimeStackConstant.Unknown;
15+
}
16+
const key = osType.charAt(0).toUpperCase() + osType.toLowerCase().slice(1);
17+
const result = RuntimeStackConstant[key];
18+
if (result === undefined) {
19+
throw new exceptions_1.UnexpectedConversion("RuntimeStackConstant", osType);
20+
}
21+
return result;
22+
}
23+
}
24+
exports.RuntimeStackUtil = RuntimeStackUtil;

lib/constants/state.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.StateConstant = void 0;
4+
var StateConstant;
5+
(function (StateConstant) {
6+
// State when initialize Github Action
7+
StateConstant[StateConstant["Initialize"] = 1] = "Initialize";
8+
// Get & Check the parameter from action.yml
9+
StateConstant[StateConstant["ValidateParameter"] = 2] = "ValidateParameter";
10+
// Get & Check if the resources does exist
11+
StateConstant[StateConstant["ValidateAzureResource"] = 3] = "ValidateAzureResource";
12+
// Zip content and choose the proper deployment method
13+
StateConstant[StateConstant["PreparePublishContent"] = 4] = "PreparePublishContent";
14+
// Publish content to Azure Functionapps
15+
StateConstant[StateConstant["PublishContent"] = 5] = "PublishContent";
16+
// Validate if the content has been published successfully
17+
StateConstant[StateConstant["ValidatePublishedContent"] = 6] = "ValidatePublishedContent";
18+
// End state with success
19+
StateConstant[StateConstant["Succeeded"] = 7] = "Succeeded";
20+
// End state with failure
21+
StateConstant[StateConstant["Failed"] = 8] = "Failed";
22+
})(StateConstant = exports.StateConstant || (exports.StateConstant = {}));

lib/exceptions.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
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;
4+
const state_1 = require("./constants/state");
5+
class BaseException extends Error {
6+
constructor(message = undefined, innerException = undefined) {
7+
super();
8+
this._innerException = innerException ? innerException : undefined;
9+
this.message = message ? message : "";
10+
}
11+
GetInnerException() {
12+
return this._innerException;
13+
}
14+
GetTraceback() {
15+
let errorMessages = [this.message];
16+
let innerException = this._innerException;
17+
while (innerException !== undefined && innerException instanceof BaseException) {
18+
errorMessages.push(innerException.message);
19+
innerException = innerException._innerException;
20+
}
21+
if (innerException !== undefined && innerException instanceof Error) {
22+
errorMessages.push(innerException.message);
23+
errorMessages.push(innerException.stack);
24+
}
25+
else if (innerException !== undefined) {
26+
errorMessages.push(String(innerException));
27+
}
28+
return errorMessages;
29+
}
30+
PrintTraceback(printer) {
31+
const traceback = this.GetTraceback();
32+
for (let i = 0; i < traceback.length; i++) {
33+
const prefix = " ".repeat(i * 2);
34+
printer(`${prefix}${traceback[i]}`);
35+
}
36+
}
37+
}
38+
exports.BaseException = BaseException;
39+
class NotImplementedException extends BaseException {
40+
}
41+
exports.NotImplementedException = NotImplementedException;
42+
class UnexpectedExitException extends BaseException {
43+
constructor(state = state_1.StateConstant.Failed) {
44+
super(state_1.StateConstant[state]);
45+
}
46+
}
47+
exports.UnexpectedExitException = UnexpectedExitException;
48+
class UnexpectedConversion extends BaseException {
49+
constructor(constantField, value) {
50+
super(`Failed to convert ${value} to ${constantField}`);
51+
}
52+
}
53+
exports.UnexpectedConversion = UnexpectedConversion;
54+
class ExecutionException extends BaseException {
55+
constructor(state, executionStage, innerException) {
56+
let errorMessage = `Execution Exception (state: ${state_1.StateConstant[state]})`;
57+
if (executionStage !== undefined) {
58+
errorMessage += ` (step: ${executionStage})`;
59+
}
60+
super(errorMessage, innerException);
61+
}
62+
}
63+
exports.ExecutionException = ExecutionException;
64+
class InvocationException extends ExecutionException {
65+
constructor(state, innerException) {
66+
super(state, "Invocation", innerException);
67+
}
68+
}
69+
exports.InvocationException = InvocationException;
70+
class ChangeParamsException extends ExecutionException {
71+
constructor(state, innerException) {
72+
super(state, "ChangeParams", innerException);
73+
}
74+
}
75+
exports.ChangeParamsException = ChangeParamsException;
76+
class ChangeContextException extends ExecutionException {
77+
constructor(state, innerException) {
78+
super(state, "ChangeContext", innerException);
79+
}
80+
}
81+
exports.ChangeContextException = ChangeContextException;
82+
class ValidationError extends BaseException {
83+
constructor(state, field, expectation, innerException) {
84+
super(`At ${state_1.StateConstant[state]}, ${field} : ${expectation}.`, innerException);
85+
}
86+
}
87+
exports.ValidationError = ValidationError;
88+
class FileIOError extends BaseException {
89+
constructor(state, action, message, innerException) {
90+
super(`When performing file operation at ${state_1.StateConstant[state]}, ${action} : ${message}`, innerException);
91+
}
92+
}
93+
exports.FileIOError = FileIOError;
94+
class WebRequestError extends BaseException {
95+
constructor(url, verb, message, innerException) {
96+
super(`When [${verb}] ${url}, error: ${message}`, innerException);
97+
}
98+
}
99+
exports.WebRequestError = WebRequestError;
100+
class AzureResourceError extends BaseException {
101+
constructor(state, action, message, innerException) {
102+
super(`When request Azure resource at ${state_1.StateConstant[state]}, ${action} : ${message}`, innerException);
103+
}
104+
}
105+
exports.AzureResourceError = AzureResourceError;

lib/handlers/contentPreparer.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
exports.ContentPreparer = void 0;
13+
const utility_js_1 = require("azure-actions-utility/utility.js");
14+
const ziputility_js_1 = require("azure-actions-utility/ziputility.js");
15+
const packageUtility_1 = require("azure-actions-utility/packageUtility");
16+
const state_1 = require("../constants/state");
17+
const exceptions_1 = require("../exceptions");
18+
const publish_method_1 = require("../constants/publish_method");
19+
const function_sku_1 = require("../constants/function_sku");
20+
const runtime_stack_1 = require("../constants/runtime_stack");
21+
const utils_1 = require("../utils");
22+
const authentication_type_1 = require("../constants/authentication_type");
23+
class ContentPreparer {
24+
invoke(state, params, context) {
25+
return __awaiter(this, void 0, void 0, function* () {
26+
this.validatePackageType(state, context.package);
27+
this._packageType = context.package.getPackageType();
28+
this._publishContentPath = yield this.generatePublishContent(state, params.packagePath, this._packageType);
29+
this._publishMethod = this.derivePublishMethod(state, this._packageType, context.os, context.sku, context.authenticationType);
30+
try {
31+
yield context.kuduServiceUtil.warmpUp();
32+
}
33+
catch (expt) {
34+
throw new exceptions_1.AzureResourceError(state, "Warmup", `Failed to warmup ${params.appName}`, expt);
35+
}
36+
return state_1.StateConstant.PublishContent;
37+
});
38+
}
39+
changeContext(_0, _1, context) {
40+
return __awaiter(this, void 0, void 0, function* () {
41+
context.packageType = this._packageType;
42+
context.publishContentPath = this._publishContentPath;
43+
context.publishMethod = this._publishMethod;
44+
return context;
45+
});
46+
}
47+
validatePackageType(state, pkg) {
48+
const packageType = pkg.getPackageType();
49+
switch (packageType) {
50+
case packageUtility_1.PackageType.zip:
51+
case packageUtility_1.PackageType.folder:
52+
break;
53+
default:
54+
throw new exceptions_1.ValidationError(state, "validatePackageType", "only accepts zip or folder");
55+
}
56+
}
57+
generatePublishContent(state, packagePath, packageType) {
58+
return __awaiter(this, void 0, void 0, function* () {
59+
switch (packageType) {
60+
case packageUtility_1.PackageType.zip:
61+
utils_1.Logger.Log(`Will directly deploy ${packagePath} as function app content`);
62+
return packagePath;
63+
case packageUtility_1.PackageType.folder:
64+
const tempoaryFilePath = utility_js_1.generateTemporaryFolderOrZipPath(process.env.RUNNER_TEMP, false);
65+
utils_1.Logger.Log(`Will archive ${packagePath} into ${tempoaryFilePath} as function app content`);
66+
try {
67+
return yield ziputility_js_1.archiveFolder(packagePath, "", tempoaryFilePath);
68+
}
69+
catch (expt) {
70+
throw new exceptions_1.FileIOError(state, "Generate Publish Content", `Failed to archive ${packagePath}`, expt);
71+
}
72+
default:
73+
throw new exceptions_1.ValidationError(state, "Generate Publish Content", "only accepts zip or folder");
74+
}
75+
});
76+
}
77+
derivePublishMethod(state, packageType, osType, sku, authenticationType) {
78+
// Uses api/zipdeploy endpoint if scm credential is provided
79+
if (authenticationType == authentication_type_1.AuthenticationType.Scm) {
80+
utils_1.Logger.Log('Will use api/zipdeploy to deploy (scm credential)');
81+
return publish_method_1.PublishMethodConstant.ZipDeploy;
82+
}
83+
// Linux Consumption sets WEBSITE_RUN_FROM_PACKAGE app settings when scm credential is not available
84+
if (osType === runtime_stack_1.RuntimeStackConstant.Linux && sku === function_sku_1.FunctionSkuConstant.Consumption) {
85+
utils_1.Logger.Log('Will use WEBSITE_RUN_FROM_PACKAGE to deploy');
86+
return publish_method_1.PublishMethodConstant.WebsiteRunFromPackageDeploy;
87+
}
88+
// Rest Skus which support api/zipdeploy endpoint
89+
switch (packageType) {
90+
case packageUtility_1.PackageType.zip:
91+
case packageUtility_1.PackageType.folder:
92+
utils_1.Logger.Log('Will use api/zipdeploy to deploy (rbac authentication)');
93+
return publish_method_1.PublishMethodConstant.ZipDeploy;
94+
default:
95+
throw new exceptions_1.ValidationError(state, "Derive Publish Method", "only accepts zip or folder");
96+
}
97+
}
98+
}
99+
exports.ContentPreparer = ContentPreparer;

lib/handlers/contentPublisher.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
exports.ContentPublisher = void 0;
13+
const state_1 = require("../constants/state");
14+
const publish_method_1 = require("../constants/publish_method");
15+
const exceptions_1 = require("../exceptions");
16+
const publishers_1 = require("../publishers");
17+
class ContentPublisher {
18+
invoke(state, _1, context) {
19+
return __awaiter(this, void 0, void 0, function* () {
20+
switch (context.publishMethod) {
21+
case publish_method_1.PublishMethodConstant.ZipDeploy:
22+
yield publishers_1.ZipDeploy.execute(state, context);
23+
break;
24+
case publish_method_1.PublishMethodConstant.WebsiteRunFromPackageDeploy:
25+
yield publishers_1.WebsiteRunFromPackageDeploy.execute(state, context);
26+
break;
27+
default:
28+
throw new exceptions_1.ValidationError(state, "publisher", "can only performs ZipDeploy and WebsiteRunFromPackageDeploy");
29+
}
30+
return state_1.StateConstant.ValidatePublishedContent;
31+
});
32+
}
33+
}
34+
exports.ContentPublisher = ContentPublisher;

0 commit comments

Comments
 (0)