Skip to content

Commit

Permalink
Merge pull request #1392 from OfficeDev/nintan/validation-update
Browse files Browse the repository at this point in the history
fix: sample validation rule
  • Loading branch information
tecton authored Jan 7, 2025
2 parents 5feddee + bec16f0 commit 4215185
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-sample-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: |
# This script runs the validation tool against all samples in the samples-config-v3.json file.
# External samples are excluded from the validation.
exceptions=("incoming-webhook-notification")
exceptions=("incoming-webhook-notification" "hello-world-office-addin")
samples=`jq -r ".samples | .[] | select(has(\"downloadUrlInfo\") | not) | .id" .config/samples-config-v3.json`
validationFailed="validation failed"
validationResult=true
Expand Down
27 changes: 18 additions & 9 deletions validation-tool/src/validators/envValidator.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import dotenv from "dotenv";
import fs from "fs-extra";
import path from "path";
import dotenv from "dotenv";
import { Result } from "../resultType";

/**
* Rule 1: env files shouldn’t contain actual value for the environment variables except for TEAMSFX_ENV and TEAMS_APP_NAME
*
*
* @param projectDir root directory of the project
* @returns validation result
*/
export default async function validateEnvFiles(projectDir: string): Promise<Result> {
export default async function validateEnvFiles(
projectDir: string
): Promise<Result> {
const result: Result = {
name: "Env Files",
passed: [],
Expand All @@ -22,18 +24,25 @@ export default async function validateEnvFiles(projectDir: string): Promise<Resu
const files = [".env.dev", ".env.local"];
for (const envFile of files) {
const filePath = path.join(projectDir, "env", envFile);
if (!await fs.exists(filePath)) {
result.failed = [`${path.join("env", envFile)} does not exist.`];
if (!(await fs.exists(filePath))) {
result.warning = [`${path.join("env", envFile)} does not exist.`];
continue;
}
const fileContent = await fs.readFile(filePath, 'utf8');
const fileContent = await fs.readFile(filePath, "utf8");
const envData = dotenv.parse(fileContent);
const mappings = Object.entries(envData).map(([key, value]) => ({ name: key, value: value }));
const mappings = Object.entries(envData).map(([key, value]) => ({
name: key,
value: value,
}));
let validEnv = true;
for (const kv of mappings) {
if (kv.name === "TEAMSFX_ENV" || kv.name === "APP_NAME_SUFFIX" || kv.name === "TEAMS_APP_NAME") {
if (
kv.name === "TEAMSFX_ENV" ||
kv.name === "APP_NAME_SUFFIX" ||
kv.name === "TEAMS_APP_NAME"
) {
continue;
} else if (kv.value !== '') {
} else if (kv.value !== "") {
result.failed.push(`${envFile}: ${kv.name} should NOT have value.`);
validEnv = false;
}
Expand Down
26 changes: 17 additions & 9 deletions validation-tool/src/validators/folderStructureValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,46 @@ import path from "path";

import { Result } from "../resultType";

const requiredFolders = [
".vscode",
"appPackage",
"env",
];
const requiredFolders = [".vscode", "appPackage", "env"];
const requiredFiles = [
"appPackage/manifest.json",
"appPackage/color.png",
"appPackage/outline.png",
"env/.env.dev",
"env/.env.local",
// "env/.env.local",
"teamsapp.yml",
"teamsapp.local.yml",
"README.md",
];

export default async function validateFolderStructure(projectDir: string): Promise<Result> {
export default async function validateFolderStructure(
projectDir: string
): Promise<Result> {
const result: Result = {
name: "Folder Structure",
passed: [],
failed: [],
warning: [],
};
for (const folder of requiredFolders) {
if (!await fs.exists(path.join(projectDir, folder)) || !await fs.stat(path.join(projectDir, folder)).then(stat => stat.isDirectory())) {
if (
!(await fs.exists(path.join(projectDir, folder))) ||
!(await fs
.stat(path.join(projectDir, folder))
.then((stat) => stat.isDirectory()))
) {
result.failed.push(`Project should have "${folder}" folder.`);
} else {
result.passed.push(`Project has "${folder}" folder.`);
}
}
for (const file of requiredFiles) {
if (!await fs.exists(path.join(projectDir, file)) || !await fs.stat(path.join(projectDir, file)).then(stat => stat.isFile())) {
if (
!(await fs.exists(path.join(projectDir, file))) ||
!(await fs
.stat(path.join(projectDir, file))
.then((stat) => stat.isFile()))
) {
result.failed.push(`Project should have "${file}" file.`);
} else {
result.passed.push(`Project has "${file}" file.`);
Expand Down
Loading

0 comments on commit 4215185

Please sign in to comment.