From da366ae1cff254da858223f383ca8878131f683a Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Wed, 29 Sep 2021 07:52:30 -0500 Subject: [PATCH] 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. --- .github/workflows/test.yml | 93 ++++++++++++++++++++++++++++++++++++ Makefile | 58 +++++++++++++++++----- nim_status_lib.nimble | 6 ++- scripts/fetch-brew-bottle.sh | 8 ---- 4 files changed, 142 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5e44476 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/Makefile b/Makefile index 1800ac3..5755327 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/nim_status_lib.nimble b/nim_status_lib.nimble index 4be2350..69a705b 100644 --- a/nim_status_lib.nimble +++ b/nim_status_lib.nimble @@ -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" diff --git a/scripts/fetch-brew-bottle.sh b/scripts/fetch-brew-bottle.sh index bab59e6..1e95b94 100755 --- a/scripts/fetch-brew-bottle.sh +++ b/scripts/fetch-brew-bottle.sh @@ -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)