Skip to content

Commit

Permalink
adding sample configs
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd committed May 20, 2023
1 parent 0ee37f5 commit 9484399
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
global using NUnit.Framework;
using Azure.Sdk.Tools.Assets.MaintenanceTool.Model;
using Azure.Sdk.Tools.Assets.MaintenanceTool.Scan;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;

namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Tests
{
public class CLITests
{
public string TestDirectory { get; protected set; }

[SetUp]
public void Setup()
{
var workingDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

if (!Directory.Exists(workingDirectory))
{
Directory.CreateDirectory(workingDirectory);
}

// copy our static test files there
var source = Path.Combine(Directory.GetCurrentDirectory(), "TestResources");
var target = Path.Combine(workingDirectory, "TestResources");

Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(source, target);

TestDirectory = workingDirectory;
}

[TearDown]
public void TearDown()
{
Directory.Delete(TestDirectory, true);
}

[Test]
[TestCase("scan", "-c", "")]
[TestCase("scan", "--config", "")]
public void TestScanOptions(params string[] args)
{
}

[Test]
[TestCase("scan")]
[TestCase("scan", "--config")]
public void TestInvalidScanOptions(params string[] args)
{
var obj = new object();

var rootCommand = Program.InitializeCommandOptions((DefaultOptions) =>
{
obj = DefaultOptions;
});

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Tests
{
public class Tests
public class ScanTests
{
// These tests assume the presence of three integration branches for the purposes of testing.
// Azure/azure-sdk-tools
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Repos": [
{
"Repo": "azure/azure-sdk-tools",
"Branches": [
"integration/assets-test-branch"
]
},
{
"Repo": "azure/azure-sdk-assets-integration",
"Branches": [
"integration/assets-branch-1",
"integration/assets-branch-2"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\test-proxy\Azure.Sdk.Tools.TestProxy\Azure.Sdk.Tools.TestProxy.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Model
{
/// <summary>
/// A given RunConfiguration contains multiple repo configurations.
/// A given RunConfiguration contains multiple repo configurations. This class provides such a container as well as
/// mappings to pick up configurations from an incoming path.
/// </summary>
public class RunConfiguration
{
public RunConfiguration() {
Repos = new List<RepoConfiguration>();
}

public RunConfiguration(string configPath)
{

}

public List<RepoConfiguration> Repos { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Binding;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.Sdk.Tools.TestProxy.CommandOptions;

namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Options
{
public class BaseOptions
{
public string ConfigLocation { get; set; } = string.Empty;
}

public class BaseOptionsBinder : BinderBase<BaseOptions>
{
private readonly Option<string> _configLocationOption;

public BaseOptionsBinder(Option<string> configLocationOption)
{
_configLocationOption = configLocationOption;
}

protected override BaseOptions GetBoundValue(BindingContext bindingContext)
{
var result = bindingContext.ParseResult.GetValueForOption(_configLocationOption);

if (result != null)
{
return new BaseOptions
{
ConfigLocation = result
};
}
else
{
return new BaseOptions
{
ConfigLocation = string.Empty
};
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,83 @@
using System.CommandLine;
using Azure.Sdk.Tools.Assets.MaintenanceTool.Model;
using Azure.Sdk.Tools.Assets.MaintenanceTool.Options;
using Azure.Sdk.Tools.Assets.MaintenanceTool.Scan;

namespace Azure.Sdk.Tools.Assets.MaintenanceTool
{
internal class Program
public class Program
{
public static void Main(string[] args)
{
// working directory is where we will look for scan_results.json
public static string[] StoredArgs = new string[] { };

// all should honor
// --ScanData <-- results from previous scans
// working directory is where we will look for previous results "output.json"

// all should honor
// --ScanData <-- results from previous scans (todo, currently checks working directory)

// SCAN
// --configuration: -> path to file
// SCAN
// --configuration: -> path to file

// BACKUP
// --configuration provided?
// SCAN
// BACKUP
// as each tag is backed up, it is saved with suffix _backup

// BACKUP
// --configuration provided?
// SCAN
// BACKUP
// as each tag is backed up, it is saved with suffix _backup
// RESTORE
// --input-tag <tag that has been stored away>

// RESTORE
// --input-tag <tag that has been stored away>
// CLEANUP
// --configuration provided?
// SCAN
// BACKUP
// CLEANUP
// each tag as found by configuration

// CLEANUP
// --configuration provided?
// SCAN
// BACKUP
// CLEANUP
// each tag as found by configuration
// --input-tag <tag on repo>?
// SCAN, BACKUP, and CLEANUP individual tag
public static void Main(string[] args)
{
StoredArgs = args;

var rootCommand = InitializeCommandOptions(Run);
var resultCode = rootCommand.Invoke(args);
Environment.Exit(resultCode);
}

public static void Run(object commandObj)
{
switch (commandObj)
{
case BaseOptions configOptions:
AssetsScanner scanner = new AssetsScanner();
var runConfig = new RunConfiguration(configOptions.ConfigLocation);
scanner.Scan(runConfig);
break;
default:
throw new ArgumentException($"Unable to parse the argument set: {string.Join(" ", StoredArgs)}");
}
}

public static RootCommand InitializeCommandOptions(Action<BaseOptions> action)
{
var root = new RootCommand();
var configOption = new Option<string>(
name: "--config",
description: "The path to the json file containing the repo configuration. A sample repo configuration can be seen under <SolutionDirectory>/integration-test-repo-configuration.yml."
) {
IsRequired = true
};
configOption.AddAlias("-c");

// --input-tag <tag on repo>?
// SCAN, BACKUP, and CLEANUP individual tag
var scanCommand = new Command("scan", "Scan the repositories as configured within the file provided to input argument --config <yml config file>.");
scanCommand.AddOption(configOption);
scanCommand.SetHandler(
(configOpts) => action(configOpts),
new BaseOptionsBinder(configOption)
);
root.Add(scanCommand);

Console.WriteLine("Hello, World!");
return root;
}
}
}
10 changes: 10 additions & 0 deletions tools/assets-automation/assets-maintenance-tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ The tool contained within this directory is intended two fulfill three main task
2. Use the map of data created in step 1 to individually backup tags from the assets repository to a target that we can retrieve later.
3. Use the map of data created in step 1 to clean up _unnecessary_ tags in the assets repository.

## Usage

### Installation

`<todo>`

### Scanning

`<todo>`

## What does the process look like?

![example processing layout](processing_layout.png)
Empty file.
35 changes: 34 additions & 1 deletion tools/assets-automation/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ stages:
displayName: "Integration Tests"
jobs:
- job: Solution_Integration_Test
name: Run Solution Tests

strategy:
matrix:
Expand Down Expand Up @@ -38,6 +39,38 @@ stages:
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/*.trx'
testRunTitle: '$(OS) AssetSync tests against .NET'
testRunTitle: '$(OS) Maintenance tool tests against .NET'
testResultsFormat: 'VSTest'
mergeTestResults: true

- job: CLI_Integration_Test
name: Invoke CLI Tool
strategy:
matrix:
Linux:
Pool: azsdk-pool-mms-ubuntu-2204-general
OS: 'Linux'

pool:
name: $(Pool)

steps:
- template: /eng/pipelines/templates/steps/install-dotnet.yml

- script: 'dotnet test /p:ArtifactsPackagesDir=$(Build.ArtifactStagingDirectory) --logger trx $(Build.SourcesDirectory)/tools/assets-automation/assets-maintenance-tool/'
displayName: 'Test'
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_MULTILEVEL_LOOKUP: 0
GIT_TOKEN: $(azuresdk-github-pat)
GIT_COMMIT_OWNER: azure-sdk
GIT_COMMIT_EMAIL: [email protected]

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/*.trx'
testRunTitle: '$(OS) Maintenance tool tests against .NET'
testResultsFormat: 'VSTest'
mergeTestResults: true

0 comments on commit 9484399

Please sign in to comment.