chore: add GitHub Actions workflow to run tests (#66)

Closes #65.

There's still some work to be done. With the changes in this PR, this project's
Makefile is a bit of a hybrid between the approaches in the Makefiles of
status-desktop and nim-status. In the future, as this project's tests expand in
scope, the logic in the Makefile, `nim_status_lib.nimble`, and/or
`.github/workflows/test.yml` may need to be revised.
This commit is contained in:
Michael Bradley 2021-09-29 07:52:30 -05:00 committed by GitHub
parent b8c729b804
commit da366ae1cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 142 additions and 23 deletions

93
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,93 @@
name: Tests
on:
pull_request:
push:
branches:
- master
jobs:
tests:
env:
NPROC: 2
strategy:
fail-fast: false
matrix:
platform:
- {
icon: 🏁,
os: windows,
shell: msys2
}
- {
icon: 🍎,
os: macos,
shell: bash --noprofile --norc -eo pipefail
}
- {
icon: 🐧,
os: ubuntu,
shell: bash --noprofile --norc -eo pipefail
}
name: ${{ matrix.platform.icon }} ${{ matrix.platform.os }}
runs-on: ${{ matrix.platform.os }}-latest
defaults:
run:
shell: ${{ matrix.platform.shell }} {0}
steps:
- name: Install tools and libraries via Homebrew
if: matrix.platform.os == 'macos'
run: |
brew install coreutils gawk openssl@1.1 pcre
rm -f /usr/local/opt/openssl
ln -s /usr/local/opt/openssl@1.1 /usr/local/opt/openssl
- name: Install tools and libraries via MSYS2
uses: msys2/setup-msys2@v2
if: matrix.platform.os == 'windows'
with:
msystem: UCRT64
update: true
install: >
base-devel
git
unzip
mingw-w64-ucrt-x86_64-go
mingw-w64-ucrt-x86_64-toolchain
mingw-w64-ucrt-x86_64-openssl
mingw-w64-ucrt-x86_64-pcre
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive
- name: Calculate cache key from submodules tree
id: calc-cache-key
run: |
echo "::set-output name=hash::$(git submodule foreach --quiet --recursive 'git rev-parse $(git rev-parse --abbrev-ref HEAD)' | sha1sum | awk '{print $1}')"
- uses: actions/cache@v2
with:
path: |
vendor/nimbus-build-system/vendor/Nim/bin
vendor/status-go/build/bin
key: ${{ matrix.platform.os }}-${{ steps.calc-cache-key.outputs.hash }}
- name: Install and build dependencies
run: |
make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 update
make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 deps
- name: Build and run tests
# using `llvm-ar` instead of `ar` on macOS is a workaround for:
# https://github.com/nim-lang/Nim/issues/15589
run: |
if [[ ${{ matrix.platform.os }} = macos ]]; then
mkdir -p "${HOME}/.local/bin"
ln -f -s /usr/local/Cellar/llvm/*/bin/llvm-ar "${HOME}/.local/bin/ar"
export PATH="${HOME}/.local/bin:${PATH}"
fi
make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 test

View File

@ -65,15 +65,25 @@ else
LIBSTATUS_EXT := so
endif
ifeq ($(detected_OS),Darwin)
bottles/openssl:
./scripts/fetch-brew-bottle.sh openssl
bottles/pcre: bottles/openssl
./scripts/fetch-brew-bottle.sh pcre
bottles: bottles/openssl bottles/pcre
endif
# ifeq ($(detected_OS),Darwin)
# BOTTLES_DIR := $(shell pwd)/bottles
# BOTTLES := $(addprefix $(BOTTLES_DIR)/,openssl@1.1 pcre)
#
# $(BOTTLES): | $(BOTTLES_DIR)
# echo -e "\e[92mFetching:\e[39m $(notdir $@) bottle"
# ./scripts/fetch-brew-bottle.sh $(notdir $@)
#
# $(BOTTLES_DIR):
# echo -e "\e[92mUpdating:\e[39m macOS Homebrew"
# if [[ $$(stat -f %u /usr/local/var/homebrew) -ne "$${UID}" ]]; then \
# echo "Missing permissions to update Homebrew formulae!" >&2; \
# else \
# brew update >/dev/null; \
# mkdir -p $(BOTTLES_DIR); \
# fi
#
# bottles: $(BOTTLES)
# endif
deps: | deps-common bottles
@ -108,7 +118,7 @@ $(STATUSGO): | deps
$(MAKE) statusgo-shared-library $(HANDLE_OUTPUT)
LIBSTATUSLIB := build/$@.$(LIBSTATUS_EXT).0
libstatuslib: | $(STATUSGO)
libstatuslib: | $(STATUSGO)
echo -e $(BUILD_MSG) "$@" && \
$(ENV_SCRIPT) nim c $(NIM_PARAMS) $(NIM_EXTRA_PARAMS) --passL:"-L$(STATUSGO_LIBDIR)" --passL:"-lstatus" -o:build/$@.$(LIBSTATUS_EXT).0 -d:ssl --app:lib --noMain --header --nimcache:nimcache/libstatuslib statuslib.nim && \
rm -f build/$@.$(LIBSTATUS_EXT) && \
@ -122,15 +132,37 @@ build_ctest: | $(LIBSTATUSLIB) build deps
echo -e $(BUILD_MSG) "build/ctest" && \
$(CC) test/main.c -Wl,-rpath,'$$ORIGIN' -I./vendor/nimbus-build-system/vendor/Nim/lib $(EXTRA_LIBS_DYNAMIC) -g -o build/ctest
LD_LIBRARY_PATH_NIMBLE := $${LD_LIBRARY_PATH}
ifneq ($(detected_OS),Windows)
ifneq ($(detected_OS),Darwin)
LD_LIBRARY_PATH_NIMBLE := $(STATUSGO_LIBDIR):$(LD_LIBRARY_PATH_NIMBLE)
endif
endif
PATH_NIMBLE := $${PATH}
ifeq ($(detected_OS),Windows)
PATH_NIMBLE := $(STATUSGO_LIBDIR):$(PATH_NIMBLE)
endif
NIMBLE_ENV = \
RELEASE=$(RELEASE)
ifeq ($(detected_OS),Windows)
NIMBLE_ENV += PATH="$(PATH_NIMBLE)"
PCRE_LDFLAGS := -L$(shell cygpath -m /ucrt64/lib) -lpcre
NIMBLE_ENV += PCRE_LDFLAGS="$(PCRE_LDFLAGS)"
else ifneq ($(detected_OS),Darwin)
NIMBLE_ENV += LD_LIBRARY_PATH="$(LD_LIBRARY_PATH_NIMBLE)"
endif
ctest: | build_ctest
echo -e "Running ctest:" && \
LD_LIBRARY_PATH="$(STATUSGO_LIBDIR)" \
./build/ctest
test: | $(STATUSGO)
$(NIMBLE_ENV) $(ENV_SCRIPT) nimble tests
clean: | clean-common
rm -rf bin/* node_modules bottles/* pkg/* tmp/* $(STATUSGO)
test:
$(ENV_SCRIPT) nimble tests
endif # "variables.mk" was not included

View File

@ -35,9 +35,11 @@ proc buildAndRun(name: string,
exec "nim " &
lang &
(if getEnv("RELEASE").strip != "false": release_opts else: debug_opts) &
(if defined(windows): " --define:usePcreHeader" else: "") &
" --define:ssl" &
" --passL:" & getEnv("STATUSGO") & "" &
# " --passL:" & "vendor/status-go/build/bin/libstatus.dylib" & "" &
" --nimcache:nimcache/" & (if getEnv("RELEASE").strip != "false": "release/" else: "debug/") & name &
(if getEnv("PCRE_LDFLAGS").strip != "": " --passL:\"" & getEnv("PCRE_LDFLAGS") & "\"" else: "") &
" --passL:\"-L" & getEnv("STATUSGO_LIBDIR") & " -lstatus \"" &
" --out:" & outDir & name &
" " &
srcDir & name & ".nim"

View File

@ -43,14 +43,6 @@ else
BEARER_TOKEN=$(get_gh_pkgs_token)
fi
# We want the most recent available version of the package.
if [[ $(stat -f %u /usr/local/var/homebrew) -ne "${UID}" ]]; then
echo "Missing permissions to update Homebrew formulae!" >&2
else
echo "${BOTTLE_NAME} - Updating HomeBrew repository"
brew update >/dev/null
fi
echo "${BOTTLE_NAME} - Finding bottle URL"
BOTTLE_JSON=$(get_bottle_json "${BOTTLE_NAME}")
BOTTLE_URL=$(echo "${BOTTLE_JSON}" | jq -r .url)