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

lancejpollard

Lance Pollard

Posted on January 23, 2024

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!

💖 💪 🙅 🚩
lancejpollard
Lance Pollard

Posted on January 23, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related