Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions common/tools/dev-tool/ci-synth-spec-gen-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env node

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// this script reads a tspconfig.yaml file and synthesize a spec-gen-sdk-artifiact.json
// to pass to eng/common/scripts/Helpers/ApiView-Helpers.ps1 Create-API-Review

const process = require("process");
const path = require("path");
const fs = require("fs");
const yaml = require("yaml");

const tspconfigPath = process.argv[2];
if (!tspconfigPath) {
console.error("Please provide a path to tspconfig.yaml");
process.exit(1);
}
// if the path is not full path, resolve it related to current working directory
const resolvedTspconfigPath = path.isAbsolute(tspconfigPath)
? tspconfigPath
: path.normalize(path.join(process.cwd(), tspconfigPath));

if (!fs.existsSync(resolvedTspconfigPath)) {
console.error(`The file ${resolvedTspconfigPath} does not exist`);
process.exit(1);
}

const tspconfigContent = fs.readFileSync(tspconfigPath, "utf8");
const tspconfig = yaml.parse(tspconfigContent);

const tsEmitterOutputDir =
tspconfig["options"]?.["@azure-tools/typespec-ts"]?.["emitter-output-dir"];
if (!tsEmitterOutputDir) {
console.error(
"The tspconfig.yaml does not have @azure-tools/typespec-ts emitter-output-dir option",
);
process.exit(1);
}
const paramters = tspconfig.parameters;
const updatedTsEmitterOutputDir = tsEmitterOutputDir
.replace("{service-dir}", paramters["service-dir"]["default"])
.replace("{output-dir}/", "");
const jsRepoPath = path.normalize(path.join(process.argv[1], "../../../../"));
const packageJsonPath = path.join(jsRepoPath, updatedTsEmitterOutputDir, "package.json");
if (!fs.existsSync(packageJsonPath)) {
console.error(
`The resolved package directory ${jsRepoPath}/${updatedTsEmitterOutputDir} does not contains a package.json`,
);
process.exit(1);
}
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonContent);
const unscopedPackageName = packageJson.name.startsWith("@")
? packageJson.name.split("/")[1]
: packageJson.name;
const specGenArtifact = {
language: "azure-sdk-for-js",
apiViewRequestData: [
{
packageName: packageJson.name,
filePath: `${packageJson.name}/${unscopedPackageName}-node.api.json`,
},
],
};
console.log(JSON.stringify(specGenArtifact, null, 2));
105 changes: 105 additions & 0 deletions common/tools/dev-tool/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
parameters:
- name: SpecCommitId
type: string
default: 'main'
displayName: 'Spec commit id'
- name: TspConfigRelativePath
type: string
default: 'specification/widget/data-plane/WidgetAnalytics/tspconfig.yaml'
displayName: 'Relative path to tspconfig.yaml in spec repo'
trigger:
branches:
include:
Expand Down Expand Up @@ -57,3 +66,99 @@ jobs:
- script: |
pnpm --filter @azure/dev-tool... test
displayName: "Run dev-tool unit tests"

- job: 'SDKAutomation'
displayName: 'SDK Automation validation'

variables:
- template: /eng/pipelines/templates/variables/globals.yml
- template: /eng/pipelines/templates/variables/image.yml
- name: NodeVersion
value: $(NODE_VERSION_LTS_MAINTENANCE)
- name: PythonVersion
value: '3.13'

pool:
name: $(LINUXPOOL)
demands: ImageOverride -equals $(LINUXVMIMAGE)

steps:
- checkout: none

- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
parameters:
Paths:
- '/*'
- '!sdk/**/test-recordings/*'
- '!sdk/**/recordings/*'
- '!sdk/**/SessionRecords/*'
- '!sdk/**/session-records/*'
Repositories:
- Name: Azure/azure-rest-api-specs
Commitish: main
WorkingDirectory: $(System.DefaultWorkingDirectory)/azure-rest-api-specs
- Name: Azure/azure-sdk-for-js
Commitish: $(Build.SourceVersion)
WorkingDirectory: $(System.DefaultWorkingDirectory)/azure-sdk-for-js
SkipCheckoutNone: true

- task: NodeTool@0
inputs:
versionSpec: $(NodeVersion)
displayName: 'Install Node.js'

- task: UsePythonVersion@0
inputs:
versionSpec: $(PythonVersion)

- script: |
npm install -g pnpm
displayName: "Install Pnpm"

- script: |
pnpm install --prod --filter @azure/dev-tool
workingDirectory: $(System.DefaultWorkingDirectory)/azure-sdk-for-js
displayName: "Install library dependencies"

- script: |
cd $(System.DefaultWorkingDirectory)/azure-rest-api-specs

echo "##[group]Run npm ci"
npm ci
echo "##[endgroup]"

echo "##[group]Synthesize spec-gen-sdk-artifact.json"
echo "$(System.DefaultWorkingDirectory)/azure-sdk-for-js/common/tools/dev-tool/ci-synth-gen-artifacts.js ${{ parameters.TspConfigRelativePath }} > $(System.DefaultWorkingDirectory)/spec-gen-sdk-artifact.json"
$(System.DefaultWorkingDirectory)/azure-sdk-for-js/common/tools/dev-tool/ci-synth-spec-gen-artifacts.js ${{ parameters.TspConfigRelativePath }} > $(System.DefaultWorkingDirectory)/spec-gen-sdk-artifact.json
echo "##[endgroup]"

node $(System.DefaultWorkingDirectory)/azure-rest-api-specs/eng/tools/spec-gen-sdk-runner/cmd/spec-gen-sdk-runner.js \
--scp $(System.DefaultWorkingDirectory)/azure-rest-api-specs \
--sdp $(System.DefaultWorkingDirectory)/azure-sdk-for-js \
--wf $(System.DefaultWorkingDirectory) \
--lang azure-sdk-for-js \
--commit ${{ parameters.SpecCommitId }} \
--spec-repo-url https://github.com/Azure/azure-rest-api-specs \
--tsp-config-relative-path ${{ parameters.TspConfigRelativePath }} \
--sdk-release-type beta \
--rm local
displayName: 'Generate SDK'

- template: /eng/common/pipelines/templates/steps/publish-artifact.yml
parameters:
ArtifactName: $(PipelineArtifactsName)
ArtifactPath: $(StagedArtifactsFolder)
CustomCondition: and(succeededOrFailed(), ne(variables['StagedArtifactsFolder'], ''))

- ${{ if in(variables['Build.Reason'], 'PullRequest') }}:
- pwsh: |
. $(SpecRepoDirectory)/eng/common/scripts/Helpers/ApiView-Helpers.ps1
Create-API-Review `
-specGenSDKArtifactPath "$(System.DefaultWorkingDirectory)/spec-gen-sdk-artifact.json" `
-apiviewArtifactName "$(PipelineArtifactsName)" `
-buildId "$(Build.BuildId)" `
-commitish "$(System.PullRequest.SourceCommitId)" `
-repoName "Azure/azure-sdk-for-js" `
-pullRequestNumber "$(System.PullRequest.PullRequestNumber)"
displayName: 'Detect API Change and Create API Review'
condition: succeeded()
Loading