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

Replace argument for removing a previous manifest #440

Merged
merged 4 commits into from
Sep 12, 2023
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
18 changes: 11 additions & 7 deletions doc/update.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@

# update command (Winget-Create)

The **update** command of the [Winget-Create](../README.md) tool is designed to update an existing manifest. The **update** command is non-interactive so that it can be seamlessly integrated into your build pipeline to assist with the publishing of your installer. The **update** command will update the manifest with the new URL, hash and version and can automatically submit the pull request (PR) to the [Windows Package Manager repo](https://docs.microsoft.com/windows/package-manager/).
The **update** command of the [Winget-Create](../README.md) tool is designed to update an existing manifest. The **update** command is non-interactive so that it can be seamlessly integrated into your build pipeline to assist with the publishing of your installer. The **update** command will update the manifest with the new URL, hash and version and can automatically submit the pull request (PR) to the [Windows Package Manager repo](https://docs.microsoft.com/windows/package-manager/).

## Usage

`wingetcreate.exe update <id> [-u <urls>] [-v <version>] [-s] [-t <token>] [-o <output directory>]`
`wingetcreate.exe update <id> [-u <urls>] [-v <version>] [-s] [-t <token>] [-o <output directory>] [-p <pull request title>] [-r] [<replace version>]`

The **update** command can be called with the installer URL(s) that you wish to update the manifest with. **Please make sure that the number of installer URL(s) included matches the number of existing installer nodes in the manifest you are updating. Otherwise, the command will fail.** This is to ensure that we can deterministically update each installer node with the correct matching installer url provided.
The **update** command can be called with the installer URL(s) that you wish to update the manifest with. **Please make sure that the number of installer URL(s) included matches the number of existing installer nodes in the manifest you are updating. Otherwise, the command will fail.** This is to ensure that we can deterministically update each installer node with the correct matching installer url provided.

> **Note**\
> The [show](show.md) command can be used to quickly view an existing manifest from the packages repository.

### *How does Winget-Create know which installer(s) to match when executing an update?*

[Winget-Create](../README.md) will attempt to match installers based on the installer architecture and installer type. The installer type will always be derived from downloading and analyzing the installer package.
[Winget-Create](../README.md) will attempt to match installers based on the installer architecture and installer type. The installer type will always be derived from downloading and analyzing the installer package.

There are cases where the intended architecture specified in the existing manifest can sometimes differ from the actual architecture of the installer package. To mitigate this discrepancy, the installer architecture will first be determined by performing a regex string match to identify the possible architecture in the installer url. If no match is found, [Winget-Create](../README.md) will resort to obtaining the architecture from the downloaded installer.

## Usage Examples

Search for an existing manifest and update the version:

`wingetcreate.exe update --version <Version> <PackageIdentifier>`
Expand Down Expand Up @@ -53,14 +54,17 @@ The following arguments are available:
| **-v, --version** | Version to be used when updating the package version field.
| **-o, --out** | The output directory where the newly created manifests will be saved locally
| **-s, --submit** | Boolean value for submitting to the Windows Package Manager repo. If true, updated manifest will be submitted directly using the provided GitHub Token
| **-r, --replace** | Boolean value for removing an existing manifest from the Windows Package Manager repo. Optionally provide a version or else the latest version will be removed. Default is false.
mdanish-kh marked this conversation as resolved.
Show resolved Hide resolved
| **-p, --prtitle** | The title of the pull request submitted to GitHub.
| **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo. If no token is provided, tool will prompt for GitHub login credentials.
| **-?, --help** | Gets additional help on this command. |

## Submit
## Submit

If you have provided your [GitHub token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) on the command line along with the **--submit** flag, **Winget-Create** will automatically submit your PR to [Windows Package Manager repo](https://docs.microsoft.com/windows/package-manager/).
If you have provided your [GitHub token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) on the command line along with the **--submit** flag, **Winget-Create** will automatically submit your PR to [Windows Package Manager repo](https://docs.microsoft.com/windows/package-manager/).

Instructions on setting up GitHub Token for Winget-Create can be found [here](../README.md#github-personal-access-token-classic-permissions).
## Output

## Output

If you would like to write the file to disk rather than submit to the repository, you can pass in the **--output** command along with the file name to write to.
6 changes: 4 additions & 2 deletions src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,10 @@ protected async Task<bool> CheckGitHubTokenAndSetClient()
/// </summary>
/// <param name="manifests">Wrapper object for manifest object models to be submitted.</param>
/// <param name="prTitle">Optional parameter specifying the title for the pull request.</param>
/// <param name="shouldReplace">Optional parameter specifying whether the new submission should replace an existing manifest.</param>
/// <param name="replaceVersion">Optional parameter specifying the version of the manifest to be replaced.</param>
/// <returns>A <see cref="Task"/> representing the success of the asynchronous operation.</returns>
protected async Task<bool> GitHubSubmitManifests(Manifests manifests, string prTitle = null)
protected async Task<bool> GitHubSubmitManifests(Manifests manifests, string prTitle = null, bool shouldReplace = false, string replaceVersion = null)
{
if (string.IsNullOrEmpty(this.GitHubToken))
{
Expand All @@ -625,7 +627,7 @@ protected async Task<bool> GitHubSubmitManifests(Manifests manifests, string prT

try
{
PullRequest pullRequest = await this.GitHubClient.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, prTitle);
PullRequest pullRequest = await this.GitHubClient.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, prTitle, shouldReplace, replaceVersion);
this.PullRequestNumber = pullRequest.Number;
PullRequestEvent pullRequestEvent = new PullRequestEvent { IsSuccessful = true, PullRequestNumber = pullRequest.Number };
TelemetryManager.Log.WriteEvent(pullRequestEvent);
Expand Down
40 changes: 37 additions & 3 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public static IEnumerable<Example> Examples
[Value(0, MetaName = "PackageIdentifier", Required = true, HelpText = "PackageIdentifier_HelpText", ResourceType = typeof(Resources))]
public string Id { get; set; }

/// <summary>
/// Gets or sets the previous version to remove from the Windows Package Manager repository.
/// </summary>
[Value(1, MetaName = "ReplaceVersion", Required = false, HelpText = "ReplaceVersion_HelpText", ResourceType = typeof(Resources))]
public string ReplaceVersion { get; set; }

/// <summary>
/// Gets or sets the new value used to update the manifest version element.
/// </summary>
Expand All @@ -78,6 +84,12 @@ public static IEnumerable<Example> Examples
[Option('s', "submit", Required = false, HelpText = "SubmitToWinget_HelpText", ResourceType = typeof(Resources))]
public bool SubmitToGitHub { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to remove a previous version of the manifest with the update.
/// </summary>
[Option('r', "replace", Required = false, HelpText = "ReplacePrevious_HelpText", ResourceType = typeof(Resources))]
public bool Replace { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to launch an interactive mode for users to manually select which installers to update.
/// </summary>
Expand All @@ -97,9 +109,9 @@ public static IEnumerable<Example> Examples
public IEnumerable<string> InstallerUrls { get; set; } = new List<string>();

/// <summary>
/// Gets or sets the unbound arguments that exist after the first positional parameter.
/// Gets or sets the unbound arguments that exist after the positional parameters.
/// </summary>
[Value(1, Hidden = true)]
[Value(2, Hidden = true)]
public IList<string> UnboundArgs { get; set; } = new List<string>();

/// <summary>
Expand Down Expand Up @@ -144,6 +156,26 @@ public override async Task<bool> Execute()
this.Id = exactId;
}

if (!string.IsNullOrEmpty(this.ReplaceVersion))
{
// If update version is same as replace version, it's a regular update.
if (this.Version == this.ReplaceVersion)
{
this.Replace = false;
}
mdanish-kh marked this conversation as resolved.
Show resolved Hide resolved

// Check if the replace version exists in the repository.
try
{
await this.GitHubClient.GetManifestContentAsync(this.Id, this.ReplaceVersion);
}
catch (Octokit.NotFoundException)
{
Logger.ErrorLocalized(nameof(Resources.VersionDoesNotExist_Error), this.Version, this.Id);
return false;
}
}

List<string> latestManifestContent;

try
Expand Down Expand Up @@ -209,7 +241,9 @@ await this.UpdateManifestsInteractively(initialManifests) :
return await this.LoadGitHubClient(true)
? (commandEvent.IsSuccessful = await this.GitHubSubmitManifests(
updatedManifests,
this.GetPRTitle(updatedManifests, originalManifests)))
this.GetPRTitle(updatedManifests, originalManifests),
this.Replace,
this.ReplaceVersion))
: false;
}

Expand Down
27 changes: 27 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1099,4 +1099,17 @@
<data name="VersionManifest_Message" xml:space="preserve">
<value>Version Manifest:</value>
</data>
<data name="ReplacePrevious_HelpText" xml:space="preserve">
<value>Boolean value for removing an existing manifest from the Windows Package Manager repo. Optionally provide a version or else the latest version will be removed. Default is false.</value>
</data>
<data name="VersionDoesNotExist_Error" xml:space="preserve">
<value>Version {0} does not exist for {1} in the Windows Package Manager repository.</value>
<comment>{0} - will be replaced with the package version

{1} - will be replaced with the package ID
</comment>
</data>
<data name="ReplaceVersion_HelpText" xml:space="preserve">
<value>Optional. Package version used in conjunction with the replace argument to remove an older version of the manifest from the Windows Package Manager repo.</value>
</data>
</root>
Loading