Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/add-assets-…
Browse files Browse the repository at this point in the history
…tooling
  • Loading branch information
scbedd committed Jun 5, 2023
2 parents e16ac14 + fbd523b commit 2d3d182
Show file tree
Hide file tree
Showing 50 changed files with 20,340 additions and 91 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/event-processor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ jobs:

- name: Process Action Event
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
# This is a temporary secret generated by github
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
30 changes: 18 additions & 12 deletions .github/workflows/scheduled-event-processor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,59 +64,65 @@ jobs:
- name: Close Stale Issues Scheduled Event
if: github.event.schedule == '0 1 * * *'
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json CloseStaleIssues
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Identify Stale PullRequests Scheduled Event
if: github.event.schedule == '0 5 * * FRI'
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json IdentifyStalePullRequests
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Close Stale PullRequests Scheduled Event
if: github.event.schedule == '30 2,8,14,20 * * *'
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json CloseStalePullRequests
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Identify Stale Issues Scheduled Event
if: github.event.schedule == '30 3,9,15,21 * * *'
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json IdentifyStaleIssues
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Close Addressed Issues Scheduled Event
if: github.event.schedule == '30 4,10,16,22 * * *'
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json CloseAddressedIssues
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Lock Closed Issues Scheduled Event
if: github.event.schedule == '30 5,11,17,23 * * *'
run: |
echo $GITHUB_PAYLOAD > payload.json
cat > payload.json << 'EOF'
${{ toJson(github.event) }}
EOF
github-event-processor ${{ github.event_name }} payload.json LockClosedIssues
shell: bash
env:
GITHUB_PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42 changes: 37 additions & 5 deletions doc/common/TypeSpec-Project-Scripts.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Integrating with typespec sync and generate scripts

There are 2 common scripts provided for each language to be able to generate from within the language
There are three common scripts provided for each language to be able to generate from within the language
repo and use the remote typespec definition in the spec repo.

## One time language repo setup

There are 3 things that these two scripts expect are set up in your language repo before they will run correctly.
There are three things that these common scripts expect to be set up in your language repo before they will run correctly.

