Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
68 changes: 68 additions & 0 deletions .github/workflows/SyncAnalyzerTemplateMSBuildVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Sync Microsoft.Build version in analyzer template with Version.props
on:
push:
branches:
- main
paths:
- 'eng/Versions.props'

jobs:
Sync-version:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Update analyzer template version with version from Versions.props
shell: pwsh
run: |
try {
# Define the paths to your XML and JSON files
$xmlFilePath = "eng/Versions.props"
$jsonFilePath = "template_feed/content/Microsoft.AnalyzerTemplate/.template.config/template.json"

# Check if the XML file exists
if (-Not (Test-Path -Path $xmlFilePath)) {
throw "Versons.props file not found: $xmlFilePath"
}

# Load and parse the XML content
[xml]$xmlContent = Get-Content -Path $xmlFilePath
$versionPrefix = [string]$xmlContent.Project.PropertyGroup.VersionPrefix

# Validate the versionPrefix
if ([string]::IsNullOrWhiteSpace($versionPrefix)) {
throw "VersionPrefix is empty or null in the XML file: $xmlFilePath"
}

# Check if the JSON file exists
if (-Not (Test-Path -Path $jsonFilePath)) {
throw "Analyzer template file not found: $jsonFilePath"
}

# Load the JSON template
$jsonContent = Get-Content -Path $jsonFilePath -Raw | ConvertFrom-Json

# Update the defaultValue of MicrosoftBuildVersion in the JSON template
$jsonContent.symbols.MicrosoftBuildVersion.defaultValue = $versionPrefix.Trim()

# Convert the JSON content back to a string
$jsonString = $jsonContent | ConvertTo-Json -Depth 10

# Write the updated JSON back to the file
Set-Content -Path $jsonFilePath -Value $jsonString
Write-Output "Updated MicrosoftBuildVersion to $versionPrefix"
}
catch {
Write-Error "An error occurred: $_"
}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'Update MicrosoftBuildVersion in analyzer template'
branch: 'update-msbuild-version-for-analyzer-template'
title: 'Update MicrosoftBuildVersion in analyzer template'
body: '[Automated] Update the MicrosoftBuildVersion defaultValue in the template.json.'
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Microsoft",
"classifications": [
"Common",
"Library"
],
"name": "MSBuild custom analyzer skeleton project.",
"generatorVersions": "[1.0.0.0-*)",
"description": "A project for creating a MSBuild analyzer library that targets .NET Standard",
"groupIdentity": "Microsoft.AnalyzerTemplate",
"identity": "Microsoft.AnalyzerTemplate",
"shortName": "msbuildanalyzer",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "Company.AnalyzerTemplate",
"preferNameDirectory": true,
"primaryOutputs": [
{
"path": "Company.AnalyzerTemplate.csproj"
}
],
"symbols": {
"$schema": "http://json.schemastore.org/template",
"author": "Microsoft",
"classifications": [
"Common",
"Library"
],
"name": "MSBuild custom analyzer skeleton project.",
"generatorVersions": "[1.0.0.0-*)",
"description": "A project for creating a MSBuild analyzer library that targets .NET Standard",
"groupIdentity": "Microsoft.AnalyzerTemplate",
"identity": "Microsoft.AnalyzerTemplate",
"shortName": "msbuildanalyzer",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "Company.AnalyzerTemplate",
"preferNameDirectory": true,
"primaryOutputs": [
{
"path": "Company.AnalyzerTemplate.csproj"
}
],
"symbols": {
"MicrosoftBuildVersion": {
"type": "parameter",
"description": "Overrides the default Microsoft.Build version where analyzer's interfaces are placed",
"datatype": "text",
"defaultValue": "17.11.0",
"defaultValue": "17.12.0",
"replaces": "1.0.0-MicrosoftBuildPackageVersion",
"displayName": "Microsoft.Build default package version override"
}
},
"postActions": [
{
"id": "restore",
"condition": "(!skipRestore)",
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [
{
"text": "Run 'dotnet restore'"
}
],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
}
]
}
},
"postActions": [
{
"id": "restore",
"condition": "(!skipRestore)",
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [
{
"text": "Run 'dotnet restore'"
}
],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
}
]
}