Blog Post

Educator Developer Blog
4 MIN READ

WingetCreate: Keeping WinGet packages up-to-date!

FBoucher's avatar
FBoucher
Brass Contributor
Jan 25, 2024

This post was written by Muhammad Danish

 

In the ever-evolving landscape of software development, efficiency is key. Windows users have long awaited an experience, where the simplicity of installing, updating, and managing software could be as seamless as executing a single command. Enter Windows Package Manager, or WinGet, a powerful tool that reshapes the way we handle software packages on the Windows platform. WinGet brings the simplicity of Linux package managers to the Windows environment, enabling users to use the command-line for installing their favorite packages.

 

To submit software packages to Windows Package Manager, the open-source Microsoft Community Package Manifest Repository is available on GitHub. Independent Software Vendors (ISVs) can submit package manifests (defined in a YAML format) in the repository to have their software packages considered for inclusion with Windows Package Manager. With frequent updates and new versions to software rolling out, the process of generating and updating manifest files must be swift and uncomplicated.

 

What's WingetCreate

Recognizing the need for simplicity and efficiency in this process, WingetCreate emerges as a solution, providing a user-friendly interface for manifest generation. WingetCreate presents two distinct modes to cater to varying user needs. The interactive mode guides new users through a series of questions, simplifying the manifest creation process and enabling easy submissions to the Community Repository. On the other hand, the autonomous mode for the update process is strategically designed for CI/CD environments, seamlessly integrating into existing pipelines. Publishers can now automate the entire workflow, from manifest generation to pull request submission, ensuring a smooth and streamlined update process on the WinGet repository.

 

Installing WingetCreate

If you already have the Windows Package Manager (WinGet) installed on your machine, you can install the manifest creator with a simple command:

 

winget install wingetcreate

 

Alternatively, you can visit the WingetCreate GitHub Repository and download the latest release from https://github.com/microsoft/winget-create/releases. Once you have the tool installed, type `wingetcreate` in a terminal session to see the tool’s help text.

WingetCreate Features

The tool supports several different functionalities. For now, we’ll look at a couple of key commands:

 

new: Interactive command that can help you generate a brand-new manifest. You’ll want to use this command if your package does not exist in the winget repository yet. The manifest generated will serve as the base manifest for a future update using the update command.
show: This command lets you see the manifest for an existing package in the community repository. Alternatively, you can visit the packages repository on GitHub (https://github.com/microsoft/winget-pkgs) and find the package manifest under the manifests/ directory.

update: This is where the fun happens.  This command lets you update an existing manifest from the community repository. Pass in `--interactive` if you want the interactive experience. By default, the command runs in autonomous mode.

If you run the commands passing `--help` e.g., `wingetcreate new --help`, it will show you the help text and supported options for each command.

See how the update command is used using an actual example in the video:

 

 

Using the tool in a CI/CD environment

The power of WingetCreate is most highlighted in a CI/CD environment. Here we’ll look at how the folks over at Microsoft’s DevHome repository (https://github.com/microsoft/devhome) automate their releases using WingetCreate. DevHome uses GitHub Actions as their CI environment to publish releases to WinGet repository. The WingetCreate docs (https://github.com/microsoft/winget-create/blob/main/pipelines/azure-pipelines.release.yml) also specify an example for usage in Azure Pipelines. Here we will look at the workflow file defined in DevHome’s repository: https://github.com/microsoft/devhome/blob/main/.github/workflows/winget-submission.yml

 

 

 

 

 

name: Submit Microsoft.DevHome package to Windows Package Manager Community Repository

on:
  workflow_dispatch:
  release:
    types: [published]

jobs:
  winget:
    name: Publish winget package
    runs-on: windows-latest
    steps:
      - name: Submit package to Windows Package Manager Community Repository
        run: |

          $packageId = "Microsoft.DevHome"
          $gitToken = "${{ secrets.WINGET_PAT }}"

          # Fetching latest release from GitHub
          $github = Invoke-RestMethod -uri "https://api.github.com/repos/microsoft/devhome/releases"
          $targetRelease = $github | Where-Object -Property name -match 'Dev Home'| Select-Object -First 1
          $installerUrl = $targetRelease | Select-Object -ExpandProperty assets -First 1 | Where-Object -Property name -match 'Windows.DevHome.*?msixbundle' | Select-Object -ExpandProperty browser_download_url
          $packageVersion = $targetRelease.tag_name.Trim("v")

          # Update package using wingetcreate
          Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
          .\wingetcreate.exe update $packageId --version $packageVersion --urls "$installerUrl" --submit --token $gitToken

 

 

 

 

 

Using the `on:` keyword, we instruct the workflow to run on specific events. Here by specifying `release: types: [publised]`, the workflow will trigger only when a new release is published on GitHub, allowing you to define this workflow file once and forget about updating your package.

 

The file contains a single job that runs a simple PowerShell script. It fetches the latest release version and URLs from GitHub, downloads WingetCreate in the agent created by GitHub Action and invokes `wingetcreate update` passing in all the required parameters. At the end of the update, a pull request is automatically submitted to the Windows Package Manager Community Repository.

 

PR submission to the WinGet GitHub Repository requires you to create a GitHub Personal Access Token and pass it to WingetCreate using the `--token option`. Instructions on how to generate the token can be found in the WingetCreate docs (https://github.com/microsoft/winget-create#github-personal-access-token-classic-permissions). Since you never want to be hardcoding your tokens (very bad idea!), GitHub allows you to define it as a repository secret (https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-encrypted-secrets-for-a-repository) for security.

 

Workflow in action, generating and submitting PRs to update the Microsoft.DevHome package:

Conclusion

WingetCreate provides a convenient method for generating and updating manifests for the community repository. Publishers are encouraged to use the tool in their release pipelines, ensuring timely package submissions so that users consistently receive the most up-to-date and secure versions of their software.

 

Additional Resources

 

Updated Jan 24, 2024
Version 1.0
No CommentsBe the first to comment