1. Make sure your .gitignore is ignoring the TempTypeSpecFiles
2. Create a common emitter-package.json for your language
Expand Down Expand Up @@ -73,14 +73,18 @@ function Get-dotnet-EmitterPackageJsonPath() {

#### Get-${Language}-EmitterAdditionalOptions (Optional)

This function allows you to append additional `--option` arguments that will be passed into typespec compile. One example of this is the `emitter-output-dir`. For dotnet we want the location of the generated files to be `{projectDir}/src` however in other languages they will have other conventions. This method will take in a fully qualified path to the project directory so you can construct your relative path to that as the output.
This function allows you to append additional `--option` arguments that will be passed into typespec compile. One example of this is the `emitter-output-dir`. For dotnet we want the location of the generated files to be `{projectDir}/src` however in other languages `emitter-output-dir` would be `$projectDirectory`. This method will take in a fully qualified path to the project directory so you can construct your relative path to that as the output.

Example

```powershell
function Get-dotnet-EmitterAdditionalOptions([string]$projectDirectory) {
return "--option @azure-tools/typespec-csharp.emitter-output-dir=$projectDirectory/src"
}
function Get-java-EmitterAdditionalOptions([string]$projectDirectory) {
return "--option @azure-tools/typespec-java.emitter-output-dir=$projectDirectory/"
}
```

## Per project setup
Expand Down Expand Up @@ -109,9 +113,33 @@ repo: Azure/azure-rest-api-specs
cleanup: false
```
## TypeSpec-Project-Process.ps1
- What does this script do?
- fetch `tspconfig.yaml` from remote if it doesn’t exist locally
- parse `tspconfig.yaml`
- create the service folder if none exists
- create an sdk project folder if none exists
- create or update `tsp-location.yaml`
- call `TypeSpec-Project-Sync.ps1`
- call `TypeSpec-Project-Generate.ps1`
- input:
- typespecProjectDirectory (required)
either a folder of `tspconfig.yaml` or a remoteUrl of `tspconfig.yaml`
- commitSha (optional)
- repoUrl (optional)
- output: sdk project folder

```powershell
./eng/common/scripts/TypeSpec-Project-Process.ps1 /home/rc/repos/tmp/spec-repo/specification/contosowidgetmanager/Contoso.WidgetManager 677e272f33a3eaa724abd769af79383a5ac2bba5 https://github.com/Azure/azure-rest-api-specs
or
./eng/common/scripts/TypeSpec-Project-Process.ps1 https://github.com/Azure/azure-rest-api-specs/blob/677e272f33a3eaa724abd769af79383a5ac2bba5/specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml
```

## TypeSpec-Project-Sync.ps1

This is the first script that should be called and can be found at `./eng/common/scripts/TypeSpec-Project-Sync.ps1`. It takes in one parameter which is the root directory of the project which is typically one layer lower than the service directory. As an example for dotnet this is `./sdk/openai/Azure.AI.OpenAI` where `openai` is the service directory and `Azure.AI.OpenAI` is the project directory.
It can be found at `./eng/common/scripts/TypeSpec-Project-Sync.ps1`. It takes in one parameter which is the root directory of the project which is typically one layer lower than the service directory. As an example for dotnet this is `./sdk/openai/Azure.AI.OpenAI` where `openai` is the service directory and `Azure.AI.OpenAI` is the project directory.

```powershell
./eng/common/scripts/TypeSpec-Project-Sync.ps1 ./sdk/openai/Azure.AI.OpenAI
Expand All @@ -125,7 +153,7 @@ This is then copied over to your project directory so that you can make temporar

## TypeSpec-Project-Generate.ps1

This is the second script that should be called and can be found at `./eng/common/scripts/TypeSpec-Project-Generate.ps1`. It takes the exact same parameter as the sync script.
It can be found at `./eng/common/scripts/TypeSpec-Project-Generate.ps1`. It takes the exact same parameter as the sync script.

```powershell
./eng/common/scripts/TypeSpec-Project-Generate.ps1 ./sdk/openai/Azure.AI.OpenAI
Expand All @@ -141,6 +169,10 @@ The exact command that gets run is output stdout to enable debugging if needed.

We currently don't do anything to the tspconfig.yaml that gets pulled in from the spec repo to limit to just your language emitter instead we use the filter option on the command line `--emit $emitterName`. This allows you to isolate the generation to only things owned by your language so you can safely add generation dependencies in CI without needing to worry about noisy neighbors.

## Local scenario

User is recommended to run `TypeSpec-Project-Process.ps1` to generate `tsp-location.yaml` automatically then it would call the other two common scripts to generate sdk code. Alternatively, user can prepare `tsp-location.yaml` manually then run the other two scripts manually to generate sdk code.

## Build tool integration

One use case that some languages have is to have their CI regenerate the project and then do a `git diff` to validate that there are no differences. This helps detect if people modify the generated files manually. To support this its valuable to have the exact same command to generate a project regardless of whether the individual library is autorest or typespec.
Expand Down
76 changes: 21 additions & 55 deletions eng/common/scripts/Update-DocsMsPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
Update docs.microsoft.com CI configuration with provided metadata
.DESCRIPTION
Update docs.microsoft.com CI configuration with metadata in the Azure/azure-sdk
metadata CSV file and information in the docs.microsoft.com repo's own /metadata
folder. The docs.microsoft.com repo's /metadata folder allows onboarding of
Update docs.microsoft.com CI configuration with metadata in the docs.microsoft.com repo's
/metadata folder. The docs.microsoft.com repo's /metadata folder allows onboarding of
packages which have not released to a central package manager.
* Use packages in the Azure/azure-sdk metadata CSV where New == true and
Hide != true
* Add metadata from files in the metadata/ folder to the CSV metadata
* Onboard new packages, update existing tracked packages, leave other packages
in place. (This is implemented on a per-language basis by
in place. (This is implemented on a per-language basis by
$UpdateDocsMsPackagesFn)
.PARAMETER DocRepoLocation
Expand All @@ -25,7 +21,7 @@ variable is meant to be used in the domain-specific business logic in
&$UpdateDocsMsPackagesFn
.PARAMETER ImageId
Optional The docker image for package validation in format of '$containerRegistry/$imageName:$tag'.
Optional The docker image for package validation in format of '$containerRegistry/$imageName:$tag'.
e.g. azuresdkimages.azurecr.io/jsrefautocr:latest
#>
Expand All @@ -42,27 +38,27 @@ param (

. (Join-Path $PSScriptRoot common.ps1)

function GetDocsMetadataForMoniker($moniker) {
function GetDocsMetadataForMoniker($moniker) {
$searchPath = Join-Path $DocRepoLocation 'metadata' $moniker
if (!(Test-Path $searchPath)) {
return @()
if (!(Test-Path $searchPath)) {
return @()
}
$paths = Get-ChildItem -Path $searchPath -Filter *.json

$metadata = @()
foreach ($path in $paths) {
$metadata = @()
foreach ($path in $paths) {
$fileContents = Get-Content $path -Raw
$fileObject = ConvertFrom-Json -InputObject $fileContents
$versionGa = ''
$versionPreview = ''
if ($moniker -eq 'latest') {
$versionPreview = ''
if ($moniker -eq 'latest') {
$versionGa = $fileObject.Version
} else {
} else {
$versionPreview = $fileObject.Version
}

$entry = @{
Package = $fileObject.Name;
Package = $fileObject.Name;
VersionGA = $versionGa;
VersionPreview = $versionPreview;
RepoPath = $fileObject.ServiceDirectory;
Expand All @@ -78,14 +74,12 @@ function GetDocsMetadataForMoniker($moniker) {

return $metadata
}
function GetDocsMetadata() {
# Read metadata from CSV
$csvMetadata = (Get-CSVMetadata).Where({ ($_.New -eq 'true' -or $_.MSDocService -ne '') -and $_.Hide -ne 'true'})

function GetDocsMetadata() {
# Read metadata from docs repo
$metadataByPackage = @{}
foreach ($package in GetDocsMetadataForMoniker 'latest') {
if ($metadataByPackage.ContainsKey($package.Package)) {
foreach ($package in GetDocsMetadataForMoniker 'latest') {
if ($metadataByPackage.ContainsKey($package.Package)) {
LogWarning "Duplicate package in latest metadata: $($package.Package)"
}
Write-Host "Adding latest package: $($package.Package)"
Expand All @@ -103,51 +97,23 @@ function GetDocsMetadata() {
}
}

# Override CSV metadata version information before returning
$outputMetadata = @()
foreach ($item in $csvMetadata) {
if ($metadataByPackage.ContainsKey($item.Package)) {
Write-Host "Overriding CSV metadata from docs repo for $($item.Package)"
$matchingPackage = $metadataByPackage[$item.Package]

# Only update the version from metadata present in the docs repo IF there
# is a specified version. The absence of package metadata in the docs repo
# (e.g. no GA version) does not imply that the CSV metadata is incorrect.
if ($matchingPackage.VersionGA) {
$item.VersionGA = $matchingPackage.VersionGA
}
if ($matchingPackage.VersionPreview) {
$item.VersionPreview = $matchingPackage.VersionPreview
}
}
$outputMetadata += $item
}

# Add entries present in the docs repo which are not present in CSV. These are
# usually packages which have not yet published a preview or GA version.
foreach ($item in $metadataByPackage.Values) {
$matchingPackagesInCsvMetadata = $csvMetadata.Where({ $_.Package -eq $item.Package })
if (!$matchingPackagesInCsvMetadata) {
Write-Host "Adding package from docs metadata that is not found in CSV metadata: $($item.Package)"
$outputMetadata += $item
}
}
# TODO - Add a call to GetDocsMetadataForMoniker for 'legacy' when that is implemented

return $outputMetadata
return $metadataByPackage.Values
}

if ($UpdateDocsMsPackagesFn -and (Test-Path "Function:$UpdateDocsMsPackagesFn")) {

try {
$docsMetadata = GetDocsMetadata
&$UpdateDocsMsPackagesFn -DocsRepoLocation $DocRepoLocation -DocsMetadata $docsMetadata -PackageSourceOverride $PackageSourceOverride -DocValidationImageId $ImageId
} catch {
} catch {
LogError "Exception while updating docs.ms packages"
LogError $_
LogError $_
LogError $_.ScriptStackTrace
exit 1
}

} else {
LogError "The function for '$UpdateFn' was not found.`
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
@if (Model.Revision.Approvers.Count > 0)
{
<span class="small text-muted">
Approvers:
Approved by:
@{
int i = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,14 @@ def evaluate_java_package(package_path: str) -> int:
possible_test_directory = resolve_java_test_directory(package_path)
possible_assets_location = os.path.join(os.path.dirname(package_path),'assets.json')

if os.path.exists(possible_assets_location):
return 2

if not possible_test_directory:
return 0
return -1

test_files = glob.glob(os.path.join(possible_test_directory, "**", "*.java"), recursive=True)

if os.path.exists(possible_assets_location):
return 2

# we only will search the test_files if there are actual session-records present
session_glob = os.path.join(possible_test_directory, "**", "session-records")
session_records = glob.glob(session_glob, recursive=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Azure.SDK.Management.ChangelogGen\Azure.SDK.Management.ChangelogGen.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="apiFile1.cs.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apiFile2.cs.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="autorest1.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="changelog1.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="mergedChangelog1.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="specReadme.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading

0 comments on commit 2d3d182

Please sign in to comment.