Skip to content

Instantly share code, notes, and snippets.

@elijahr
Last active October 11, 2021 08:32
Show Gist options
  • Save elijahr/66e7f4db1e3f474689c4f72deb1191d3 to your computer and use it in GitHub Desktop.
Save elijahr/66e7f4db1e3f474689c4f72deb1191d3 to your computer and use it in GitHub Desktop.
Drop-in multi-architecture testing for Nim projects
# Drop-in multi-architecture testing for Nim projects.
# To use, copy to `.github/workflows/` & enable via Settings → Actions → Allow.
# Push changes to run `nimble test`.
# Tests macos/ubuntu, glibc/musl, gcc/clang and x86/arm/ppc.
# Configure nim-version, os, libc, arch, & cc in ##matrix sections.
# Extra dependencies? Update ##extra-deps sections.
# Author: https://github.com/elijahr
# Source: https://gist.github.com/elijahr/66e7f4db1e3f474689c4f72deb1191d3
# License: MIT
---
# yamllint disable rule:line-length
# yamllint disable rule:comments
# yamllint disable rule:comments-indentation
name: Test
on: # yamllint disable-line rule:truthy
push:
branches:
# - master
- '*'
tags:
- '*'
paths-ignore:
- '*.md'
pull_request:
branches:
- '*'
paths-ignore:
- '*.md'
jobs:
t_unixes:
name: 👑 ${{matrix.nim-version}}/${{matrix.os}}/${{matrix.libc}}/${{matrix.cc}}/x86_64
runs-on: ${{matrix.os}}-latest
timeout-minutes: ${{matrix.timeout-minutes}}
strategy:
fail-fast: false
matrix:
include:
##matrix
- os: ubuntu
nim-version: 1.4.2
cc: gcc
libc: glibc
timeout-minutes: 10
- os: macos
nim-version: 1.4.2
cc: clang
libc: bsd
timeout-minutes: 20
# - os: ubuntu
# nim-version: latest
# cc: gcc
# libc: glibc
# timeout-minutes: 10
# - os: ubuntu
# nim-version: 1.4.2
# cc: clang
# libc: glibc
# timeout-minutes: 10
# - os: ubuntu
# nim-version: 1.2.10
# cc: gcc
# libc: glibc
# timeout-minutes: 10
steps:
- name: 'optimization: restore cached nim→c code'
uses: actions/cache@v2
with:
path: ${HOME}/.cache
key: cache-${{matrix.nim-version}}/${{matrix.os}}/${{matrix.libc}}/${{matrix.cc}}/x86_64
- name: checkout project
uses: actions/checkout@v2
- name: install nim (via asdf-nim)
uses: asdf-vm/actions/install@v1
with:
tool_versions: |
nim ${{matrix.nim-version}}
- name: install clang
if: runner.os == 'Linux' && matrix.cc == 'clang'
run: sudo apt-get update -q -y && sudo apt-get -qq install -y clang
##extra-deps
# - name: install extra dependencies (linux)
# if: runner.os == 'Linux'
# run: sudo apt-get -qq install -y autopoint libssh2-1 libssh2-1-dev
##extra-deps
# - name: install extra dependencies (macOS)
# if: runner.os == 'macOS'
# run: brew install openssl@1.1 automake
- name: 'clang: set CPATH and LIBRARY_PATH'
if: runner.os == 'macOS'
run: |
# Let clang know where to find homebrew include/lib dirs.
# Usually these would have been set in a custom shell init script.
CPATH="$(xcrun --show-sdk-path)"
if [[ "$(uname -m)" == "arm64" ]]; then
# arm64 runners not supported yet, but for when
CPATH="$CPATH:/opt/homebrew/include"
LIBRARY_PATH=/opt/homebrew/lib
else
CPATH="$CPATH:/usr/local/include"
LIBRARY_PATH=/usr/local/lib
fi
echo "CPATH=$CPATH" >> $GITHUB_ENV
echo "LIBRARY_PATH=$LIBRARY_PATH" >> $GITHUB_ENV
- name: nimble test
run: |
. "${HOME}/.asdf/asdf.sh"
asdf local nim ${{matrix.nim-version}}
nimble develop -y
nimble test --cc:${{matrix.cc}}
t_linux_musl:
name: 👑${{matrix.nim-version}}/alpine/musl/gcc/x86_64
runs-on: ubuntu-latest
container: alpine:latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
##matrix
nim-version: [1.4.2]
steps:
- name: 'optimization: restore cached nim→c code'
uses: actions/cache@v2
with:
path: ~/.cache
key: cache-${{matrix.nim-version}}/ubuntu/musl/gcc/x86_64
- name: install dependencies
run: |
apk add --update --no-cache --upgrade \
bash git curl coreutils tar xz grep
git clone https://github.com/asdf-vm/asdf.git "${HOME}/.asdf" \
--branch v0.8.1
##extra-deps
# apk add --no-cache --upgrade \
# autoconf automake
- name: nimble test
run: |
. "${HOME}/.asdf/asdf.sh"
asdf local nim ${{matrix.nim-version}}
nimble develop -y
nimble test --cc:gcc
t_linux_non_x86:
name: 👑${{matrix.nim-version}}/${{matrix.os}}/${{matrix.libc}}/${{matrix.cc}}/${{matrix.arch}}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
##matrix
- os: buster
nim-version: 1.0.10
cc: gcc
libc: glibc
arch: ppc64le
- os: buster
nim-version: 1.2.8
cc: gcc
libc: glibc
arch: aarch64
- os: buster
nim-version: 1.4.2
cc: gcc
libc: glibc
arch: armv7
steps:
- name: 'optimization: restore cached nim→c code'
uses: actions/cache@v2
with:
path: ~/.cache
key: cache-${{matrix.nim-version}}/${{matrix.os}}/${{matrix.libc}}/${{matrix.cc}}/x86_64
- name: checkout project
uses: actions/checkout@v2
- name: install nim, nimble test
uses: uraimo/run-on-arch-action@v2.1.1
with:
arch: ${{matrix.arch}}
distro: ${{matrix.os}}
dockerRunArgs: --volume "${HOME}/.cache:/root/.cache"
setup: mkdir -p "${HOME}/.cache"
shell: /usr/bin/env bash
install: |
apt-get update -q -y
apt-get -qq install -y curl git hub xz-utils build-essential
git clone https://github.com/asdf-vm/asdf.git "${HOME}/.asdf" \
--branch v0.8.1
##extra-deps
# apt-get -qq install -y autopoint
. "${HOME}/.asdf/asdf.sh"
asdf plugin add nim
asdf nim install-deps -y
asdf install nim ${{matrix.nim-version}}
run: |
. "${HOME}/.asdf/asdf.sh"
asdf local nim ${{matrix.nim-version}}
nimble develop -y
nimble test --cc:${{matrix.cc}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment