azure-rest-api-specs/documentation/sdkautomation
Ray Chen fe44d3261f
Update sdk-suppressions.md (#31190)
* Update sdk-suppressions.md

Add more details about the suppression file location for TypeSpec scenarios and OpenAPI scenarios.

* Update documentation/sdkautomation/sdk-suppressions.md

fix typo

Co-authored-by: Mariana Rios Flores <mariari@microsoft.com>

---------

Co-authored-by: Mariana Rios Flores <mariari@microsoft.com>
2024-10-23 15:13:07 -07:00
..
GenerateInputSchema.json Updated sdk automation docs (#23345) 2023-04-03 09:50:25 +08:00
GenerateOutputSchema.json Update GenerateOutputSchema.json (#29865) 2024-07-22 10:36:38 +08:00
InitOutputSchema.json SDK Automation Doc Update (#11422) 2020-11-11 16:52:54 +08:00
InstallInstructionScriptInputSchema.json Update sdk automation document (#29553) 2024-06-24 17:54:53 +08:00
InstallInstructionScriptOutputSchema.json chore: Add prettier overrides for other JSON files (#12604) 2021-02-05 13:46:12 +08:00
README.md Update sdk automation document (#29553) 2024-06-24 17:54:53 +08:00
SpecConfigSchema.json chore: Add prettier overrides for other JSON files (#12604) 2021-02-05 13:46:12 +08:00
SwaggerToSdkConfigSchema.json Update sdk automation document (#29553) 2024-06-24 17:54:53 +08:00
sdk-automation-faq.md Update sdk-automation-faq.md (#30883) 2024-10-16 14:10:09 -07:00
sdk-suppressions.md Update sdk-suppressions.md (#31190) 2024-10-23 15:13:07 -07:00

README.md

SDK Automation Customization

This is the specification of the new SDK Automation customization configuration. Old customization that hardcoded in sdk automation will still work but this new approach is preferred.

SDK Automation workflow

Opened PR Validation Trigger

SDK Automation is launched with matrix in azure pipeline. For each language configured:

  1. Get the PR merge commit and clone the spec repo on the merge commit.

  2. Get the PR changed file list. For each changed file, find the nearest readme.md in parent folder. Get list of related readme.md.

  3. Filter which sdk will be generated:

    1. For Swagger PR, filter the list of readme.md with: find the swagger-to-sdk section in the readme.md, and see if the specified language is configured for that readme.md. Example of swagger-to-sdk in SDK Automation:
      ```yaml $(swagger-to-sdk)
      swagger-to-sdk:
        - repo: azure-sdk-for-python
        - repo: azure-sdk-for-java
        - repo: azure-sdk-for-go
        - repo: azure-sdk-for-js
      ``` <EOL>
      
    2. For TypeSpec PR, filter the list of tspconfig.yaml: find the options config in tspconfig.yaml, and see if the specified language emitter is configured.

    If the specific language is not configured here, generation for this typespec project will be skipped.

  4. Get specificationRepositoryConfiguration.json from spec repo default branch. See SpecRepoConfig. Get the repo and branch config in the file.

  5. Clone mainRepository and checkout mainBranch. If secondaryRepository is specified then checkout secondaryRepository and secondaryBranch instead.

  6. Get swagger_to_sdk_config.json from cloned SDK repository. The config file path could be customized by configFilePath in spec config. For the definition of the config see SwaggerToSdkConfig.

  7. Launch initScript defined in SwaggerToSdkConfig. All the script's working directory is root folder of cloned SDK repository.

  8. Calculate PR diff and related readme.md. If generationCallMode is one-for-all-configs then run one pass for the rest steps, else (one-per-config) loop the rest steps with each readme.md.

  9. Launch generateScript defined in SwaggerToSdkConfig with generateInput.json. The script should produce generateOutput.json if parseGenerateOutput is true. If dryRun is set to true then first run of generateScript will be used to collect package information , then loop each package info and checkout package related branch and launch generateScript with package related readmeMd and dryRun set to false.

  10. Get generated package. If packageFolderFromFileSearch is defined with file search then package folder is detected based on git diff in SDK repository and algorithm described in SwaggerToSdkConfig Schema. Else package folder is from generateOutput.json. For each package loop the rest steps.

  11. Launch buildScript to build the package. Collect the artifacts by config artifactPathFromFileSearch. This step could be skipped if it's not defined in SwaggerToSdkConfig and it's covered by generateScript and the result could be found in generateOutput.json.

  12. Launch changelogScript to get changelog and detect breaking change. This step could be skipped if changelog and breaking change could be found in generateOutput.json. If breaking change is found, the spec PR will be labelled with BreakingChange-<Lang>-Sdk.

  13. Launch installInstructionScript to get install instruction for that package. This step could be skipped if install instruction could be found in generateOutput.json. The lite install instruction will be shown in spec PR comment, the full install instruction will be shown in generated SDK PR.

  14. Commit the package related code in SDK repository. Force push to GenerationBranch in integrationRepository. Create or update GenerationPR from GenerationBranch to MainBranch in integrationRepository. If integrationRepository is a fork of mainRepository, its MainBranch should be synced once a day.

Continuous Integration (PR Merged) Trigger

Almost the same as opened PR trigger, with different on step 14:

  1. Commit the package related code in SDK repository. Close GenerationPR and delete GenerationBranch. Force push to IntegrationBranch in integrationRepository. Create or update IntegrationPR from IntegrationBranch to MainBranch in mainRepository. Close the integrationPR if closeIntegrationPR in SwaggerToSdkConfig is set to true.

Definitions

SpecRepoConfig

This is type of file ./specificationRepositoryConfiguration.json in swagger spec repo.

SpecRepoConfig Example

{
  "sdkRepositoryMappings": {
    "azure-sdk-for-js": {
      "integrationRepository": "AzureSDKAutomation/azure-sdk-for-js",
      "mainRepository": "Azure/azure-sdk-for-js"
    },
    "azure-sdk-for-python": {
      "integrationRepository": "AzureSDKAutomation/azure-sdk-for-python",
      "mainRepository": "Azure/azure-sdk-for-python",
      "mainBranch": "release/v3"
    }
  },
  "overrides": {
    "Azure/azure-rest-api-specs-pr": {
      "sdkRepositoryMappings": {
        "azure-sdk-for-js": {
          "integrationRepository": "azure-sdk/azure-sdk-for-js-pr",
          "mainRepository": "Azure/azure-sdk-for-js-pr"
        },
        "azure-sdk-for-python": {
          "integrationRepository": "azure-sdk/azure-sdk-for-python-pr",
          "mainRepository": "Azure/azure-sdk-for-python-pr",
          "mainBranch": "release/v3"
        }
      }
    }
  }
}

SpecRepoConfig Schema

See ./SpecConfigSchema.json

SwaggerToSdkConfig

This is type of file ./swagger_to_sdk_config.json in sdk repo. The running environment of these scripts would be expected to be Ubuntu 18.04 on Azure Pipeline. This may change in the future. All the running script should be executable. The working folder of all the scripts is the root folder of sdk repo.

SwaggerToSdkConfig Example

{
  "advancedOptions": {
    "createSdkPullRequests": true,
    "generationCallMode": "one-for-all-configs"
  },
  "initOptions": {
    "initScript": {
      // Script to init dependencies.
      // Param: <path_to_initInput.json> <path_to_initOutput.json>
      // initInput.json: Not implemented. Placeholder for input arguments.
      // initOutput.json: See #initOutput.
      "path": "./eng/tools/sdk_init"
    }
  },
  "generateOptions": {
    // Param: <path_to_generateInput.json> <path_to_generateOutput.json>
    // generateInput.json: See #GenerateInput .
    // generateOutput.json: See #GenerateOutput .
    "generateScript": {
      "path": "./eng/tools/sdk_generate",
      "stderr": {
        "showInComment": true
      },
      "stdout": {
        // Show logs start with "[Autorest]" in PR comment.
        "showInComment": "^\\[Autorest\\]"
      }
    },

    "parseGenerateOutput": true
  },
  "packageOptions": {
    // Param: <path_to_package_folder>
    "buildScript": {
      "path": "./eng/tools/sdk_package",
      "stderr": {
        // Everything in stderr will show in comment and mark package with warning.
        "showInComment": true,
        "scriptWarning": true
      },
      "exitCode": {
        // If exit code is not zero, mark package with warning instead of error.
        "result": "warning"
      }
    },
    
    // Param: <path_to_package_folder>
    "changelogScript": {
      "path": "./eng/tools/sdk_breaking_change",
      "breakingChangeDetect": "Breaking Change"
    },

    "breakingChangesLabel": "BreakingChange-DotNet-Sdk"
  },
  "artifactOptions": {
    // Param: <path_to_installInstructionInput.json> <path_to_installInstructionOutput.json>
    // installInstructionInput.json: See #InstallInstructionScriptInput .
    // installInstructionOutput.json: See #InstallInstructionScriptOutput .
    "installInstructionScript": {
      "path": "./eng/tools/sdk_install_instruction"
    }
  }
}

SwaggerToSdkConfig Schema

See ./SwaggerToSdkConfigSchema.json

GenerateInput

Input file for generate script.

GenerateInput Example

{
  "dryRun": false,
  "specFolder": "/z/work/azure-rest-api-specs",
  "headSha": "fce3400431eff281bddd04bed9727e63765b8da0",
  "headRef": "refs/pull/1234/merge",
  "repoHttpsUrl": "https://github.com/Azure/azure-rest-api-specs.git",
  "trigger": "pull_request",
  "changedFiles": [
    "specification/cdn/something/cdn.json"
  ],
  "relatedReadmeMdFiles": [
    "specification/cdn/something/readme.md"
  ],
  "installInstructionInput": {
    "isPublic": false,
    "downloadCommandTemplate": "curl -L \"{URL}\" -o {FILENAME}",
    "trigger": "pullRequest"
  }
}

GenerateInput Schema

See ./GenerateInputSchema.json

GenerateOutput

Output file for generate script.

GenerateOutput Example

{
  "packages": [
    {
      "packageName": "Microsoft.Cdn",
      "path": [
        "sdk/cdn"
      ],
      "readmeMd": [
        "specification/cdn/something/readme.md"
      ],
      "changelog": {
        "content": "Feature: something \n Breaking Changes: something\n",
        "hasBreakingChange": true
      },
      "artifacts": [
        "sdk/cdn/cdn.nuget",
        "sdk/cdn/cdn.snuget"
      ],
      "installInstructions": {
        "full": "To install something...",
        "lite": "dotnet something"
      },
      "result": "succeeded"
    }
  ]
}

GenerateOutput Schema

See ./GenerateOutputSchema.json

InstallInstructionScriptInput

Input of install instruction script.

InstallInstructionScriptInput Example

{
  "packageName": "Microsoft.Cdn",
  "artifacts": [
    "sdk/cdn/cdn.nuget",
    "sdk/cdn/cdn.snuget"
  ],
  "isPublic": true,
  "downloadCommandTemplate": "curl -L \"{URL}\" -o {FILENAME}",
  "trigger": "pullRequest",
}

InstallInstructionScriptInput Schema

See ./InstallInstructionScriptInput.json

InstallInstructionScriptOutput

Output of install instruction script.

InstallInstructionScriptOutput Example

{
  "full": "To install something...",
}

InstallInstructionScriptOutput Schema

See ./InstallInstructionScriptOutput.json

TriggerType

TriggerType Schema

{
  // How this generation is triggered.
  "$id": "TriggerType",
  "type": "string",
  "enum": ["pullRequest", "continuousIntegration"]
}

InitOutput

InitOutput Schema

{
  "type": "object",
  "properties": {
    "envs": {
      // Environment variable to be set in following scripts.
      "additionalProperties": {
        "type": "string"
      }
    }
  }
}