|
| 1 | +How to Release a Binary Distribution of an Application on Github with Dune |
| 2 | +========================================================================== |
| 3 | + |
| 4 | +This guide will show you how to write a Github Action which builds a binary |
| 5 | +distribution of an application for various platforms using Dune package |
| 6 | +management, and uploads the compiled artifacts to a Github release. |
| 7 | + |
| 8 | +We'll make a workflow called "Release" which will run every time a tag is pushed |
| 9 | +to the repo on Github. The workflow will build the project for the targets |
| 10 | +``x86_64-linux``, ``x86_64-macos``, and ``aarch64-macos``, and then upload a |
| 11 | +gzipped tarball of the built artifacts to a Github release named after the tag. |
| 12 | + |
| 13 | +Dune will be installed by the `setup-dune |
| 14 | +<https://github.com/ocaml-dune/setup-dune>`_ action. |
| 15 | + |
| 16 | +The following is the manifest for a Github Action workflow which releases a |
| 17 | +binary distribution of a package named ``my_app``. |
| 18 | + |
| 19 | +.. code:: yaml |
| 20 | +
|
| 21 | + name: Release |
| 22 | +
|
| 23 | + on: |
| 24 | + push: |
| 25 | + tags: |
| 26 | + - '*' |
| 27 | +
|
| 28 | + jobs: |
| 29 | + release-unix: |
| 30 | + name: Release for ${{ matrix.name }} |
| 31 | + runs-on: ${{ matrix.os }} |
| 32 | + strategy: |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + - os: macos-15-intel |
| 36 | + name: x86_64-macos |
| 37 | + - os: macos-15 |
| 38 | + name: aarch64-macos |
| 39 | + - os: ubuntu-latest |
| 40 | + name: x86_64-linux |
| 41 | + steps: |
| 42 | +
|
| 43 | + - uses: actions/checkout@v5 |
| 44 | +
|
| 45 | + - name: Install Dune |
| 46 | + uses: ocaml-dune/setup-dune@v0 |
| 47 | +
|
| 48 | + - name: Build the project |
| 49 | + run: dune build @install --release --only-packages my_app |
| 50 | +
|
| 51 | + - name: Set environment variable to the archive name minus the file extension |
| 52 | + run: echo OUT_NAME=my_app-${{ github.ref_name }}-${{ matrix.name }} >> $GITHUB_ENV |
| 53 | +
|
| 54 | + - name: Release a tarball of build outputs |
| 55 | + run: | |
| 56 | + mkdir -p "$OUT_NAME" |
| 57 | + cp -rlf _build/install/default/* "$OUT_NAME" |
| 58 | + tar czf "$OUT_NAME.tar.gz" "$OUT_NAME" |
| 59 | +
|
| 60 | + - name: Upload artifacts |
| 61 | + uses: ncipollo/release-action@v1 |
| 62 | + with: |
| 63 | + allowUpdates: true |
| 64 | + artifacts: "*.tar.gz" |
| 65 | +
|
| 66 | +With the above manifest in a file ``.github/workflows/release.yml``, whenever a |
| 67 | +tag is pushed to the repo, gzipped tarballs will be uploaded to a new release of |
| 68 | +the project named after the tag, in files named |
| 69 | +``my_app-<TAG>-x86_64-linux.tar.gz``, ``my_app-<TAG>-x86_64-macos.tar.gz``, and |
| 70 | +``my_app-<TAG>-aarch64-macos.tar.gz``. |
0 commit comments