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
121 changes: 121 additions & 0 deletions .github/agents/az-powershell-release.agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
description: "Az PowerShell AutoRest module release agent. Use when: generating PowerShell cmdlets from a new API version, updating autorest README.md, running autorest generation, building autorest modules, recording tests, fixing autorest build errors, updating API version in ConnectedMachine or other AutoRest-based modules."
name: "Az PowerShell Release"
tools: [read, edit, search, execute, web, agent, todo]
---

You are a specialist at releasing Azure PowerShell AutoRest-generated modules. Your job is to update modules to new API versions, generate cmdlets, fix build errors, and record tests.

## Workflow

1. **Find the API spec** — Look up the target API version in `azure-rest-api-specs` repo, get the latest commit hash and the `openapi.json` path
2. **Update README.md** — Update `commit:`, `input-file:`, and any directives with changed paths
3. **Run autorest** — Generate cmdlets from the updated spec
4. **Fix build issues** — Resolve common code-gen conflicts (TrackedResource inheritance, duplicate operations, common-types version mismatches)
5. **Build the module** — Run `./build-module.ps1`
6. **Update recordings** — Replace old API version string in `*.Recording.json` test files
7. **Run tests** — Use `./test-module.ps1 -Playback` to verify, then `-Record` for live re-recording

## Key Knowledge

### TypeSpec-Based Spec Structure (2025+)
The azure-rest-api-specs repo migrated to TypeSpec. The old swagger path:
```
specification/<service>/resource-manager/Microsoft.<Service>/preview/<version>/<Service>.json
```
Is now:
```
specification/<service>/resource-manager/Microsoft.<Service>/<Service>/preview/<version>/openapi.json
```
Note the extra `<Service>/` directory level. This means:
- `input-file` paths have an extra directory level
- Relative `$ref` paths in directives need one additional `../` (6 levels up to reach `specification/` instead of 5)
- A single `openapi.json` replaces multiple `.json` files

### Finding the Commit Hash
Use the GitHub API to get the latest commit touching the target API version:
```
https://api.github.com/repos/Azure/azure-rest-api-specs/commits?path=specification/<service>/resource-manager/Microsoft.<Service>/<Service>/preview/<version>/openapi.json&per_page=1
```

### Common-Types Version
New API versions typically use v6 common-types. If directives reference `common-types/resource-management/v3/types.json`, update them to `v6`. Only files loaded by the main openapi.json are available in autorest's workspace — referencing unloaded versions causes `doesn't exist in workspace` errors.

### autorest npm Connectivity Issues
If `registry.npmjs.org` is blocked (SSL errors), work around it:
1. Download `@autorest/powershell` via Microsoft proxy: `npm pack @autorest/powershell@4.0.754 --registry https://packagefeedproxy.microsoft.io/npm/`
2. Install manually: `npm install <tgz-path> --registry https://packagefeedproxy.microsoft.io/npm/` into `~/.autorest/@autorest_powershell@<version>`
3. Use `--use=<local-path>` flags with autorest

### Known autorest.powershell v4 Bugs

**TrackedResource Location conflict (v6 common-types):**
Models inheriting from TrackedResource via allOf may generate duplicate `Location`/`Location1` properties. Fix by adding a directive to change the allOf to inherit from `Resource` instead and inline `tags`/`location` properties:
```yaml
- from: swagger-document
where: $.definitions.<ModelName>
transform: >-
var trackedProps = { "tags": {...}, "location": {...} };
if (!$.properties.tags) { $.properties.tags = trackedProps.tags; }
if (!$.properties.location) { $.properties.location = trackedProps.location; }
$.allOf = [{"$ref": "../../../../../../common-types/resource-management/v6/types.json#/definitions/Resource"}];
return $;
```

**Parameter type conflicts (multiple operations using same parameter name):**
New operations like `SetupExtensions` may conflict with existing `MachineExtension` operations. Fix with:
```yaml
- remove-operation: <OperationId>
```

**ISO 8601 duration parsing:**
Properties with duration format (`PT4H`) may fail to parse as `System.TimeSpan`. These need custom code in the `/custom` folder or a directive to change the property type.

### Build Commands
```powershell
# Generate (from the .Autorest directory)
autorest --use=<powershell-path> --use=<modelerfour-path> --debug

# Build
./build-module.ps1 # Full build with docs
./build-module.ps1 -NoDocs # Skip docs if platyPS missing

# Test
./test-module.ps1 -Playback # Verify with existing recordings
./test-module.ps1 -Record # Record new tests (needs Azure connection)

# Try out
./run-module.ps1 # Interactive shell with module loaded
```

### Updating Test Recordings
When only the API version changed, bulk-update recording files:
```powershell
Get-ChildItem test/*.Recording.json | ForEach-Object {
$content = Get-Content $_.FullName -Raw
$content = $content -replace "old-api-version", "new-api-version"
Set-Content $_.FullName -Value $content -NoNewline
}
```
Tests using long-running operations (LRO) with unique polling URLs **must** be re-recorded live.

### Git Hygiene
After autorest generation, only ConnectedMachine (or target module) files should be changed. If other files appear modified:
1. `git reset HEAD` to unstage everything
2. `git checkout -- <non-target-paths>` to restore
3. Verify with `git status --short | Where-Object { $_ -notmatch "TargetModule" }`

## Constraints
- NEVER cancel build commands — they can take 15-60 minutes
- NEVER modify `NuGet.Config`
- ALWAYS use commit hashes (not branch names) for API spec references
- ALWAYS add comments explaining WHY each directive exists
- ALWAYS verify the `openapi.json` path structure before updating README.md (TypeSpec vs old swagger)
- DO NOT modify files outside the target module directory without user confirmation

## Output
After completing the workflow, report:
- Number of generated files
- Build status (pass/fail with error summary)
- Test results (passed/failed/skipped counts)
- Any remaining issues requiring manual intervention (e.g., live test recording needed)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the ""License"");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ""AS IS"" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
// is regenerated.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - ConnectedMachine")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.1.1")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.1.1")]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.CLSCompliantAttribute(false)]

34 changes: 27 additions & 7 deletions src/ConnectedMachine/ConnectedMachine.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ In this directory, run AutoRest:
> see https://aka.ms/autorest

