DEV Community

Lance Pollard
Lance Pollard

Posted on

Build, Install, and Publish a Local Choco Command (Chocolatey for Windows)

Follow this repo.

Create an org.repo.nuspec file, with this content:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>org.repo</id>
    <title>Org Repo</title>
    <version>0.0.2</version>
    <authors>Name</authors>
    <description>Markdown description</description>
    <dependencies>
      <dependency id="imagemagick" />
      <dependency id="fontforge" />
    </dependencies>
  </metadata>
</package>
Enter fullscreen mode Exit fullscreen mode

You can search packages on choco like ffmpeg, to see what the dependency names are.

The GitHub Action to publish this is:

on: push

jobs:
  test:
    # Windows Server 2022 (https://github.com/actions/runner-images)
    runs-on: windows-2022
    environment: build
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.10.x
      - name: Set PACKAGE_VERSION
        id: version
        run: |
          echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $env:GITHUB_ENV
      - name: Choco pack
        run: |
          choco pack org.repo.nuspec
      - name: Choco install
        run: |
          choco install -y org.repo --source "'.;chocolatey'"
      - name: Choco set api key
        env:
          CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }}
        run:
          choco apikey --key $env:CHOCOLATEY_API_KEY --source https://push.chocolatey.org/
      - name: Choco publish
        env:
          PACKAGE_VERSION: "0.0.2"
        run:
          choco push org.repo.${{ env.PACKAGE_VERSION }}.nupkg --source https://push.chocolatey.org/
Enter fullscreen mode Exit fullscreen mode

If you want to do more than this, like creating an executable, see this example chocolateyinstall.ps1 script, and follow the obscure directions for creating the chocolateyinstall.ps1 script. Here is another "default" script.

Cheers!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
lancejpollard profile image
Lance Pollard

My meta-package got rejected from chocolatey.org community.chocolatey.org/packages/... . A meta package is something that just installs stuff, no executable.

Here is what they said:

As I messaged over on Discord (discord.com/channels/7785523614541...) this package is for a very specific use case and has limited scope. Packages published on the Chocolatey Community Repository are for the wider community and have broad appeal and use. The Chocolatey Community Repository should not be as an an alternative to setting up your own repository.

Due to the above, and from what I can see, this isn't a package we would approve.

Darn :/ Maybe there is another approach.

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay