diff --git a/.env b/.env new file mode 100644 index 00000000..0fe316bc --- /dev/null +++ b/.env @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# All of the following environment variables are required to set default values +# for the parameters in docker-compose.yml. + +# empty prefix means that the docker-compose configuration will use named +# volumes which potentially improves the performance on docker for macos and +# docker for windows, it also prevents the contamination of the source +# directory +# a non-empty prefix means that directories from the host are bind-mounted +# into the container, it should be set to ".docker/" on github actions to keep +# the cache plugin functional +DOCKER_VOLUME_PREFIX= + +# turn on inline build cache, this is a docker buildx feature documented +# at https://github.com/docker/buildx#--cache-tonametypetypekeyvalue +BUILDKIT_INLINE_CACHE=1 +COMPOSE_DOCKER_CLI_BUILD=1 +DOCKER_BUILDKIT=1 + +# different architecture notations +ARCH=amd64 +ARCH_ALIAS=x86_64 +ARCH_SHORT=amd64 + +# The default Debian version to use for the docker image +DEBIAN=12 + +# Default repository to pull and push images from +REPO=ghcr.io/apache/arrow-js-dev + +# Default versions for various dependencies +NODE=18 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..eaf9c941 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,116 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: NodeJS + + +on: + push: + branches: + - '**' + - '!dependabot/**' + tags: + - '**' + pull_request: + +concurrency: + group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} + cancel-in-progress: true + +permissions: + contents: read + +env: + DOCKER_VOLUME_PREFIX: ".docker/" + +jobs: + + docker: + name: AMD64 Debian 12 NodeJS 18 + runs-on: ubuntu-latest + if: ${{ !contains(github.event.pull_request.title, 'WIP') }} + timeout-minutes: 45 + steps: + - name: Checkout Arrow JS + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + with: + fetch-depth: 0 + - name: Execute Docker Build + run: | + docker compose run debian-js + + macos: + name: AMD64 macOS 13 NodeJS ${{ matrix.node }} + runs-on: macos-13 + if: ${{ !contains(github.event.pull_request.title, 'WIP') }} + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + node: [18] + steps: + - name: Checkout Arrow JS + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Jest Cache + uses: actions/cache@v4 + with: + path: .jest-cache + key: js-jest-cache-${{ runner.os }}-${{ hashFiles('src/**/*.ts', 'test/**/*.ts', 'yarn.lock') }} + restore-keys: js-jest-cache-${{ runner.os }}- + - name: Install NodeJS + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + - name: Build + shell: bash + run: ci/scripts/js_build.sh $(pwd) /tmp/build + - name: Test + shell: bash + run: ci/scripts/js_test.sh /tmp/build + + windows: + name: AMD64 Windows NodeJS ${{ matrix.node }} + runs-on: windows-latest + if: ${{ !contains(github.event.pull_request.title, 'WIP') }} + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + node: [18] + steps: + - name: Checkout Arrow JS + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Jest Cache + uses: actions/cache@v4 + with: + path: .jest-cache + key: js-jest-cache-${{ runner.os }}-${{ hashFiles('src/**/*.ts', 'test/**/*.ts', 'yarn.lock') }} + restore-keys: js-jest-cache-${{ runner.os }}- + - name: Install NodeJS + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + - name: Build + shell: bash + run: ci/scripts/js_build.sh $(pwd) /tmp/build + - name: Test + shell: bash + run: ci/scripts/js_test.sh /tmp/build diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..e69de29b diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 00000000..e69de29b diff --git a/ci/docker/debian-12-js.dockerfile b/ci/docker/debian-12-js.dockerfile new file mode 100644 index 00000000..1c49e77e --- /dev/null +++ b/ci/docker/debian-12-js.dockerfile @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +ARG arch=amd64 +ARG node=18 +FROM ${arch}/node:${node} + +ENV NODE_NO_WARNINGS=1 + +# install rsync for copying the generated documentation +RUN apt-get update -y -q && \ + apt-get install -y -q --no-install-recommends rsync && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* diff --git a/ci/scripts/js_build.sh b/ci/scripts/js_build.sh new file mode 100755 index 00000000..52d06f0f --- /dev/null +++ b/ci/scripts/js_build.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -ex + +source_dir=${1} +build_dir=${2} + +: ${BUILD_DOCS_JS:=OFF} + +# https://github.com/apache/arrow/issues/41429 +# TODO: We want to out-of-source build. This is a workaround. We copy +# all needed files to the build directory from the source directory +# and build in the build directory. +rm -rf ${build_dir}/js +mkdir -p ${build_dir} + +cp -aL ${source_dir}/LICENSE.txt ${build_dir}/ +cp -aL ${source_dir}/NOTICE.txt ${build_dir}/ +cp -aL ${source_dir} ${build_dir}/js +pushd ${build_dir}/js + +yarn --immutable + +yarn lint:ci +yarn build + +if [ "${BUILD_DOCS_JS}" == "ON" ]; then + # If apache or upstream are defined use those as remote. + # Otherwise use origin which could be a fork on PRs. + if [ "$(git -C ${source_dir} config --get remote.apache.url)" == "git@github.com:apache/arrow-js.git" ]; then + yarn doc --gitRemote apache + elif [[ "$(git -C ${source_dir}config --get remote.upstream.url)" =~ "https://github.com/apache/arrow-js" ]]; then + yarn doc --gitRemote upstream + elif [[ "$(basename -s .git $(git -C ${source_dir} config --get remote.origin.url))" == "arrow-js" ]]; then + yarn doc + else + echo "Failed to build docs because the remote is not set correctly. Please set the origin or upstream remote to https://github.com/apache/arrow-js.git or the apache remote to git@github.com:apache/arrow-js.git." + exit 0 + fi + mkdir -p ${build_dir}/docs/js + rsync -a doc/ ${build_dir}/docs/js +fi + +popd diff --git a/ci/scripts/js_test.sh b/ci/scripts/js_test.sh new file mode 100755 index 00000000..a25178d1 --- /dev/null +++ b/ci/scripts/js_test.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -ex + +build_dir=${1}/js + +pushd ${build_dir} + +yarn lint +yarn test +yarn test:bundle + +popd diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..0786ef22 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,54 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Usage +# ----- +# +# The docker compose file is parametrized using environment variables, the +# defaults are set in .env file. +# +# Example: +# $ ARCH=amd64 docker compose build debian-js +# $ ARCH=amd64 docker compose run debian-js + +volumes: + debian-ccache: + name: ${ARCH}-debian-${DEBIAN}-ccache + +services: + debian-js: + # Usage: + # docker compose build debian-js + # docker compose run debian-js + image: ${REPO}:${ARCH}-debian-${DEBIAN}-js-${NODE} + build: + context: . + dockerfile: ci/docker/debian-${DEBIAN}-js.dockerfile + cache_from: + - ${REPO}:${ARCH}-debian-${DEBIAN}-js-${NODE} + args: + arch: ${ARCH} + node: ${NODE} + volumes: &debian-volumes + - .:/arrow-js:delegated + - ${DOCKER_VOLUME_PREFIX}debian-ccache:/ccache:delegated + environment: + BUILD_DOCS_JS: "ON" + command: &js-command > + /bin/bash -c " + /arrow-js/ci/scripts/js_build.sh /arrow-js /build && + /arrow-js/ci/scripts/js_test.sh /build"