Skip to content

Commit

Permalink
fix: ensure schema version is updated with YAML version (#13029)
Browse files Browse the repository at this point in the history
Co-authored-by: rentu <rentu>
  • Loading branch information
SLdragon authored Jan 9, 2025
1 parent 765cfa1 commit 561f1c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,13 @@ export class AadManifestHelper {
const version = document.get("version") as string;
if (version <= "v1.7") {
document.set("version", "v1.8");
const docContent = document.toString();
const updatedContent = docContent.replace(
/(yaml-language-server:\s*\$schema=https:\/\/aka\.ms\/teams-toolkit\/)v\d+\.\d+(\/yaml\.schema\.json)/,
"$1v1.8$2"
);
await fs.writeFile(ymlPath, updatedContent, "utf8");
}
await fs.writeFile(ymlPath, document.toString(), "utf8");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ describe("Microsoft Entra manifest helper Test", () => {
chai.assert.isTrue(writtenContent.includes(expectedTeamsAppYaml));
});

it("updateVersionForTeamsAppYamlFile should works fine when yaml contains schema url", async () => {
const teamsAppYaml = `# yaml-language-server: $schema=https://aka.ms/teams-toolkit/v1.7/yaml.schema.json
# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file
# Visit https://aka.ms/teamsfx-actions for details on actions
version: v1.7`;
const expectedTeamsAppYaml = `# yaml-language-server: $schema=https://aka.ms/teams-toolkit/v1.8/yaml.schema.json
# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file
# Visit https://aka.ms/teamsfx-actions for details on actions
version: v1.8`;

sinon.stub(fs, "pathExists").resolves(true);
sinon.stub(fs, "readFile").resolves(teamsAppYaml as any);
const writeFileStub = sinon.stub(fs, "writeFile");

await AadManifestHelper.updateVersionForTeamsAppYamlFile("fake-project-path");

const writtenContent = writeFileStub.getCall(0).args[1];
chai.assert.isTrue(writtenContent.includes(expectedTeamsAppYaml));
});

it("processRequiredResourceAccessInManifest with id", async () => {
const manifestWithId: any = {
requiredResourceAccess: [
Expand Down

0 comments on commit 561f1c5

Please sign in to comment.