Skip to content

Commit

Permalink
ci: Build and release dkml and with-dkml
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Nov 23, 2023
1 parent 944d811 commit fdb5506
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/dkml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,39 @@ jobs:
- name: Teardown DkML compilers on a Linux host
if: startsWith(matrix.dkml_host_abi, 'linux_')
uses: ./.ci/dkml-compilers/gh-linux/post

# Upload artifact

- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.dkml_host_abi }}
path: dist/

#--------
# Release
#--------

release:
runs-on: ubuntu-latest
permissions:
contents: write # Needed for softprops/action-gh-release@v1
# Wait until `build` complete
needs:
- build
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
path: dist

- name: Restructure multi-ABI directories
run: ci/prepare-release.sh

- name: Release (only when Git tag pushed)
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
_release/*
59 changes: 58 additions & 1 deletion ci/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ if [ -x /usr/bin/cygpath ]; then
PROJECT_DIR=$(/usr/bin/cygpath -au "$PROJECT_DIR")
fi

dkml_version=$(cat "$PROJECT_DIR/src/runtimelib/version.txt")

# shellcheck disable=SC2154
echo "
=============
build-test.sh
=============
.
----
DkML
----
$dkml_version
.
---------
Arguments
---------
Expand Down Expand Up @@ -78,6 +85,56 @@ opamrun exec -- ocamlc -config
# Update
opamrun update

# Reset repository to match the current version of DkML, not the dkml-workflows' version
opamrun repository remove diskuv --all || true
opamrun repository add diskuv "git+https://github.com/diskuv/diskuv-opam-repository.git#$dkml_version"

# Make your own build logic! It may look like ...
opamrun install . --deps-only --with-test --yes
opamrun exec -- dune runtest
case "$dkml_host_abi" in
darwin_x86_64)
toolchain=darwin_arm64;;
*)
toolchain=''
esac
if [ -n "$toolchain" ]; then
opamrun exec -- dune build -x "$toolchain"
else
opamrun exec -- dune build
fi

# ------------ Verbatim from diskuvbox (plus for OPAM_PKGNAME loop) --------------

# Prereq: Diagnostics
case "${dkml_host_abi}" in
linux_*)
if command -v apk; then
apk add file
fi ;;
esac

# Copy the installed binaries (including cross-compiled ones) from Opam into dist/ folder.
# Name the binaries with the target ABI since GitHub Releases are flat namespaces.
install -d dist/
mv _build/install/default "_build/install/default.${dkml_host_abi}"
set +f
for OPAM_PKGNAME in dkml with-dkml; do
for i in _build/install/default.*; do
target_abi=$(basename "$i" | sed s/default.//)
if [ -e "_build/install/default.${target_abi}/bin/${OPAM_PKGNAME}.exe" ]; then
install -v "_build/install/default.${target_abi}/bin/${OPAM_PKGNAME}.exe" "dist/${target_abi}-${OPAM_PKGNAME}.exe"
file "dist/${target_abi}-${OPAM_PKGNAME}.exe"
else
install -v "_build/install/default.${target_abi}/bin/${OPAM_PKGNAME}" "dist/${target_abi}-${OPAM_PKGNAME}"
file "dist/${target_abi}-${OPAM_PKGNAME}"
fi
done
done

# For Windows you must ask your users to first install the vc_redist executable.
# Confer: https://github.com/diskuv/dkml-workflows#distributing-your-windows-executables
case "${dkml_host_abi}" in
windows_x86_64) wget -O dist/vc_redist.x64.exe https://aka.ms/vs/17/release/vc_redist.x64.exe ;;
windows_x86) wget -O dist/vc_redist.x86.exe https://aka.ms/vs/17/release/vc_redist.x86.exe ;;
windows_arm64) wget -O dist/vc_redist.arm64.exe https://aka.ms/vs/17/release/vc_redist.arm64.exe ;;
esac
18 changes: 18 additions & 0 deletions ci/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# ------------ Verbatim from diskuvbox --------------
set -euf

# Restructure multi-ABI directories
_release="$(pwd)/_release"
install -d "$_release"

cd dist
find . -mindepth 1 -maxdepth 1 -type d | while read -r distname; do
rsync -av "$distname/" "$_release"
done
cd ..

# Display files to be distributed
cd _release
ls -R
cd ..

0 comments on commit fdb5506

Please sign in to comment.