Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add a package table to README.md #2864

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ To make it easier for you to develop with the Google APIs using the Google API c

The generator that produces the source code for API-specific libraries is in https://github.com/googleapis/gapic-generator-csharp. The most recently generated code is available in `Src/Generated/`, and the discovery documents from which that code was generated are in `DiscoveryJson/`.

The libraries are shown in the following table.

|API|NuGet package|Reference documentation|
|---|---|---|

# Support Forums

If you find an issue with in the client library we would appreciate you adding an issue in the [issue tracker](https://github.com/googleapis/google-api-dotnet-client/issues).
Questions regarding usage of the client library should be posted to [stackoverflow.com](http://stackoverflow.com/) using the tag [#google-api-dotnet-client](http://stackoverflow.com/questions/tagged/google-api-dotnet-client)

14 changes: 14 additions & 0 deletions Src/Tools/Tools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageChecker", "PackageCh
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolUtilities", "ToolUtilities\ToolUtilities.csproj", "{0F43325F-ED02-43F4-ACEE-07F129007552}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateReadmePackageList", "UpdateReadmePackageList\UpdateReadmePackageList.csproj", "{242B6A60-E733-4ADC-B9E5-BF307327B173}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -97,6 +99,18 @@ Global
{0F43325F-ED02-43F4-ACEE-07F129007552}.Release|x64.Build.0 = Release|Any CPU
{0F43325F-ED02-43F4-ACEE-07F129007552}.Release|x86.ActiveCfg = Release|Any CPU
{0F43325F-ED02-43F4-ACEE-07F129007552}.Release|x86.Build.0 = Release|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Debug|Any CPU.Build.0 = Debug|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Debug|x64.ActiveCfg = Debug|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Debug|x64.Build.0 = Debug|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Debug|x86.ActiveCfg = Debug|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Debug|x86.Build.0 = Debug|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Release|Any CPU.ActiveCfg = Release|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Release|Any CPU.Build.0 = Release|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Release|x64.ActiveCfg = Release|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Release|x64.Build.0 = Release|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Release|x86.ActiveCfg = Release|Any CPU
{242B6A60-E733-4ADC-B9E5-BF307327B173}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 27 additions & 0 deletions Src/Tools/UpdateReadmePackageList/PackageTableEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: License

using Google.Apis.Discovery.v1.Data;
using ToolUtilities;

namespace UpdateReadmePackageList;

internal class PackageTableEntry
{
public string PackageName { get; }
public string NugetLink => $"https://www.nuget.org/packages/{PackageName}";
public string ReferenceDocsLink => $"https://googleapis.dev/dotnet/{PackageName}/latest/api/{PackageName}.html";
public string ApiDocsLink { get; }
public string ApiName { get; }

private PackageTableEntry(RestDescription discoveryDoc)
{
PackageName = Discovery.GetPackageName(discoveryDoc);
ApiDocsLink = discoveryDoc.DocumentationLink;
ApiName = $"{discoveryDoc.Title} {discoveryDoc.Version.Replace('.', '_')}";
}

public static PackageTableEntry Load(string discoveryFilePath) =>
new(Discovery.ParseDiscoveryJson(File.ReadAllText(discoveryFilePath)));

internal string ToMarkdown() =>
$"|[{ApiName}]({ApiDocsLink})|[{PackageName}]({NugetLink})|[Library documentation]({ReferenceDocsLink})|";
}
65 changes: 65 additions & 0 deletions Src/Tools/UpdateReadmePackageList/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024 Google LLC
//
// 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
//
// https://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.

// Translates the arguments from BuildGenerated.sh into directories containing
// libraries. This is primarily for the sake of being able to accept Discovery file
// paths as reported by earlier phases of the build pipeline. See BuildGenerated.sh
// for details of the expected arguments. The first argument is the generation directory,
// and is specified by BuildGenerated.sh itself.

// This code copies elements from the REST generator. While duplication isn't great,
// this is code that isn't expected to change regularly, and it's cleaner to make this
// small utility standalone than to put it into the generator itself (or have some common
// dependency library).

using UpdateReadmePackageList;

// Everything before this line is preserved.
// Everything after this line, but before the next empty line, is replaced.
// Everything after the empty line after this line is preserved.
const string TableHeaderSeparator = "|---|---|---|";

if (args.Length != 2)
{
Console.WriteLine("Arguments: <path-to-README.md> <path-to-discovery-directory>");
return 1;
}

string readmePath = args[0];
string discoveryDirectory = args[1];

var readmeLines = File.ReadAllLines(readmePath).ToList();
int separatorIndex = readmeLines.IndexOf(TableHeaderSeparator);
if (separatorIndex == -1)
{
Console.WriteLine($"Unable to find header separator line in {readmePath}. Aborting.");
return 1;
}

var linesBeforeSeparator = readmeLines.Take(separatorIndex);
var linesAfterTable = readmeLines.Skip(separatorIndex).SkipWhile(line => line != "");

var tableEntries = Directory.GetFiles(discoveryDirectory, "*.json")
.Select(PackageTableEntry.Load)
.OrderBy(te => te.PackageName, StringComparer.Ordinal);

var newReadmeLines = linesBeforeSeparator
.Append(TableHeaderSeparator)
.Concat(tableEntries.Select(te => te.ToMarkdown()))
.Concat(linesAfterTable)
.ToList(); // Evaluate eagerly before we start to write anything.

File.WriteAllLines(readmePath, newReadmeLines);

return 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\ToolUtilities\ToolUtilities.csproj" />
</ItemGroup>

</Project>