``` yaml
commit: a9980ec5181a161dd26c5277f7651722b60503ea
commit: e0594098dde23f29e9908a1f230021e5f4609a4b
require:
- $(this-folder)/../../readme.azure.noprofile.md
input-file:
- $(repo)/specification/hybridcompute/resource-manager/Microsoft.HybridCompute/preview/2024-07-31-preview/HybridCompute.json
- $(repo)/specification/hybridcompute/resource-manager/Microsoft.HybridCompute/preview/2024-07-31-preview/privateLinkScopes.json
- $(repo)/specification/hybridcompute/resource-manager/Microsoft.HybridCompute/HybridCompute/preview/2026-06-16-preview/openapi.json

module-version: 0.1.0
title: ConnectedMachine
Expand All @@ -54,18 +53,29 @@ disable-transform-identity-type-for-operation:
- Machines_Update

directive:
# Fix License model - autorest incorrectly generates duplicate Location property from TrackedResource inheritance
# We suppress the generated Location1 by telling autorest to inline the TrackedResource properties for License only
- from: swagger-document
where: $.definitions.License
transform: >-
var trackedProps = { "tags": {"type": "object", "description": "Resource tags.", "additionalProperties": {"type": "string"}}, "location": {"type": "string", "description": "The geo-location where the resource lives", "x-ms-mutability": ["read", "create"]} };
if (!$.properties.tags) { $.properties.tags = trackedProps.tags; }
if (!$.properties.location) { $.properties.location = trackedProps.location; }
$.allOf = [{"$ref": "../../../../../../common-types/resource-management/v6/types.json#/definitions/Resource"}];
return $;

- from: swagger-document
where: $.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}"].get.parameters
transform: >-
return [
{
"$ref": "../../../../../common-types/resource-management/v3/types.json#/parameters/ApiVersionParameter"
"$ref": "../../../../../../common-types/resource-management/v6/types.json#/parameters/ApiVersionParameter"
},
{
"$ref": "../../../../../common-types/resource-management/v3/types.json#/parameters/SubscriptionIdParameter"
"$ref": "../../../../../../common-types/resource-management/v6/types.json#/parameters/SubscriptionIdParameter"
},
{
"$ref": "../../../../../common-types/resource-management/v3/types.json#/parameters/ResourceGroupNameParameter"
"$ref": "../../../../../../common-types/resource-management/v6/types.json#/parameters/ResourceGroupNameParameter"
},
{
"name": "machineName",
Expand Down Expand Up @@ -207,7 +217,7 @@ directive:
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "../../../../../common-types/resource-management/v3/types.json#/definitions/ErrorResponse"
"$ref": "../../../../../../common-types/resource-management/v6/types.json#/definitions/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -393,6 +403,16 @@ directive:
# These APIs are used by the agent so they do not need to be in the cmdlets
- remove-operation: Machines_CreateOrUpdate
- remove-operation: MachineRunCommands_Update
# SetupExtensions is a non-standard operation that conflicts with MachineExtension parameter types
- remove-operation: SetupExtensions

# Fix MaximumDuration: swagger 'duration' format maps to System.TimeSpan which can't parse ISO 8601 (PT4H)
# Use string type instead so the ISO 8601 value passes through directly to the API
- from: swagger-document
where: $.definitions.MachineInstallPatchesParameters.properties.maximumDuration
transform: >-
delete $.format;
return $;

# Create model cmdlet for complex object
- model-cmdlet:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "licenses",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
{
"resourceType": "locations/publishers/extensionTypes/versions",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
"commands": [
{
"name": "Get-AzConnectedExtensionMetadataV2",
"description": "Gets an Extension Metadata based on location, publisher, extensionType and version",
"path": "/providers/Microsoft.HybridCompute/locations/{location}/publishers/{publisher}/extensionTypes/{extensionType}/versions/{version}",
"help": {
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine/get-azconnectedextensionmetadatav2"
},
"parameterSets": [
{
"parameters": [
"-ExtensionType <String>",
"-Location <String>",
"-Publisher <String>",
"-Version <String>"
]
}
]
},
"examples": [
{
"description": "Gets an Extension Metadata based on location, publisher, extensionType and version",
"parameters": [
{
"name": "-ExtensionType",
"value": "[Path.extensionType]"
},
{
"name": "-Location",
"value": "[Path.location]"
},
{
"name": "-Publisher",
"value": "[Path.publisher]"
},
{
"name": "-Version",
"value": "[Path.version]"
}
]
}
]
},
{
"name": "Get-AzConnectedExtensionMetadata",
"description": "Gets an Extension Metadata based on location, publisher, extensionType and version",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "machines/extensions",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "machines/licenseProfiles",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "machines/runCommands",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "machines",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "privateLinkScopes/networkSecurityPerimeterConfigurations",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "privateLinkScopes",
"apiVersion": "2024-07-31-preview",
"apiVersion": "2026-06-16-preview",
"learnMore": {
"url": "https://learn.microsoft.com/powershell/module/az.connectedmachine"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.LicenseDetails
https://learn.microsoft.com/powershell/module/Az.ConnectedMachine/new-azconnectedlicensedetail
#>
function New-AzConnectedLicenseDetail {
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.ModelCmdletAttribute()]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.LicenseDetails')]
[CmdletBinding(PositionalBinding=$false)]
Param(
Expand All @@ -42,7 +43,7 @@ function New-AzConnectedLicenseDetail {
[string]
$State,
[Parameter(HelpMessage="Describes the license target server.")]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.PSArgumentCompleterAttribute("Windows Server 2012", "Windows Server 2012 R2")]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.PSArgumentCompleterAttribute("Windows Server 2012", "Windows Server 2012 R2", "Windows Server 2016")]
[string]
$Target,
[Parameter(HelpMessage="Describes the license core type (pCore or vCore).")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.ProductFeature
https://learn.microsoft.com/powershell/module/Az.ConnectedMachine/new-azconnectedlicenseprofilefeature
#>
function New-AzConnectedLicenseProfileFeature {
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.ModelCmdletAttribute()]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.ProductFeature')]
[CmdletBinding(PositionalBinding=$false)]
Param(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.ProductFeatureUpdate
https://learn.microsoft.com/powershell/module/Az.ConnectedMachine/update-azconnectedlicenseprofilefeature
#>
function Update-AzConnectedLicenseProfileFeature {
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.ModelCmdletAttribute()]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.ProductFeatureUpdate')]
[CmdletBinding(PositionalBinding=$false)]
Param(
Expand Down
Loading
Loading