From c45e0c3d7b23f29c88df6ed23ef2a9c10d850d25 Mon Sep 17 00:00:00 2001 From: Martijn Bastiaan Date: Fri, 14 Jan 2022 13:39:56 +0100 Subject: [PATCH] Setup GitHub Actions --- .ci/docker/Dockerfile | 41 --------- .ci/docker/build-and-publish-docker-image.sh | 24 ----- .ci/setup.sh | 26 ------ .ci/test_whitespace.sh | 11 +++ .github/workflows/ci.yml | 96 ++++++++++++++++++++ .gitlab-ci.yml | 48 ---------- stack.yaml | 5 +- 7 files changed, 110 insertions(+), 141 deletions(-) delete mode 100644 .ci/docker/Dockerfile delete mode 100755 .ci/docker/build-and-publish-docker-image.sh delete mode 100755 .ci/setup.sh create mode 100755 .ci/test_whitespace.sh create mode 100644 .github/workflows/ci.yml delete mode 100644 .gitlab-ci.yml diff --git a/.ci/docker/Dockerfile b/.ci/docker/Dockerfile deleted file mode 100644 index 118cb441..00000000 --- a/.ci/docker/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -FROM ubuntu:focal -ARG GHC_VERSION - -ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 LC_ALL=C.UTF-8 PATH=/opt/bin:/root/.ghcup/bin:$PATH - -ENV LATEST_STACK=linux-x86_64.tar.gz -ENV STACK_DEPS="g++ gcc libc6-dev libffi-dev libgmp-dev make xz-utils zlib1g-dev git gnupg netbase" -ARG GHC_DEPS="curl libc6-dev libgmp-dev pkg-config libnuma-dev build-essential" - -ENV CABAL_VERSION=3.2.0.0 - -ARG GHCUP_URL="https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup" -ARG GHCUP_BIN=/root/.ghcup/bin/ghcup - -# Install GHC + Cabal -RUN apt-get update \ - && apt-get install -y $GHC_DEPS curl \ - && mkdir -p $(dirname $GHCUP_BIN) \ - && curl $GHCUP_URL --output $GHCUP_BIN \ - && chmod +x $GHCUP_BIN \ - && ghcup upgrade \ - && ghcup install ghc ${GHC_VERSION} \ - && ghcup set ghc ${GHC_VERSION} \ - && ghcup install cabal ${CABAL_VERSION} \ - && ghcup set cabal ${CABAL_VERSION} - -# Install Stack -RUN apt-get update \ - && apt-get -y install wget \ - && apt-get -y install $STACK_DEPS \ - && wget https://get.haskellstack.org/stable/$LATEST_STACK \ - && tar xzf $LATEST_STACK && rm $LATEST_STACK \ - && mv stack*/stack /usr/bin - -# Clash dependency -RUN apt-get update \ - && apt-get -y install libtinfo-dev - -# Compression utils -RUN apt-get update \ - && apt-get -y install tar zip zstd diff --git a/.ci/docker/build-and-publish-docker-image.sh b/.ci/docker/build-and-publish-docker-image.sh deleted file mode 100755 index aef2d56c..00000000 --- a/.ci/docker/build-and-publish-docker-image.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -set -xeo pipefail - -REPO="docker.pkg.github.com/clash-lang/clash-protocols" -DIR=$(dirname "$0") -now=$(date +%F) - -for GHC_VERSION in "8.6.5" "8.10.2" -do - NAME="protocols-focal-ghc-cabal-stack-${GHC_VERSION}" - - docker build -t "${REPO}/${NAME}:$now" "$DIR" --build-arg GHC_VERSION=${GHC_VERSION} - docker tag "${REPO}/${NAME}:$now" "${REPO}/${NAME}:latest" - - read -p "Push to GitHub? (y/N) " push - - if [[ $push =~ ^[Yy]$ ]]; then - docker push "${REPO}/${NAME}:$now" - docker push "${REPO}/${NAME}:latest" - else - echo "Skipping push to container registry" - fi -done diff --git a/.ci/setup.sh b/.ci/setup.sh deleted file mode 100755 index 43fb83a4..00000000 --- a/.ci/setup.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -set -xou pipefail - -grep \ - -E ' $' -n -r . \ - --include=*.{hs,hs-boot,sh,cabal,md,yml} \ - --exclude-dir=dist-newstyle --exclude-dir=deps -if [[ $? == 0 ]]; then - echo "EOL whitespace detected. See ^" - exit 1; -fi - -set -e - -ghcup set ghc ${GHC_VERSION} -ghcup set cabal ${CABAL_VERSION} - -cabal --version -ghc --version - -# run new-update first to generate the cabal config file that we can then modify -# retry 5 times, as hackage servers are not perfectly reliable -NEXT_WAIT_TIME=0 -until cabal update || [ $NEXT_WAIT_TIME -eq 5 ]; do - sleep $(( NEXT_WAIT_TIME++ )) -done diff --git a/.ci/test_whitespace.sh b/.ci/test_whitespace.sh new file mode 100755 index 00000000..fb4ea880 --- /dev/null +++ b/.ci/test_whitespace.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -xou pipefail + +grep \ + -E ' $' -n -r . \ + --include=*.{hs,hs-boot,sh,cabal,md,yml} \ + --exclude-dir=dist-newstyle --exclude-dir=deps +if [[ $? == 0 ]]; then + echo "EOL whitespace detected. See ^" + exit 1; +fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..7f8e5542 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,96 @@ +name: CI + +# Trigger the workflow on all pull requests and pushes/merges to master branch +on: + pull_request: + push: + branches: [master] + +jobs: + stack: + name: Stack tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Stack / GHC + uses: haskell/actions/setup@v1 + with: + ghc-version: '8.10.7' # Exact version of ghc to use + enable-stack: true + stack-version: 'latest' + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.stack + key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }} + ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}- + ${{ runner.os }}-ghc-${{ matrix.ghc }}- + + # Ask Stack to use system GHC instead of installing its own copy + - name: Use system GHC + run: | + stack config set system-ghc --global true + + - name: Test with Stack + run: | + .ci/test_stack.sh + + cabal: + name: Cabal tests - ${{ matrix.os }} / ghc ${{ matrix.ghc }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + cabal: + - "3.2" + ghc: + - "8.10.7" + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Haskell + uses: haskell/actions/setup@v1 + id: setup-haskell-cabal + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.cabal + key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}-${{ github.sha }} + ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ github.ref }}- + ${{ runner.os }}-ghc-${{ matrix.ghc }}- + + - name: Build + run: | + cabal build all -fci + + - name: Test + run: | + .ci/test_cabal.sh + + - name: Documentation + run: | + .ci/build_docs.sh + + linting: + name: Source code linting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Whitespace + run: | + .ci/test_whitespace.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 803c289a..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,48 +0,0 @@ -.common: - timeout: 1 hour - retry: - max: 2 - when: - - runner_system_failure - - stuck_or_timeout_failure - cache: - key: $CI_JOB_NAME - paths: - - cache.tar.zstd - tags: - - local - before_script: - - export THREADS=$(nproc) - - export CABAL_JOBS=$(nproc) - - tar -xf cache.tar.zstd -C / || true - - .ci/setup.sh - - export - after_script: - - tar -cf - $(ls -d /root/.cabal /root/.stack /nix || true) | zstd -T0 -3 > cache.tar.zstd - -.common-810: - extends: .common - image: docker.pkg.github.com/clash-lang/clash-protocols/protocols-focal-ghc-cabal-stack-8.10.2:2020-12-07 - variables: - GHC_VERSION: "8.10.2" - CABAL_VERSION: "3.2.0.0" - -# Haddock is broken on 865. -haddock: - extends: .common-810 - artifacts: - paths: - - docs/* - expire_in: 1 month - script: - - .ci/build_docs.sh - -cabal-8.10.2: - extends: .common-810 - script: - - .ci/test_cabal.sh - -stack: - extends: .common-810 - script: - - .ci/test_stack.sh diff --git a/stack.yaml b/stack.yaml index 2c9506e2..e4d6850c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2020-12-14 +resolver: lts-18.21 # ghc-8.10.7 packages: - . @@ -9,7 +9,8 @@ extra-deps: subdirs: - hedgehog - git: https://github.com/cchalmers/circuit-notation.git - commit: 0fe897cb95bd1be87abed044f4072f104dec2f7d + commit: 2574640364eef12222517af059b9e4a7e6b503a7 +- clash-prelude-1.2.5 flags: clash-prelude: