Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit fbedf11

Browse files
committed
Add shell script that builds dune and makes tarball
This makes it easier to test the binary distro offline since the tarball has the same logic as the release github action (which now just runs the script). This also makes it more reliable to test the build and packaging process since the script can be run from a test setting, so this change also introduces a github action that runs such a test. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
1 parent 62f9c04 commit fbedf11

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ jobs:
2525
- run: echo NAME=dune-${{ github.ref_name }}-${{ matrix.name }} >> $GITHUB_ENV
2626
- uses: actions/checkout@v4
2727
- uses: cachix/install-nix-action@v31
28-
- name: Build dune
29-
run: nix build ${{ matrix.output }}
30-
- name: Create dune tarball
31-
run: |
32-
cp -rL result $NAME
33-
chmod -R u+w $NAME
34-
tar czf $NAME.tar.gz $NAME
28+
- name: Build the binary distro and package it as a tarball
29+
- run: ./make_tarball.sh $NAME ${{ matrix.output }}
3530
- uses: ncipollo/release-action@v1
3631
with:
3732
allowUpdates: true

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: test
2+
on: [push, pull_request]
3+
jobs:
4+
5+
test-make-tarball:
6+
name: "Test that we can build the binary distro and package it as a tarball"
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
include:
11+
- os: macos-13
12+
name: x86_64-apple-darwin
13+
output: .#dune.dynamic
14+
- os: macos-14
15+
name: aarch64-apple-darwin
16+
output: .#dune.dynamic
17+
- os: ubuntu-latest
18+
name: x86_64-unknown-linux-musl
19+
output: .#dune.static
20+
steps:
21+
- run: echo NAME=dune-${{ matrix.name }} >> $GITHUB_ENV
22+
- uses: actions/checkout@v4
23+
- if: matrix.os == 'ubuntu-latest'
24+
name: "Install shells on ubuntu"
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y zsh fish
28+
- if: matrix.os != 'ubuntu-latest'
29+
name: "Install shells on macos"
30+
run: brew install fish
31+
- uses: cachix/install-nix-action@v31
32+
- name: "Build the binary distro and package it as a tarball"
33+
run: ./make_tarball.sh $NAME ${{ matrix.output }}
34+
- name: "Test that we can extract the tarball and run the env scripts and dune executable"
35+
run: |
36+
tar xf $NAME.tar.gz
37+
bash -c "source $NAME/share/dune/env/env.bash; __dune_env $PWD/$NAME; dune --version"
38+
zsh -c "source $NAME/share/dune/env/env.zsh; __dune_env $PWD/$NAME; dune --version"
39+
fish -c "source $NAME/share/dune/env/env.fish; __dune_env $PWD/$NAME; dune --version"
40+
41+
test-make-tarball-shellcheck:
42+
name: "Run shellcheck on the build script"
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- name: "Install shellcheck"
47+
run: |
48+
sudo apt-get update
49+
sudo apt-get install -y shellcheck
50+
- name: "Run shellcheck on the build script"
51+
run: shellcheck make_tarball.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
result
2+
*.tar.gz

make_tarball.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
if [ "$#" -ne "2" ]; then
5+
echo "Usage: $0 NAME TARGET"
6+
echo
7+
echo "Creates a file NAME.tar.gz containing the dune binary distro."
8+
echo "TARGET is the nix target that gets built. It should be one of:"
9+
echo " - .#dune.dynamic (builds a dynamically-linked dune executable)"
10+
echo " - .#dune.static (builds a statically-linked dune executable)"
11+
exit 1
12+
fi
13+
14+
NAME="$1"
15+
TARGET="$2"
16+
17+
set -x
18+
19+
tmp_dir="$(mktemp -d)"
20+
trap 'rm -rf "$tmp_dir"' EXIT
21+
nix build "$TARGET"
22+
cp -rL result "$tmp_dir/$NAME"
23+
chmod -R u+w "$tmp_dir/$NAME"
24+
pushd "$tmp_dir"
25+
tar czf "$NAME.tar.gz" "$NAME"
26+
popd
27+
mv "$tmp_dir/$NAME.tar.gz" .

0 commit comments

Comments
 (0)