diff --git a/.github/scripts/cross.sh b/.github/scripts/cross.sh index 07017192..a52f0873 100755 --- a/.github/scripts/cross.sh +++ b/.github/scripts/cross.sh @@ -1,9 +1,16 @@ #!/bin/bash -set -x +# set -x set -e -if [ "$CROSS" != 1 ]; then +if [ "$BUILD_CMD" != "cross" ]; then + echo "cross.sh - is a helper to assist only in cross compiling environments" >&2 + echo "To use this tool set the BUILD_CMD env var to the \"cross\" value" >&2 + exit 111 +fi + +if [ -z "$CROSS_IMAGE" ]; then + echo "The CROSS_IMAGE env var should be provided" >&2 exit 111 fi diff --git a/.github/scripts/make.sh b/.github/scripts/make.sh index 62aa0c06..79192541 100755 --- a/.github/scripts/make.sh +++ b/.github/scripts/make.sh @@ -1,9 +1,9 @@ #!/bin/bash -set -x +# set -x set -e -if [ "$CROSS" = 1 ]; then +if [ "$BUILD_CMD" == "cross" ]; then if [ -z "$CC" ]; then echo "make.sh: CC is not set" >&2 exit 111 diff --git a/.github/scripts/tree-sitter.sh b/.github/scripts/tree-sitter.sh index 2e6e31c2..0cac9153 100755 --- a/.github/scripts/tree-sitter.sh +++ b/.github/scripts/tree-sitter.sh @@ -1,11 +1,27 @@ #!/bin/bash -set -x +# set -x set -e +if [ -z "$ROOT" ]; then + echo "The ROOT env var should be set to absolute path of a repo root folder" >&2 + exit 111 +fi + +if [ -z "$TARGET" ]; then + echo "The TARGET env var should be equal to a \`cargo build --target \` command value" >&2 + exit 111 +fi + tree_sitter="$ROOT"/target/"$TARGET"/release/tree-sitter -if [ "$CROSS" = 1 ]; then +if [ "$BUILD_CMD" == "cross" ]; then + if [ -z "$CROSS_RUNNER" ]; then + echo "The CROSS_RUNNER env var should be set to a CARGO_TARGET_*_RUNNER env var value" >&2 + echo "that is available in a docker image used by the cross tool under the hood" >&2 + exit 111 + fi + cross.sh $CROSS_RUNNER "$tree_sitter" "$@" else "$tree_sitter" "$@" diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index c8a9e4c3..941cec2a 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -24,14 +24,14 @@ jobs: steps: - name: Get PR head ref if: ${{ github.event_name == 'pull_request' }} - id: ref + id: pr_head_ref run: | echo "ref=refs/pull/${{ github.event.pull_request.number }}/head" >> $GITHUB_OUTPUT outputs: ref: >- ${{ (github.event_name == 'pull_request' && startsWith(github.head_ref, 'release/v')) - && steps.ref.outputs.ref + && steps.pr_head_ref.outputs.ref || github.ref }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68ba8ce4..3f7452e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -113,16 +113,16 @@ jobs: env: RUST_TEST_THREADS: ${{ matrix.rust-test-threads }} USE_CROSS: ${{ matrix.use-cross }} + TARGET: ${{ matrix.target }} CC: ${{ matrix.cc }} AR: ${{ matrix.ar }} run: | PATH="$PWD/.github/scripts:$PATH" echo "$PWD/.github/scripts" >> $GITHUB_PATH - echo "TREE_SITTER=tree-sitter.sh" >> $GITHUB_ENV - echo "ROOT=$PWD" >> $GITHUB_ENV - export TARGET=${{ matrix.target }} + echo "TREE_SITTER=tree-sitter.sh" >> $GITHUB_ENV echo "TARGET=$TARGET" >> $GITHUB_ENV + echo "ROOT=$PWD" >> $GITHUB_ENV [ -n "$RUST_TEST_THREADS" ] && \ echo "RUST_TEST_THREADS=$RUST_TEST_THREADS" >> $GITHUB_ENV @@ -132,8 +132,7 @@ jobs: if [ "$USE_CROSS" == "true" ]; then echo "BUILD_CMD=cross" >> $GITHUB_ENV - export CROSS=1; echo "CROSS=1" >> $GITHUB_ENV - runner=$(cross.sh bash -c "env | sed -nr '/^CARGO_TARGET_.*_RUNNER=/s///p'") + runner=$(BUILD_CMD=cross cross.sh bash -c "env | sed -nr '/^CARGO_TARGET_.*_RUNNER=/s///p'") [ -n "$runner" ] && echo "CROSS_RUNNER=$runner" >> $GITHUB_ENV fi @@ -142,30 +141,30 @@ jobs: run: make.sh CFLAGS="-Werror" -j - name: Build wasm library - if: ${{ !matrix.use-cross && !matrix.cli-only }} + if: ${{ !matrix.use-cross && !matrix.cli-only }} # No sense to build on the same Github runner hosts many times run: script/build-wasm - name: Build CLI run: $BUILD_CMD build --release --target=${{ matrix.target }} - name: Fetch fixtures - if: ${{ !matrix.cli-only }} + if: ${{ !matrix.cli-only }} # Don't fetch fixtures for only CLI building targets run: script/fetch-fixtures - name: Generate fixtures - if: ${{ !matrix.cli-only }} # Can't natively run CLI on runner's host + if: ${{ !matrix.cli-only }} # Can't natively run CLI on Github runner's host run: script/generate-fixtures - name: Generate WASM fixtures - if: ${{ !matrix.use-cross && !matrix.cli-only }} + if: ${{ !matrix.use-cross && !matrix.cli-only }} # See comment for the "Build wasm library" step run: script/generate-fixtures-wasm - name: Run main tests - if: ${{ !matrix.cli-only }} # Can't natively run CLI on runner's host + if: ${{ !matrix.cli-only }} # Can't natively run CLI on Github runner's host run: $BUILD_CMD test --target=${{ matrix.target }} - name: Run wasm tests - if: ${{ !matrix.use-cross && !matrix.cli-only }} + if: ${{ !matrix.use-cross && !matrix.cli-only }} # See comment for the "Build wasm library" step run: script/test-wasm - name: Run benchmarks