I don't release CPAN modules so often, but when I do, I try to do it with class! π
Some days ago, I got the idea that it could be nice to have a Github action to automatically upload a distribution to CPAN.
I wondered how to upload a distribution from command line (I never needed such thing) and luckily there is already a perfect existing solution for this: cpan-upload
I never created before a Github action but surprisingly it is very easy. There are 2 types of actions:
I started with javascript version but since it required more customization, I quickly switched to dockerfile action.
So finally here is it:
thibaultduponchelle/action-upload-to-cpan β¨
I tested it with Acme::Automatix
The yml file describing the process of building and releasing my repository source code is like this:
on: [push]
jobs:
build-and-release:
runs-on: ubuntu-latest
name: Build and release Acme::Automatix to CPAN
steps:
- uses: actions/checkout@v2
- name: Configure
run: perl Makefile.PL
- name: Build
run: make
- name: Deliver locally
run: make dist
- name: Upload to CPAN
id: upload
uses: thibaultduponchelle/action-upload-to-cpan@master
with:
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
Since credentials are required to upload to CPAN, you have to give your username and password, but you don't want to share them with everybody so you have to put them in as "secrets". Go to "Settings" then "Secrets" and you can add your secret credentials.
Only the password is really secret, so I can show you how I added my username (yes I'm "CONTRA" on CPAN):
And later they well appear obfuscated in the logs π
By default, upload-to-cpan
will try to upload any tarball in the root directory of your github repo (could maybe change that in the future). Also I'm using @master
version of the action but this will change in the future.
If you forget to update the version, the releasing with fail with a "conflict".
You can be smarter than me and introduce conditions to upload (only release when merging on a "production" branch, or only release on tagging...)
Conclusion
I really think this action is useful and since I wrote it, I discovered that these kind of things exist for other ecosystems (e.g. rubygems, pypi...) so it confirmed my feeling π
Then all that remains is to wish you Happy releasing! β¨
Top comments (2)
I'm not clear. Is this action run on every commit, or only when you choose to run it?
In my example with
on: [push]
it is executed on each commit.This part is up to you to decide (as the build of the module), this is why I say that you can customize more (because each commit does not always imply a delivery to CPAN).