DEV Community

Cover image for Automatically upgrade your package on winget with GitHub Actions
Alexandre
Alexandre

Posted on

Automatically upgrade your package on winget with GitHub Actions

My Workflow

If you are an open source maintainer that wants to distribute your project on Windows, you will probably want to publish it on the Windows Package Manager aka winget. That can be done by creating a package manifest and submitting it to the Windows Package Manager Community Repository (more details in the documentation).

Because you have to do that for each version of your application/package it can quickly become tedious. Fortunately there is a tool called Windows Package Manager Manifest Creator aka Winget Create that can help you with that. That is why I decided to create a workflow that would automate the upgrade of an application manifest each time a new version of the application is released.

Submission Category:

DIY Deployments

Yaml File or Link to Code

GitHub logo TechWatching / winget-package-submission

Contains a workflow to automate the upgrade of a winget package.

winget-package-submission

This repository contains a workflow to automate the upgrade of a winget package You can find more information in this article.

Using this workflow

To use this workflow, you have to:

  • copy-paste the .github/workflows/winget-submission.yml file in your github repository
  • generate a PAT with the scope public_repo and add it to the secrets of your project with the name Project_PAT
  • replace the environment variable value packageFileName with the filename of your package in the GitHub releases of your project
  • replace the environment variable value packageId with the identifier of your package in Windows Package Manager

Windows Package Manager Manifest Creator

This workflow uses Windows Package Manager Manifest Creator to update and submit a new version of a package manifest

Workflow trigger

The workflow is triggered each time a release is published. The idea behind that is to have a new package submitted when a new version of the package…


name: Submit Nushell package to Windows Package Manager Community Repository 

on:
  release:
    types: [published]

env:
  packageFileName: windows.msi
  packageId: MyPackageIdInWinget

jobs:

  winget:
    name: Publish winget package
    runs-on: windows-latest
    steps:
      - name: Submit package to Windows Package Manager Community Repository
        run: |
          iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
          $github = Get-Content '${{ github.event_path }}' | ConvertFrom-Json
          $installerUrl = $github.release.assets | Where-Object -Property name -match ${env:packageFileName} | Select -ExpandProperty browser_download_url -First 1
          .\wingetcreate.exe update ${env:packageId} -s -v $github.release.tag_name -u $installerUrl -t ${{ secrets.Project_PAT }}
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

More information about this workflow can be found in the README of the project.

This workflow I built is currently used on the open source project Nushell (16,4k stars on GitHub). You can check the latest workflow executions here Each time a new version of Nushell is released, the new package manifest is submitted to the Windows Package Manager Community Repository.

If you want to have more details about how this workflow works, how it is used in Nushell or about the tool Winget Create this workflow uses, you can read the article I wrote about that here.

Any other project that wants to distribute its package through winget (and wants to automate it) is more than welcome to use this workflow. Feel free to modify it to meet your project needs.

Discussion (0)