Publish your gitlab project to CPAN using App::pause
Many people moved from GitHub to GitLab after annoucing that microsoft bought GitHub. So did I.
After some initial problems with the settling in, it works quite well. GitLab and the integrated CI is very useful to automatically upload your projects to CPAN if all tests are positive.
The steps are quite simple:
1.) Start with some project on gitlab. It doesn’t matter which one.
2.) On gitlab you can configure the some ci settings in your project
- https://gitlab.com/profile/Your-Project/settings/ci_cd
- in Variables you’ve to insert:
-
- PAUSE_USER
-
- PAUSE_PASSWORD
Why here? Because you don’t want to shour your username and passwort in the build log.
These variable are available in the CI-Job
- PAUSE_PASSWORD
3.) Add .gitlab-ci.yml like this example:
image: docker:latest
services:
- docker:dind
stages:
- test
- build
- release
variables:
RELEASE_IMAGE: perl:5.24
UPLOAD_IMAGE: mziescha/perl-app-pause
CONTAINER: perl-critic-test
DIST_NAME: Your-Project
build:
stage: build
script:
- docker run -d -v "$(pwd)":/app -w /app --name $CONTAINER -e 'RELEASE_TESTING=1' -e 'RELEASE_TESTING=1' -e 'AUTHOR_TESTING=1' $RELEASE_IMAGE /bin/sleep infinity
- docker exec $CONTAINER cpanm -q -n --installdeps .
- docker exec $CONTAINER cpanm -q -n Test::Pod Test::Pod::Coverage Devel::Cover::Report::Codecov Test::CheckManifest
- docker exec $CONTAINER prove -v -l t
only:
- master
perl-5-10:
stage: test
script:
- docker run -d -v "$(pwd)":/app -w /app --name $CONTAINER perl:5.10 /bin/sleep infinity
- docker exec $CONTAINER cpanm -q -n --installdeps .
- docker exec $CONTAINER cpanm -q -n File::Slurp Devel::Cover::Report::Codecov
- docker exec $CONTAINER prove -v -l t
except:
- tags
perl-release:
stage: test
script:
- docker run -d -v "$(pwd)":/app -w /app --name $CONTAINER $RELEASE_IMAGE /bin/sleep infinity
- docker exec $CONTAINER cpanm -q -n --installdeps .
- docker exec $CONTAINER cpanm -q -n File::Slurp
- docker exec $CONTAINER prove -v -l t
except:
- tags
release:
stage: release
script:
- docker run -d -v "$(pwd)":/app -w /app --name $CONTAINER -e 'RELEASE_TESTING=1' $RELEASE_IMAGE /bin/sleep infinity
- docker exec $CONTAINER cpanm -q -n --installdeps .
- docker exec $CONTAINER cpanm -q -n Test::CheckManifest
- docker exec $CONTAINER sh -c 'perl Makefile.PL && make test && make dist'
- echo "username=$PAUSE_USER" > "$(pwd)/pause.conf"
- echo "password=$PAUSE_PASSWORD" >> "$(pwd)/pause.conf"
- docker run --rm -v "$(pwd)/pause.conf":/root/pause.conf:ro -v "$(pwd)":/app -w /app $UPLOAD_IMAGE pause upload $(ls $DIST_NAME-*.tar.gz)
- rm -f "$(pwd)/pause.conf"
only:
- tags
So what's happening here? GitLab is starting the two perl test stages on each branch with two different perl versions. On the master branch another job will be started for the build stage, too.
The interesting part now is the release stage: It's only started if a new tag is created.
It runs the tests and after that it will create the dist file. Now the CI is using the configured variables to create the pause.conf
which is used by App::pause. To upload I created a public docker image 'mziescha/perl-app-pause' and run it with the command
pause upload $(ls $DIST_NAME-*.tar.gz)
It's not dangerous to use ls in this case because there is only one dist. And in this way I don't have to care about the version number.
You can find my sample here: Perl::Critic::Policy::Variables::RequireHungarianNotation
Leave a comment