From c9d9a010e29cd60c556c23380d987db9f3ff63c7 Mon Sep 17 00:00:00 2001 From: "David G. Moore, Jr" Date: Fri, 20 Oct 2023 04:19:58 -0400 Subject: [PATCH] Fix tsc build command path, add missing package versions API, and update dependencies for GitHub package deletion script - Added missing working directory information to the tsc build command in the NuGetPush.nuproj file. - Implemented missing package versions API in delete-github-package-version.ts. - Updated the command line arguments for delete-github-package-version.ts to use the corresponding short options (-o, -i, -v, -t, -k) instead of the long options (--org, --package-id, --package-version, --type, --token). - Replaced pwsh with just $(DeleteGitHubPackageVersionScriptName) in the PushGitHub target of the Sdk.targets file. Also updated the arguments passed to the script to match the new command line argument format. --- NuGetPush.nuproj | 2 +- NuGetPush.sln | 29 +++----- Scripts/ts/delete-github-package-version.ts | 77 ++++++++++++++------- Scripts/ts/github-cli-types.ts | 7 +- Sdk/Sdk.props | 12 ++-- Sdk/Sdk.targets | 2 +- 6 files changed, 77 insertions(+), 52 deletions(-) diff --git a/NuGetPush.nuproj b/NuGetPush.nuproj index cc8058839ea..07f6c7f11fd 100644 --- a/NuGetPush.nuproj +++ b/NuGetPush.nuproj @@ -33,7 +33,7 @@ - + diff --git a/NuGetPush.sln b/NuGetPush.sln index 1ef057e6c51..6233e65b998 100644 --- a/NuGetPush.sln +++ b/NuGetPush.sln @@ -1,29 +1,22 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# -Project("{82B4Z3B9B-A64C-4715-B499-D71E9CA2BD60}") = "NuGetPush", "NuGetPush.nuproj", "{2498EED9-9158-41BD-9D4A-246A70A1D9E2}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}" + ProjectSection(SolutionItems) = preProject + ..\..\..\Directory.Build.props = ..\..\..\Directory.Build.props + ..\..\..\Directory.Build.targets = ..\..\..\Directory.Build.targets + ..\..\..\global.json = ..\..\..\global.json + ..\..\..\Packages\Versions.Local.props = ..\..\..\Packages\Versions.Local.props + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Local|Any CPU = Local|Any CPU Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 + Testing|Any CPU = Testing|Any CPU + Staging|Any CPU = Staging|Any CPU + Production|Any CPU = Production|Any CPU Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x64.ActiveCfg = Debug|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x64.Build.0 = Debug|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x86.ActiveCfg = Debug|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x86.Build.0 = Debug|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|Any CPU.Build.0 = Release|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x64.ActiveCfg = Release|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x64.Build.0 = Release|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x86.ActiveCfg = Release|Any CPU - {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Scripts/ts/delete-github-package-version.ts b/Scripts/ts/delete-github-package-version.ts index 78bf410bbaa..3580773837d 100755 --- a/Scripts/ts/delete-github-package-version.ts +++ b/Scripts/ts/delete-github-package-version.ts @@ -12,54 +12,81 @@ import process from 'process'; import { deletePackageVersionAsync } from "./github-cli.js"; -import { PackageType } from './github-cli-types.js'; +import { PackageType, toPackageType, toSemVer } from './github-cli-types.js'; import yargs from 'yargs/yargs'; import { hideBin } from 'yargs/helpers'; import { SemVer } from "semver"; // const argv = yargs(hideBin(process.argv)); +const getArg = function (...marker: string[]): string | undefined { + for (let i = 0; i < marker.length; i++) { + var pos = process.argv.findIndex(arg => arg.endsWith(marker[i])); + if (pos > -1 && pos < process.argv.length - 1) { + return process.argv[pos + 1]; + } + return undefined; + } +}; + const main = async () => { - console.log(`yargs: ${JSON.stringify(yargs)}`); + // console.log(`yargs: ${JSON.stringify(yargs)}`); // console.log(`argv: ${JSON.stringify(argv)}`); - const ToSemVer = (stringVer: string) => new SemVer(stringVer); - console.log(`ToSemVer: ${JSON.stringify(ToSemVer)}`); + console.log(`ToSemVer: ${JSON.stringify(toSemVer)}`); - const ToPackageType = (stringType: string) => stringType as PackageType; - console.log(`ToPackageType: ${JSON.stringify(ToPackageType)}`); + console.log(`ToPackageType: ${JSON.stringify(toPackageType)}`); - const argv = await yargs(hideBin(process.argv)) - .usage("Usage: $0 [github-token]") - .option("org", { "type": "string", "describe": "The organization that owns the package", "demandOption": true, "string": true, "message": "The organization is required", "alias": ["o", "organization", "org"] }) - .option("package-id", { "type": "string", "describe": "The package's ID/name", "demandOption": true, "string": true, "message": "The package ID is required", "alias": ["i", "id", "package-id", "pkgid"] }) - .option("package-version", { "describe": "The package's semver version number", "demandOption": true, "message": "Package version is required", "alias": ["v", "version", "package-version"], "coerce": ToSemVer }) - .option("type", { "type": "string", "describe": "The package's type (one of npm, maven, rubygems, docker, nuget, container)", "choices": ["npm", "maven", "rubygems", "docker", "nuget", "container"], "alias": ["t", "type", "package-tyoe"], "default": "nuget", "coerce": ToPackageType }) - .option("token", { "type": "string", "describe": "The GitHub API token", "alias": ["token", "t"], "string": true, "default": process.env.GITHUB_TOKEN }) - // .showCompletionScript() - .showHelpOnFail(true) - .help() - .argv; + // const argv = await yargs(hideBin(process.argv)) + // // .usage("Usage: $0 [github-token]") + // .option("org", { "type": "string", "describe": "The organization that owns the package", "demandOption": true, "string": true, "message": "The organization is required", "alias": ["o", "organization", "org"] }) + // .option("package-id", { "type": "string", "describe": "The package's ID/name", "demandOption": true, "string": true, "message": "The package ID is required", "alias": ["i", "id", "package-id", "pkgid"] }) + // .option("package-version", { "describe": "The package's semver version number", "demandOption": true, "message": "Package version is required", "alias": ["v", "version", "package-version"], "coerce": ToSemVer }) + // .option("type", { "type": "string", "describe": "The package's type (one of npm, maven, rubygems, docker, nuget, container)", "choices": ["npm", "maven", "rubygems", "docker", "nuget", "container"], "alias": ["t", "type", "package-tyoe"], "default": "nuget", "coerce": ToPackageType }) + // .option("token", { "type": "string", "describe": "The GitHub API token", "alias": ["token", "t"], "string": true, "default": process.env.GITHUB_TOKEN }) + // // .showCompletionScript() + // .showHelpOnFail(true) + // .help() + // .argv; - console.log(`argv: ${JSON.stringify(argv)}`); + // console.log(`argv: ${JSON.stringify(argv)}`); // const Argsv = await argv.argv; // console.log(`argsv: ${JSON.stringify(Argsv)}`); - const orgId = argv.org; - const packageId = argv.packageId; - const version = argv.packageVersion; - const packageType = argv.type; - const token = argv.token; + const orgId = getArg("org", "o", "organization"); + const packageId = getArg("i", "id", "package-id", "pkgid"); + const version = toSemVer(getArg("v", "version", "package-version")); + const packageType = toPackageType(getArg("t", "type", "package-type")); + const token = getArg("token", "k"); console.log(`Args: org: ${orgId}, packageId: ${packageId}, version: ${version}, packageType: ${packageType}, token: ${token}`); + if (orgId === undefined) { + throw new Error("Organization is required"); + } + + if (packageId === undefined) { + throw new Error("Package ID is required"); + } + + if (version === undefined) { + throw new Error("Package version is required"); + } + + if (packageType === undefined) { + throw new Error("Package type is required"); + } + + if (token === undefined) { + throw new Error("GitHub API token is required"); + } + await deletePackageVersionAsync(orgId, packageId, version, packageType, token); }; console.log(`main: ${main}`); -main(); - +await main(); diff --git a/Scripts/ts/github-cli-types.ts b/Scripts/ts/github-cli-types.ts index e66a0fc0fe0..cc9d202f064 100644 --- a/Scripts/ts/github-cli-types.ts +++ b/Scripts/ts/github-cli-types.ts @@ -9,6 +9,7 @@ * Copyright © 2022-2023 David G. Moore, Jr., All Rights Reserved * License: MIT (https://opensource.org/licenses/MIT) */ +import { SemVer } from "semver"; export interface PackageVersion { id: number; @@ -18,7 +19,7 @@ export interface PackageVersion { created_at: string; updated_at: string; visibility: string; - package_type: string; + package_type: PackageType; downloads_count: number; description: string; html_url: string; @@ -31,3 +32,7 @@ export interface ApiMessage { } export type PackageType = "nuget" | "npm" | "docker" | "maven" | "rubygems" | "container"; + + +export const toSemVer = (stringVer: string | undefined) => new SemVer(stringVer ?? "0.0.0"); +export const toPackageType = (stringType: string | undefined) => stringType as PackageType; diff --git a/Sdk/Sdk.props b/Sdk/Sdk.props index 7e1a24e4c9e..68063e41968 100644 --- a/Sdk/Sdk.props +++ b/Sdk/Sdk.props @@ -1,23 +1,23 @@ - + - $(MSBuildThisFileDirectory)../NuGet.config - $(MSBuildThisFileDirectory)../Scripts/delete-github-package-version.ps1 + $(MSBuildThisFileDirectory)../NuGet.config + $(MSBuildThisFileDirectory)../Scripts/delete-github-package-version diff --git a/Sdk/Sdk.targets b/Sdk/Sdk.targets index 00597a3dcc5..94ae767a2d0 100644 --- a/Sdk/Sdk.targets +++ b/Sdk/Sdk.targets @@ -39,7 +39,7 @@ - pwsh $(DeleteGitHubPackageVersionScriptName) $(PackageId) $(PackageVersion) '$(GitHubAuthToken)' + $(DeleteGitHubPackageVersionScriptName) --org "dgmjr-io" -i "$(PackageId)" -v "$(PackageVersion)" --t nuget --token "$(GitHubAuthToken)"