DEV Community

Cover image for New Github action to Upload to CPAN

Posted on • Updated on

New Github action to Upload to CPAN

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:


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]

    runs-on: ubuntu-latest
    name: Build and release Acme::Automatix to CPAN
    - 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
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}
Enter fullscreen mode Exit fullscreen mode

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...)


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)

davehodg profile image
Dave Hodgkinson

I'm not clear. Is this action run on every commit, or only when you choose to run it?

thibaultduponchelle profile image
Tib • Edited

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).