One of those 500 packages was mine, I added another to their number just an hour ago, and I've got two more in the oven. Given, then, that I'm starting to maintain a few packages, I went to the trouble of automating the Hackage release process, and in this post I'm going to briefly walk through setting up this automated environment.
- Install cabal-upload from Hackage. I'm afraid that at the time of writing this is not perfectly simple because it won't build with GHC 6.8 or above: this can be fixed with a new .cabal file, however, which I've made available here. (Edit: I've just noticed that this functionality seems to have been added to Cabal itself! You may just be able to use cabal upload. However, I'm not sure what the right config file location is for the next step).
- Add a file containing your Hackage username and password in the format ("username","password") called ~/.cabal-upload/auth.
- Copy the following shell script into a file called release in the root of your project (the same directory as the Setup.lhs file):
#!/bin/bash # echo "Have you updated the version number? Type 'yes' if you have!" read version_response if [ "$version_response" != "yes" ]; then echo "Go and update the version number" exit 1 fi sdist_output=`runghc Setup.lhs sdist` if [ "$?" != "0" ]; then echo "Cabal sdist failed, aborting" exit 1 fi # Want to find a line like: # Source tarball created: dist/ansi-terminal-0.1.tar.gz # Test this with: # runghc Setup.lhs sdist | grep ... filename=`echo $sdist_output | sed 's/.*Source tarball created: \([^ ]*\).*/\1/'` echo "Filename: $filename" if [ "$filename" = "$sdist_output" ]; then echo "Could not find filename, aborting" exit 1 fi # Test this with: # echo dist/ansi-terminal-0.1.tar.gz | sed ... version=`echo $filename | sed 's/^[^0-9]*\([0-9\.]*\).tar.gz$/\1/'` echo "Version: $version" if [ "$version" = "$filename" ]; then echo "Could not find version, aborting" exit 1 fi echo "This is your last chance to abort! I'm going to upload in 10 seconds" sleep 10 git tag "v$version" if [ "$?" != "0" ]; then echo "Git tag failed, aborting" exit 1 fi # You need to have stored your Hackage username and password as directed by cabal-upload # I use -v5 because otherwise the error messages can be cryptic cabal-upload -v5 $filename if [ "$?" != "0" ]; then echo "Hackage upload failed, aborting" exit 1 fi # Success! exit 0
- When you're ready to release something, simply run the shell script! Not only will this package up your project and upload it to Hackage, it will also add a version tag to your Git repository (obviously you should change this bit if you are using another VCS!).
If you would like to follow my continuing adventures in Haskell open source, please check out my GitHub profile! Patches gratefully accepted