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!

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.