Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions tools/sdk-automation-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib/
node_modules/
package-deps.json
.env
.vscode
21 changes: 21 additions & 0 deletions tools/sdk-automation-core/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
14 changes: 14 additions & 0 deletions tools/sdk-automation-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
104 changes: 104 additions & 0 deletions tools/sdk-automation-core/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
trigger:
- master

pool:
name: AzurePipelines-EO
demands:
- ImageOverride -equals AzurePipelinesUbuntu20.04compliant

variables:
DOCKER_BUILDKIT: 1

jobs:
- job: Build_Verfication
steps:
- task: npmAuthenticate@0
inputs:
workingFile: .npmrc

- script: cp .npmrc .npmrc-registry
displayName: Disable .npmrc-registry

- script: sed -i -E 's/"version":\s*"([0-9\.]+)",/"version":"\1.$(Build.BuildNumber)",/' package.json
displayName: Set version in package.json

- task: Docker@2
displayName: Build Image
inputs:
command: build
repository: openapi/sdk-automation
tags: $(Build.BuildNumber)
Dockerfile: ./Dockerfile
containerRegistry: openapi_test_docker_connection
arguments: --build-arg UBUNTU_MIRROR=$(UBUNTU_MIRROR)

- task: Docker@2
displayName: Push Image
condition: notIn(variables['Build.Reason'], 'PullRequest')
inputs:
command: push
repository: openapi/sdk-automation
containerRegistry: openapi_test_docker_connection
tags: $(Build.BuildNumber)

- task: ComponentGovernanceComponentDetection@0
displayName: Dependencies Compliance Analysis
inputs:
verbosity: Verbose
snapshotForceEnabled: true
useDefaultDetectors: false
detectorsToRun: Npm

- job: Integration_Test
variables:
SDK_REPO_NAME: PLACEHOLDER
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'

- task: npmAuthenticate@0
inputs:
workingFile: .npmrc

- script: npm ci
displayName: NPM Install

- script: |
git config --global user.email "[email protected]"
git config --global user.name "SDK Automation"
rm .npmrc

npm config set audit false
sudo npm install -g npm@latest

sudo apt update
sudo apt install python3-setuptools python3-venv
/usr/bin/python3 -m venv work/pyenv
node ./node_modules/.bin/autorest --typescript

TEST_RUN_ID=`node -e "console.log(Math.random().toString(36).substring(2, 8))"`
echo "##vso[task.setvariable variable=TEST_RUN_ID]$TEST_RUN_ID"
echo "TEST_RUN_ID=$TEST_RUN_ID"
displayName: Init

- script: |
source work/pyenv/bin/activate
npm run test-ci
displayName: Integration Test
timeoutInMinutes: 30
env:
SPEC_REPO: $(spec-repo)
GITHUB_COMMENT_AUTHOR_NAME: $(github.amrom.workers.devment-author-name)
GITHUBAPP_ID: $(githubapp-id)
GITHUBAPP_PRIVATE_KEY: $(githubapp-private-key)

- script: |
[ -z $TEST_RUN_ID ] || npm run clear-github-test-repos
displayName: Clean Up
condition: always()
env:
SPEC_REPO: $(spec-repo)
GITHUB_COMMENT_AUTHOR_NAME: $(github.amrom.workers.devment-author-name)
GITHUBAPP_ID: $(githubapp-id)
GITHUBAPP_PRIVATE_KEY: $(githubapp-private-key)
10 changes: 10 additions & 0 deletions tools/sdk-automation-core/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import globals from "globals";
import tseslint from "typescript-eslint";


export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: globals.node }},
...tseslint.configs.recommended,
];
Binary file added tools/sdk-automation-core/images/failed.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/sdk-automation-core/images/inProgress.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/sdk-automation-core/images/pending.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/sdk-automation-core/images/succeeded.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/sdk-automation-core/images/warning.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions tools/sdk-automation-core/integrationTest/clearGithubTestRepos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getTestGithubClient, repoOwner } from './utils';
import { sdkAutomationCliConfig } from '../src/cli/config';
import { Octokit, RestEndpointMethodTypes } from '@octokit/rest';

type ReposListForOrgResponse = RestEndpointMethodTypes['repos']['listForOrg']['response']['data']

const cleanGithubTestRepos = async () => {
const github = await getTestGithubClient();
const reposRsp: ReposListForOrgResponse = await github.paginate(github.repos.listForOrg.endpoint.merge({
org: repoOwner
}));

const runId = sdkAutomationCliConfig.testRunId;
const prefixToMatch = runId ? `test-${runId}` : 'test';

let repos = reposRsp.map(repo => repo.name);
console.log(`Repos in ${repoOwner}:`);
console.log(repos.join('\n'));

console.log(`\nFilter: ${prefixToMatch}`);
repos = repos.filter(name => name.startsWith(prefixToMatch));
console.log(`Repos after filter:`);
console.log(repos.join('\n'));

const parallelCount = 4;
const promises: Promise<void>[] = [];
for (let i = 0; i < parallelCount; ++i) {
promises.push(cleanReposWorker(github, repos));
}
await Promise.all(promises);
};

const cleanReposWorker = async (github: Octokit, repos: string[]) => {
while (repos.length > 0) {
const repoName = repos.shift() as string;
console.log(`Cleaning up ${repoOwner}/${repoName}`);
try {
await github.repos.delete({ owner: repoOwner, repo: repoName });
} catch (e) {
console.log(`Failed to delete ${repoOwner}/${repoName}: ${e.message} ${e.stack}`);
}
}
};

// tslint:disable-next-line: no-floating-promises
cleanGithubTestRepos();
26 changes: 26 additions & 0 deletions tools/sdk-automation-core/integrationTest/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const fixtures = {
specTest: {
name: 'spec-test',
patch0_AddService: 'spec-test-patch0-add-service',
patch1_Add_02_01: 'spec-test-patch1-add-02-01', // Depends on patch0
patch2_Empty: 'spec-test-patch2-empty-update', // Depends on patch0
patch3_TwoReadme: 'spec-test-patch3-two-readme'
},
sdkGo: {
name: 'sdk-go-test'
},
sdkJs: {
name: 'sdk-js-test',
patch0_AddServiceGen: 'sdk-js-test-patch0-add-service-gen' // CodeGen result after spec patch0
},
sdkPy: {
name: 'sdk-py-test',
patch0_Track2: 'sdk-py-test-patch0-track2' // Track2 config
},
sdkTf: {
name: 'sdk-tf-test'
},
schmARM: {
name: 'schm-arm-test'
}
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schemas/code-model-v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://openapistorageprod.blob.core.windows.net/sdkautomation/prod/schemas/swagger_to_sdk_config.schema.json",
"meta": {
"autorest_options": {
"use": "@autorest/[email protected]",
"azureresourceschema": "",
"multiapi": "",
"sdkrel:azureresourceschema-folder": ".",
"title": "none",
"pass-thru:subset-reducer": ""
},
"advanced_options": {
"create_sdk_pull_requests": true,
"sdk_generation_pull_request_base": "integration_branch"
},
"version": "0.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
# *.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
*.zip

# Editor swap files
*.swp
*~
.DS_Store
.vscode

# ignore vendor/
vendor/
Loading