diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..890074c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,99 @@ +name: CI + +on: + pull_request: + branches: [master] + push: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ghc-version: ['9.6.7', '9.8.4', '9.10.2', '9.12.2'] + steps: + - uses: actions/checkout@v4 + + - name: Setup Haskell + uses: haskell-actions/setup@v2 + with: + ghc-version: ${{ matrix.ghc-version }} + cabal-version: '3.12' + + - name: Cache cabal packages + uses: actions/cache@v4 + with: + path: | + ~/.cabal/packages + ~/.cabal/store + dist-newstyle + key: ${{ runner.os }}-ghc-${{ matrix.ghc-version }}-cabal-${{ hashFiles('**/*.cabal') }} + restore-keys: | + ${{ runner.os }}-ghc-${{ matrix.ghc-version }}-cabal- + + - name: Build + run: cabal build all + + - name: Run tests + run: cabal test --test-show-details=direct + + benchmark: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Haskell + uses: haskell-actions/setup@v2 + with: + ghc-version: '9.10.3' + cabal-version: '3.12' + + - name: Cache cabal packages + uses: actions/cache@v4 + with: + path: | + ~/.cabal/packages + ~/.cabal/store + dist-newstyle + key: ${{ runner.os }}-cabal-${{ hashFiles('**/*.cabal') }} + restore-keys: | + ${{ runner.os }}-cabal- + + - name: Build + run: cabal build bench + + - name: Run benchmarks + run: cabal run bench -- --csv bench-results.csv + + - name: Upload benchmark results + uses: actions/upload-artifact@v4 + with: + name: benchmark-results + path: bench-results.csv + + fourmolu: + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Install fourmolu + run: | + FOURMOLU_VERSION="0.17.0.0" + BINDIR=$HOME/.local/bin + mkdir -p "$BINDIR" + curl -sSfL "https://github.com/fourmolu/fourmolu/releases/download/v${FOURMOLU_VERSION}/fourmolu-${FOURMOLU_VERSION}-linux-x86_64" -o "$BINDIR/fourmolu" + chmod a+x "$BINDIR/fourmolu" + echo "$BINDIR" >> $GITHUB_PATH + + - name: Run fourmolu + run: ./scripts/fourmolize.sh diff --git a/scripts/fourmolize.sh b/scripts/fourmolize.sh new file mode 100755 index 0000000..71f7620 --- /dev/null +++ b/scripts/fourmolize.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [[ $# -gt 0 ]]; then + case "$1" in + --changes) + # Run fourmolu on changes compared to `master`. + git diff --diff-filter=MA --name-only origin/master HEAD -- '*.hs' + ;; + *) + echo "Invalid option: $1" >&2 + exit 1 + ;; + esac +else + git ls-files -- '*.hs' +fi \ + | { grep -v Setup.hs || true; } \ + | xargs -r fourmolu -m inplace + +git diff --exit-code