Skip to content

Commit

Permalink
ci: add release lib workflow (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi authored May 25, 2024
1 parent affa3ba commit 9450784
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 3 deletions.
221 changes: 221 additions & 0 deletions .github/workflows/release-lib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
name: release-lib
on:
push:
tags:
- "lib-v*"
pull_request:
branches:
- main
paths:
- .github/workflows/release-lib.yml
- src/rust/**
- src/Makevars*
- tools/**
- "!tools/lib-sums.tsv"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

env:
LIB_NAME: libr_glaredb

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
# TODO: Can't build for arm64 Linux for now
# - os: ubuntu-22.04
# target: aarch64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
# TODO: Can't build for Windows for now
# - os: windows-latest
# target: x86_64-pc-windows-gnu
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: ilammy/setup-nasm@v1
if: runner.os == 'Windows'

- name: prep Rust
working-directory: src/rust
run: |
LIB_VERSION="$(cargo metadata --format-version=1 --no-deps | jq --raw-output '.packages[0].version')"
echo "LIB_VERSION=${LIB_VERSION}" >>"$GITHUB_ENV"
rustup target add ${{ matrix.target }}
# savvy needs R_INCLUDE_DIR envvar
echo R_INCLUDE_DIR="$(Rscript -e 'cat(normalizePath(R.home(\"include\")))')" >>"$GITHUB_ENV"
- uses: Swatinem/rust-cache@v2
with:
workspaces: "src/rust -> target"
shared-key: ${{ matrix.target }}-release

- name: prep for arm64 Linux
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >>"$GITHUB_ENV"
echo 'CC=aarch64-linux-gnu-gcc' >>"$GITHUB_ENV"
echo 'CXX=aarch64-linux-gnu-g++' >>"$GITHUB_ENV"
echo 'AR=aarch64-linux-gnu-ar' >>"$GITHUB_ENV"
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
Ncpus: 2

- name: build lib
env:
NOT_CRAN: "true"
DEBUG: "" # TODO: allow set to `false`
TARGET: ${{ matrix.target }}
working-directory: src
run: |
# make sure savvy is built from source because rust-cache doesn't work well.
(find ~/.cargo/registry/ rust/target -name 'savvy-*' | xargs rm -rf) || true
LIB_PATH="$(pwd)/rust/target/${TARGET}/release/${LIB_NAME}.a"
ARTIFACT_NAME="${LIB_NAME}-${LIB_VERSION}-${TARGET}.tar.gz"
# Rinternals header is needed
pushd ..
Rscript -e 'install.packages(c("pkgbuild", "nanoarrow"))'
Rscript -e 'pkgbuild::compile_dll(debug = FALSE)'
popd
tar -czf "../${ARTIFACT_NAME}" -C "rust/target/${TARGET}/release" "${LIB_NAME}.a"
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >>"$GITHUB_ENV"
- name: upload artifact
uses: actions/upload-artifact@v4
with:
name: libs-${{ matrix.target }}
path: ${{ env.ARTIFACT_NAME }}

test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
# TODO: Can't build for Windows for now
# - windows-latest
- ubuntu-22.04
r:
- oldrel-1
- release
- devel
exclude:
- os: macos-latest
r: devel
- os: macos-latest
r: oldrel-1
include:
- os: macos-12
r: release

permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: prep Rust
working-directory: src/rust
run: |
LIB_VERSION="$(cargo metadata --format-version=1 --no-deps | jq --raw-output '.packages[0].version')"
echo "LIB_VERSION=${LIB_VERSION}" >>"$GITHUB_ENV"
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "LIB_TARGET=x86_64-pc-windows-gnu" >>"$GITHUB_ENV"
else
echo "LIB_TARGET=$(rustc -vV | grep host | cut -d' ' -f2)" >>"$GITHUB_ENV"
fi
rm "$(rustup which cargo)"
- uses: actions/download-artifact@v4
with:
name: libs-${{ env.LIB_TARGET }}
path: libs

- name: prep lib
run: |
ARTIFACT_NAME="${LIB_NAME}-${LIB_VERSION}-${LIB_TARGET}.tar.gz"
mkdir -p "tools"
tar -xzf "libs/${ARTIFACT_NAME}" -C "tools"
rm -rf "libs"
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r }}
use-public-rspm: true
Ncpus: "2"
extra-repositories: https://rpolars.r-universe.dev # For the polars package

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck, any::devtools
needs: check

- name: R test
shell: Rscript {0}
run: |
devtools::load_all()
testthat::test_dir("tests")
release:
needs:
- build
- test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
pattern: libs-*
path: libs
merge-multiple: true

- name: create checksums
working-directory: libs
run: |
sha256sum * >"../sha256sums.txt"
md5sum * >"../md5sums.txt"
- name: create release
uses: softprops/action-gh-release@v2
with:
prerelease: true
files: |
libs/*
sha256sums.txt
md5sums.txt
6 changes: 3 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ check_bin_lib() {
echo "The library was found at <${LIBR_GLAREDB_PATH}>. No need to build it."
echo "--------------------------------------------------------------------"
echo ""
sed -e "s|@RUST_TARGET@||" src/Makevars.in >src/Makevars
sed -e "s|@TARGET@||" src/Makevars.in >src/Makevars
if [ "${LIBR_GLAREDB_PATH}" != "${LIBR_GLAREDB_DEFAULT_PATH}" ]; then
echo ""
echo "------------------------ [COPYING BINARY] ------------------------"
Expand All @@ -74,7 +74,7 @@ check_bin_lib() {
echo "No need to build it."
echo "--------------------------------------------------------------------"
echo ""
sed -e "s|@RUST_TARGET@||" src/Makevars.in >src/Makevars
sed -e "s|@TARGET@||" src/Makevars.in >src/Makevars
exit 0
elif [ "${LIBR_GLAREDB_BUILD}" = "false" ]; then
echo ""
Expand Down Expand Up @@ -115,4 +115,4 @@ else
fi

TARGET="${TARGET:-${HOST_TRIPLE}}"
sed -e "s/@TARGET@/${TARGET}/" src/Makevars.in >src/Makevars
sed -e "s|@TARGET@|${TARGET}|" src/Makevars.in >src/Makevars
1 change: 1 addition & 0 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TARGET = @TARGET@

# catch DEBUG envvar, which is passed from pkgbuild::compile_dll()
# TODO: if debug=false, the profile is set to `falserelease`
PROFILE = $(subst x,release,$(subst truex,dev,$(DEBUG)x))

LIBNAME = libr_glaredb.a
Expand Down

0 comments on commit 9450784

Please sign in to comment.