Skip to content

Instantly share code, notes, and snippets.

@anmonteiro
Last active March 23, 2025 22:31
Show Gist options
  • Save anmonteiro/abd9275456888740758aa9f772d1992a to your computer and use it in GitHub Desktop.
Save anmonteiro/abd9275456888740758aa9f772d1992a to your computer and use it in GitHub Desktop.

Using dune-release to release OCaml packages

Originally written 2020-05-16

dune-release is a good improvement over the old opam-publish, but releasing software is still clearly not a solved problem, and I find it hard to remember the exact steps involved in releasing an opam package, especially if some time has passed since the last release. This note is an attempt at having a place that I can refer to when occasionally releasing my software to opam.

  1. First things first: lint your opam files:
$ dune-release lint
  1. (Optional) Build a distribution archive to check that the project builds (optionally pass -p pkg1,pkg2) to build just a few packages. I've also found --skip-tests useful here for repos that have e.g. submodules.
$ dune-release distrib
  1. Tag a VCS release in your repository:
$ dune-release tag x.y.z
  1. Distribute the release archive and upload it to GitHub (don't forget to point dune-release at your changelog -- I've found the algorithm for finding the changes file is a little clunky):
$ dune-release distrib && dune-release publish --change-log=./CHANGES.md
  1. Package the opam release:
$ dune-release opam pkg -p pkg1,pkg2 --change-log=./CHANGES.md
  1. Submit the release to the opam repository:
$ dune-release opam submit --change-log=./CHANGES.md
@jchavarri
Copy link

Thanks for this guide!

Just a small note: step 5 requires the DUNE_RELEASE_GITHUB_TOKEN env var to be available in the current session, to make it available:

export DUNE_RELEASE_GITHUB_TOKEN="ghp_<your_GitHub_token>"

@davesnx
Copy link

davesnx commented Feb 10, 2024

Found the same issue but didn't had the env var, but the token was stored: ~/.config/dune/github.token change it and run again

@jchavarri
Copy link

jchavarri commented Feb 16, 2024

the only permission needed for the token is just repo -> public_repo

@jchavarri
Copy link

$ dune-release distrib && dune-release publish distrib --change-log=./CHANGES.md

Apparently dune-release publish distrib is not a thing anymore in 2.1.0:

dune-release: too many arguments, don't know what to do with 'distrib'
Usage: dune-release publish [OPTION]…
Try 'dune-release publish --help' or 'dune-release --help' for more information.

@anmonteiro
Copy link
Author

it's just dune-release publish now, I've edited the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment