This GitHub Action enables you to publish a PowerShell module to the PowerShell Gallery or another Nuget-Based Repository.
Forked from: https://github.com/pcgeek86/publish-powershell-module-action
- Add a GitHub Actions Workflow configuration to your GitHub project, under
.github/workflows/main.yml
- Configure a secret on your GitHub repository, containing your PowerShell Gallery NuGet API key
- Add the following step to your GitHub Actions job
For example, if you named your secret PS_GALLERY_KEY
:
- name: Publish Module to PowerShell Gallery
uses: pcgeek86/publish-powershell-module-action@v20
id: publish-module
with:
NuGetApiKey: ${{ secrets.PS_GALLERY_KEY }}
moduleName: 'MyModule'
modulePath: .\Modules\MyModule
You can use a custom Nuget repository with this parameters.
NuGetApiKey: ${{ secrets.PRIVATEREPO_KEY }}
NugetRepository: Privaterepo
NugetRepositorySourceUrl: ${{ vars.NUGET_REPOSITORY_SOURCE_URL }}
NugetRepositoryPublishUrl: ${{ vars.NUGET_REPOSITORY_PUBLISH_URL }}
You can automatically update the module version on change. This feature is inspired from powershellexplained.com
To use this feature enable it:
AutoVersion: true
You should also use "autocommit" for adding the changed version to your git repostiory. (It stores a fingerprint, and the current version).
I recommend your this step for it:
- name: Commit new version back
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'CICD: Updated PSVersion'
commit_user_name: CICD
This feature requires the action tj-actions/changed-files
configured like that:
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: Modules/**
json: true
escape_json: false
Now you can passtrough the changed files:
ChangedFiles: "${{ steps.changed-files.outputs.all_changed_and_modified_files }}"
ChangedFilesIgnoredExtensions: "md,org"
- You're writing a PowerShell script module (not a compiled module)
- Your module is contained within a subfolder of your GitHub repository