Skip to content

Commit eb123b1

Browse files
authored
[StaticWebAppsV0] Stable Staging Environment inputs for Static Web Apps (#15981)
* Added working directory * Added task inputs for Stable Staging Environments * Update input help text * Update task.json * Updated Branch detection to accommodate Classic Releases in addition to Build Pipelines
1 parent 52c0b1e commit eb123b1

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

Tasks/AzureStaticWebAppV0/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const routesLocationInputName = 'routes_location';
1212
const buildTimeoutInMinutesInputName = 'build_timeout_in_minutes';
1313
const configFileLocationInputName = 'config_file_location';
1414
const apiTokenInputName = 'azure_static_web_apps_api_token';
15+
const deploymentEnvironmentInputName = 'deployment_environment';
16+
const productionBranchInputName = 'production_branch';
1517

1618
async function run() {
1719
const envVarFilePath: string = path.join(__dirname, 'env.list');
@@ -33,7 +35,7 @@ async function run() {
3335
bash.line(tl.getInput('args', false));
3436

3537
await createDockerEnvVarFile(envVarFilePath);
36-
38+
3739
const options = {
3840
failOnStdErr: false
3941
};
@@ -59,9 +61,9 @@ async function createDockerEnvVarFile(envVarFilePath: string) {
5961
systemVariableNames.add(envVarName)
6062
}
6163

62-
const addInputStringToString = (envVarName: string, envVarValue: string, inputName: string, ) => {
64+
const addInputStringToString = (envVarName: string, envVarValue: string, inputName: string,) => {
6365
if (envVarValue.includes("\n")) {
64-
throw "Input "+inputName+" is a multiline string and cannot be added to the build environment.";
66+
throw "Input " + inputName + " is a multiline string and cannot be added to the build environment.";
6567
}
6668

6769
addSystemVariableToString(envVarName, envVarValue)
@@ -76,6 +78,8 @@ async function createDockerEnvVarFile(envVarFilePath: string) {
7678
const routesLocation: string = tl.getInput(routesLocationInputName, false) || "";
7779
const buildTimeoutInMinutes: string = tl.getInput(buildTimeoutInMinutesInputName, false) || "";
7880
const configFileLocation: string = tl.getInput(configFileLocationInputName, false) || "";
81+
const deploymentEnvironment: string = tl.getInput(deploymentEnvironmentInputName, false) || "";
82+
const productionBranch: string = tl.getInput(productionBranchInputName, false) || "";
7983

8084
const skipAppBuild: boolean = tl.getBoolInput('skip_app_build', false);
8185
const skipApiBuild: boolean = tl.getBoolInput('skip_api_build', false);
@@ -97,6 +101,8 @@ async function createDockerEnvVarFile(envVarFilePath: string) {
97101
addInputStringToString("ROUTES_LOCATION", routesLocation, routesLocationInputName);
98102
addInputStringToString("BUILD_TIMEOUT_IN_MINUTES", buildTimeoutInMinutes, buildTimeoutInMinutesInputName);
99103
addInputStringToString("CONFIG_FILE_LOCATION", configFileLocation, configFileLocationInputName);
104+
addInputStringToString("DEPLOYMENT_ENVIRONMENT", deploymentEnvironment, deploymentEnvironmentInputName);
105+
addInputStringToString("PRODUCTION_BRANCH", productionBranch, productionBranchInputName);
100106

101107
addSystemVariableToString("SKIP_APP_BUILD", skipAppBuild.toString());
102108
addSystemVariableToString("SKIP_API_BUILD", skipApiBuild.toString());
@@ -114,17 +120,17 @@ async function createDockerEnvVarFile(envVarFilePath: string) {
114120
addSystemVariableToString("IS_PULL_REQUEST", "");
115121
addSystemVariableToString("BASE_BRANCH", "");
116122
addSystemVariableToString("REPOSITORY_BASE", containerWorkingDir);
117-
addSystemVariableToString("BRANCH", process.env.BUILD_SOURCEBRANCHNAME || "");
123+
addSystemVariableToString("BRANCH", process.env.BUILD_SOURCEBRANCHNAME || process.env.BUILD_SOURCEBRANCH || "");
118124
addSystemVariableToString("DEPLOYMENT_ACTION", "upload");
119125

120126
const denylistString = await fs.promises.readFile(path.join(__dirname, 'envVarDenylist.json'), 'utf8');
121127
const denylist = JSON.parse(denylistString);
122128

123-
Object.keys(process.env).forEach( (envVarKey: string) => {
129+
Object.keys(process.env).forEach((envVarKey: string) => {
124130
const envVarValue = process.env[envVarKey];
125131

126132
if (envVarValue.includes("\n")) {
127-
tl.warning("Environment variable "+envVarKey+" is a multiline string and cannot be added to the build environment.");
133+
tl.warning("Environment variable " + envVarKey + " is a multiline string and cannot be added to the build environment.");
128134
return;
129135
}
130136

@@ -133,23 +139,23 @@ async function createDockerEnvVarFile(envVarFilePath: string) {
133139
return;
134140
}
135141

136-
if(!denylist.includes(envVarKey.toUpperCase())) {
142+
if (!denylist.includes(envVarKey.toUpperCase())) {
137143
addVariableToString(envVarKey, envVarValue);
138144
}
139145
});
140146

141147
await fs.promises.writeFile(envVarFilePath, variableString);
142148
}
143149

144-
function getNullableBooleanFromString(boolString:string): boolean {
150+
function getNullableBooleanFromString(boolString: string): boolean {
145151
if (boolString == null) return null;
146152
boolString = boolString.toLowerCase();
147153

148-
if(boolString === "true") {
154+
if (boolString === "true") {
149155
return true;
150156
}
151157

152-
if(boolString === "false") {
158+
if (boolString === "false") {
153159
return false;
154160
}
155161

Tasks/AzureStaticWebAppV0/task.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@
128128
"defaultValue": "",
129129
"required": false,
130130
"helpMarkDown": "Api token for deployment. Not required if passed as an environment variable"
131+
},
132+
{
133+
"name": "deployment_environment",
134+
"type": "string",
135+
"label": "Deployment Environment",
136+
"defaultValue": "",
137+
"required": false,
138+
"helpMarkDown": "Environment to deploy to. Leave blank for production environment. Takes precedence over Production Branch"
139+
},
140+
{
141+
"name": "production_branch",
142+
"type": "string",
143+
"label": "Production Branch",
144+
"defaultValue": "",
145+
"required": false,
146+
"helpMarkDown": "Production branch. When specified and Deployment Environment is empty, deployments from other branches will be preview environments"
131147
}
132148
],
133149
"execution": {

0 commit comments

Comments
 (0)