Skip to content

Commit

Permalink
Fix tsc build command path, add missing package versions API, and upd…
Browse files Browse the repository at this point in the history
…ate 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.
  • Loading branch information
dgmjr committed Oct 20, 2023
1 parent 813c646 commit c9d9a01
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 52 deletions.
2 changes: 1 addition & 1 deletion NuGetPush.nuproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PackageTag Include="Packaging" />
</ItemGroup>
<Target Name="BuildTypeScript" AfterTargets="Build">
<Exec Command="tsc $(MSBuildThisFileDirectory)Scripts/ts/*.ts --outDir $(MSBuildThisFileDirectory)Scripts/js --esModuleInterop" />
<Exec Command="tsc" WorkingDirectory="./Scripts" />
</Target>
<Target Name="CleanJSOutput" AfterTargets="Clean">
<Delete Files="$(MSBuildThisFileDirectory)Scripts/js/*" />
Expand Down
29 changes: 11 additions & 18 deletions NuGetPush.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
77 changes: 52 additions & 25 deletions Scripts/ts/delete-github-package-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <org> <package-id> <package-version> <package-type> [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 <org> <package-id> <package-version> <package-type> [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();
7 changes: 6 additions & 1 deletion Scripts/ts/github-cli-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
12 changes: 6 additions & 6 deletions Sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<!--
* Sdk.props
*
*
* Created: 2022-11-27-05:39:27
* Modified: 2022-12-05-04:12:36
*
*
* Author: David G. Moore, Jr. <[email protected]>
*
*
* Copyright © 2022-2023 David G. Moore, Jr., All Rights Reserved
* License: MIT (https://opensource.org/licenses/MIT)
-->

<Project>
<ItemDefinitionGroup>
<NuGetSource Value="Value" PushOnBuild="false" ApiKey="" />
<NuGetSource Value="Value" PushOnBuild="false" ApiKey="" />
<NuGetPushJob PackagePath="" PackageId="" Version="" ApiKey="" DeleteCommand="" PushCommand="" />
</ItemDefinitionGroup>
<PropertyGroup>
<NuGetConfigFile>$(MSBuildThisFileDirectory)../NuGet.config</NuGetConfigFile>
<DeleteGitHubPackageVersionScriptName>$(MSBuildThisFileDirectory)../Scripts/delete-github-package-version.ps1</DeleteGitHubPackageVersionScriptName>
<NuGetConfigFile>$(MSBuildThisFileDirectory)../NuGet.config</NuGetConfigFile>
<DeleteGitHubPackageVersionScriptName>$(MSBuildThisFileDirectory)../Scripts/delete-github-package-version</DeleteGitHubPackageVersionScriptName>
<GitHubOrg />
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<Target Name="PushGitHub" DependsOnTargets="EnsureGitHubToken" Condition="'$(GeneratePackageOnBuild)' == 'true'">
<PropertyGroup>
<DeleteGitHubPackageVersionScript>pwsh $(DeleteGitHubPackageVersionScriptName) $(PackageId) $(PackageVersion) '$(GitHubAuthToken)'</DeleteGitHubPackageVersionScript>
<DeleteGitHubPackageVersionScript>$(DeleteGitHubPackageVersionScriptName) --org "dgmjr-io" -i "$(PackageId)" -v "$(PackageVersion)" --t nuget --token "$(GitHubAuthToken)"</DeleteGitHubPackageVersionScript>
</PropertyGroup>
<Message Text="echo 'DeleteGitHubPackageVersionScript: $(DeleteGitHubPackageVersionScript)' " />
<Exec Command="$(DeleteGitHubPackageVersionScript)" ContinueOnError="true" IgnoreExitCode="true" />
Expand Down

0 comments on commit c9d9a01

Please sign in to comment.