/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/devops/snippets/create-dotnet-github-action/DotNet.GitHubAction/ActionInputs.cs
58 строк
2 KB
David Pine
Update GHA code, .NET 7.0, and address set-output deprecation (#32621)
17 ноя 2022, 02:10
Не верифицирован
17 ноя 2022, 02:10
6b2fc41
Код
Авторство
О чём код?
using CommandLine; namespace DotNet.GitHubAction; public class ActionInputs { string _repositoryName = null!; string _branchName = null!; public ActionInputs() { if (Environment.GetEnvironmentVariable("GREETINGS") is { Length: > 0 } greetings) { Console.WriteLine(greetings); } } [Option('o', "owner", Required = true, HelpText = "The owner, for example: \"dotnet\". Assign from `github.repository_owner`.")] public string Owner { get; set; } = null!; [Option('n', "name", Required = true, HelpText = "The repository name, for example: \"samples\". Assign from `github.repository`.")] public string Name { get => _repositoryName; set => ParseAndAssign(value, str => _repositoryName = str); } [Option('b', "branch", Required = true, HelpText = "The branch name, for example: \"refs/heads/main\". Assign from `github.ref`.")] public string Branch { get => _branchName; set => ParseAndAssign(value, str => _branchName = str); } [Option('d', "dir", Required = true, HelpText = "The root directory to start recursive searching from.")] public string Directory { get; set; } = null!; [Option('w', "workspace", Required = true, HelpText = "The workspace directory, or repository root directory.")] public string WorkspaceDirectory { get; set; } = null!; static void ParseAndAssign(string? value, Action<string> assign) { if (value is { Length: > 0 } && assign is not null) { assign(value.Split("/")[^1]); } } }