Publish modules to the Forge with Github Actions and Puppet Development Kit

You can also manually publish new versions of your module to the Forge using Puppet Development Kit, or automate publishing with PDK using GitHub Actions.

 
  1. When creating a Github Action to publish to the Forge, ensure that you have access to the Forge API and have your API token on hand.
  2. Set up your Github Action to build a release of your module when triggered and publish it using the PDKrelease publish command.

    Example:

    # This is a generic workflow for releasing a Puppet module.
    # It requires that the caller sets `secrets: inherit` to ensure
    # that secrets are visible from steps in this workflow.
    name: "Module Release"
    
    on:
      workflow_call:
    
    jobs:
      release:
        name: "Release"
        runs-on: "ubuntu-latest"
        if: github.repository_owner == 'puppetlabs'
    
        steps:
    
          - name: "Checkout"
            uses: "actions/checkout@v4"
            with:
              ref: "${{ github.ref }}"
              clean: true
              fetch-depth: 0
    
          - name: "Get version"
            id: "get_version"
            run: |
              echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT
    
          - name: "PDK build"
            uses: "docker://puppet/pdk:3.0.0.0"
            with:
              args: "build"
    
          - name: "Generate release notes"
            run: |
              export GH_HOST=github.com
              gh extension install chelnak/gh-changelog
              gh changelog get --latest > OUTPUT.md
            env:
              GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    
          - name: "Create release"
            run: |
              gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    
          - name: "Publish module"
            uses: "docker://puppet/pdk:3.0.0.0"
            with:
              args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force'
  3. For more information on Github Actions, visit the Github Actions documentation.
  4. For more information on the PDKrelease command, visit PDK release command.