Skip to content

Commit

Permalink
Merge f920f7d into ca2d168
Browse files Browse the repository at this point in the history
  • Loading branch information
igoravl authored Jul 24, 2024
2 parents ca2d168 + f920f7d commit 073ff45
Show file tree
Hide file tree
Showing 308 changed files with 6,630 additions and 7,148 deletions.
37 changes: 15 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ env:
SkipReleaseNotes: ${{ true }}

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

Expand Down Expand Up @@ -90,10 +91,12 @@ jobs:
shell: pwsh
run: |
$fileName = (Get-ChildItem [0-9]*.md -Recurse | Sort-Object Name | Select -ExpandProperty FullName -Last 1)
echo $fileName
$releaseNotes = (Get-Content $fileName -Encoding UTF8 | Select-Object -Skip 4) -join '%0A'
echo $releaseNotes
Write-Output "::set-output name=RELEASE_NOTES::$releaseNotes"
Write-Output $fileName
$releaseNotes = (Get-Content $fileName -Encoding UTF8 | Select-Object -Skip 4)
Write-Output $releaseNotes
Write-Output 'RELEASE_NOTES<<EOF' >> $env:GITHUB_OUTPUT
Write-Output $releaseNotes >> $env:GITHUB_OUTPUT
Write-Output 'EOF' >> $env:GITHUB_OUTPUT
- name: Create Draft Release
id: create_release
shell: pwsh
Expand Down Expand Up @@ -132,15 +135,10 @@ jobs:
runs-on: ubuntu-latest
environment: production
needs: [ Staging ]
if: ${{ github.event_name != 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}
- name: Promote release
id: promote_release
shell: pwsh
Expand All @@ -155,8 +153,8 @@ jobs:
$rel = Get-GitHubRelease `
| Where-Object { ($_.Draft -eq $true) -and ($_.Name -eq "Release $($env:BUILD_NAME)") }
Set-GitHubRelease -Release $rel.id -Draft:$false
Write-Output "::set-output name=RELEASE_URL::$($rel.html_url)"
Write-Output "::set-output name=RELEASE_TAG::$($env:BUILD_NAME.Replace('+', '%2B'))"
Write-Output "RELEASE_URL=$($rel.html_url)" >> $env:GITHUB_OUTPUT
Write-Output "RELEASE_TAG=$($env:BUILD_NAME.Replace('+', '%2B'))" >> $env:GITHUB_OUTPUT
outputs:
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }}
RELEASE_NOTES: ${{ needs.Staging.outputs.RELEASE_NOTES }}
Expand All @@ -167,7 +165,6 @@ jobs:

runs-on: ubuntu-latest
needs: [ Release ]
if: ${{ github.event_name != 'pull_request' }}
env:
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }}
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
Expand All @@ -187,8 +184,8 @@ jobs:
git checkout --track origin/gh-pages
unzip -o ../../TfsCmdlets-Docs-*.zip
popd
echo build_info: TfsCmdlets v${BUILD_NAME}, released $(date +%F) >> _config.yml
echo >> _config.yml
Write-Output build_info: TfsCmdlets v${BUILD_NAME}, released $(date +%F) >> _config.yml
Write-Output >> _config.yml
git config --local user.name "Igor Abade"
git config --local user.email igoravl@gmail.com
git add *
Expand All @@ -200,7 +197,6 @@ jobs:
runs-on: ubuntu-latest
needs: [ Release ]
environment: psgallery
if: ${{ github.event_name != 'pull_request' }}
env:
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
PSGALLERY_KEY: ${{ secrets.API_KEY }}
Expand All @@ -223,7 +219,6 @@ jobs:
runs-on: ubuntu-latest
needs: [ Release ]
environment: nuget
if: ${{ github.event_name != 'pull_request' }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
Expand All @@ -243,7 +238,6 @@ jobs:
runs-on: windows-latest
needs: [ Release ]
environment: chocolatey
if: ${{ github.event_name != 'pull_request' }}
env:
CHOCO_KEY: ${{ secrets.API_KEY }}
steps:
Expand All @@ -266,7 +260,6 @@ jobs:
runs-on: ubuntu-latest
needs: [ Release ]
environment: winget
if: ${{ github.event_name != 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }}
Expand Down Expand Up @@ -324,7 +317,7 @@ jobs:
steps:
- name: No-op
shell: bash
run: echo "no-op"
run: Write-Output "no-op"
# - name: Tweet
# id: tweet
# uses: snow-actions/tweet@v1.3.0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,4 @@ CSharp/.idea/**
# Miscellaneous files

CSharp/*/Generated/**
Docs/AzDO-Security-Actions.csv
2 changes: 1 addition & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ try {
$isCI = $true
}
elseif ($env:GITHUB_ACTIONS) {
Write-Output "::set-output name=BUILD_NAME::$BuildName"
Write-Output "BUILD_NAME=$BuildName" >> $env:GITHUB_OUTPUT
$isCI = $true
}

Expand Down
2 changes: 2 additions & 0 deletions CSharp/TfsCmdlets.Common/Cmdlets/TfsCmdletAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public sealed class TfsCmdletAttribute : Attribute

public bool ReturnsValue { get; set; }

public string AdditionalCredentialParameterSets { get; set; }

public TfsCmdletAttribute(CmdletScope scope = CmdletScope.None)
{
Scope = scope;
Expand Down
4 changes: 2 additions & 2 deletions CSharp/TfsCmdlets.Common/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static object CallHiddenMethod(this object self, string methodName, param
return method.Invoke(self, parameters);
}

public static string ToJsonString(this object self)
public static string ToJsonString(this object self, bool compress = true)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(self, Newtonsoft.Json.Formatting.None);
return Newtonsoft.Json.JsonConvert.SerializeObject(self, compress? Newtonsoft.Json.Formatting.None: Newtonsoft.Json.Formatting.Indented);
}

private static T FindMember<T>(object self, string memberName)
Expand Down
52 changes: 31 additions & 21 deletions CSharp/TfsCmdlets.Common/Services/Impl/LoggerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ public void LogError(Exception ex, string errorId = null, ErrorCategory category
var innerException = ex.InnerException ?? ex;
var id = errorId ?? innerException.GetType().Name;

PowerShell.WriteError(new ErrorRecord(ex, id, category, targetObject));
try
{
Log($"Detailed Error:\n{ex.ToJsonString(false)})");
}
finally
{
PowerShell.WriteError(new ErrorRecord(ex, id, category, targetObject));
}
}

public void LogWarn(string message)
Expand All @@ -38,7 +45,7 @@ public void LogParameters(string commandName, IParameterManager parameters)
if (!PowerShell.IsVerbose) return;

var parms = new Dictionary<string, object>();
var parameterSetName = parameters["ParameterSetName"]?? "__AllParameterSets";
var parameterSetName = parameters["ParameterSetName"] ?? "__AllParameterSets";
var hasParameterSetName = !parameterSetName.Equals("__AllParameterSets");

foreach (var key in parameters.Keys.Where(key => !key.Equals("ParameterSetName")))
Expand All @@ -57,30 +64,33 @@ public void LogParameters(string commandName, IParameterManager parameters)
value = switchParameter.IsPresent;
break;
}
case Models.Connection conn: {
value = $"{{Connection Url={conn.Uri}}}";
break;
}
case WebApiTeamProject tp: {
value = $"{{Project Name='{tp.Name}' Id={tp.Id}}}";
break;
}
case WebApiTeam t: {
value = $"{{Team Name='{t.Name}' Id={t.Id}}}";
break;
}
case Models.Connection conn:
{
value = $"{{Connection Url={conn.Uri}}}";
break;
}
case WebApiTeamProject tp:
{
value = $"{{Project Name='{tp.Name}' Id={tp.Id}}}";
break;
}
case WebApiTeam t:
{
value = $"{{Team Name='{t.Name}' Id={t.Id}}}";
break;
}
}
parms[key] = value;
}

var args = Newtonsoft.Json.Linq.JObject.FromObject(parms)
.ToString(Newtonsoft.Json.Formatting.None)
.Replace("\":", "\" = ")
.Replace(",\"", "; \"");

Log($"Running [{commandName}] with {(hasParameterSetName ? $"parameter set '{parameterSetName}' and " : "")}the following implicit and explicit arguments:");
Log(args);
var args = parms.ToJsonString(compress: false)
.Replace("\":", "\" =")
.Replace(",\"", "; \"")
.Trim('{', '}')
.Split(';');

Log($"Running [{commandName}] with {(hasParameterSetName ? $"parameter set '{parameterSetName}' and " : "")}" +
$"the following implicit and explicit arguments:\n{string.Join("\n", args)}");
}

[ImportingConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class CmdletInfo : GeneratorState
public string CmdletAttribute { get; private set; }
public string OutputTypeAttribute { get; private set; }

public string AdditionalCredentialParameterSets { get; private set; }

public CmdletInfo(INamedTypeSymbol cmdlet, Logger logger)
: base(cmdlet, logger)
{
Expand All @@ -46,6 +48,7 @@ public CmdletInfo(INamedTypeSymbol cmdlet, Logger logger)
CustomControllerName = cmdlet.GetAttributeNamedValue<string>("TfsCmdletAttribute", "CustomControllerName");
ReturnsValue = cmdlet.GetAttributeNamedValue<bool>("TfsCmdletAttribute", "ReturnsValue");
SkipGetProperty = cmdlet.GetAttributeNamedValue<bool>("TfsCmdletAttribute", "SkipGetProperty");
AdditionalCredentialParameterSets = cmdlet.GetAttributeNamedValue<string>("TfsCmdletAttribute", "AdditionalCredentialParameterSets");
CmdletAttribute = GenerateCmdletAttribute(this);
OutputTypeAttribute = GenerateOutputTypeAttribute(this);

Expand Down Expand Up @@ -95,7 +98,8 @@ private static IEnumerable<GeneratedProperty> GenerateScopeProperty(CmdletScope
var isGetScopedCmdlet = IsGetScopeCmdlet(settings);
var isPipeline = IsPipelineProperty(currentScope, settings);
var valueFromPipeline = isPipeline ? "ValueFromPipeline=true" : string.Empty;
var parameterSetNames = isGetScopedCmdlet ? _credentialParameterSetNames.Select(s => $"ParameterSetName=\"{s}\"") : new[] { string.Empty };
var additionalParameterSets = settings.AdditionalCredentialParameterSets?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0];
var parameterSetNames = isGetScopedCmdlet ? _credentialParameterSetNames.Union(additionalParameterSets).Select(s => $"ParameterSetName=\"{s}\"") : new[] { string.Empty };
var attributes = new List<(string, string)>();

if (scopeName.Equals("Collection"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.14" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Xml.Linq;
using TfsCmdlets.Models;

namespace TfsCmdlets.Cmdlets.Admin
{
Expand Down Expand Up @@ -45,4 +47,38 @@ partial class GetConfigurationConnectionString
[Credential]
public PSCredential Credential { get; set; } = PSCredential.Empty;
}

[CmdletController]
partial class GetConfigurationConnectionStringController
{
protected override IEnumerable Run()
{
if (Has_Session)
{
throw new NotImplementedException("Remote sessions are currently not supported");
}

if (!Parameters.Get<string>("ComputerName").Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
throw new NotImplementedException("Remote computers are currently not supported");
}

var installationPath = Data.GetItem<TfsInstallationPath>(new {
Component = TfsComponent.ApplicationTier
});

var webConfigPath = Path.Combine(installationPath.InnerObject, "Web Services/Web.config");
var webConfig = XDocument.Load(webConfigPath);

var connString = webConfig
.Element("configuration")
.Element("appSettings")
.Descendants("add")
.Where(el => el.Attribute("key").Value == "applicationDatabase")
.Select(el => el.Attribute("value").Value)
.FirstOrDefault();

return connString;
}
}
}
Loading

0 comments on commit 073ff45

Please sign in to comment.