Skip to content

Commit

Permalink
Add cabal-gild and update hook
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 3, 2024
1 parent 46097e3 commit 8cbc6d7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/check-cabal-gild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Check cabal-gild format

on:
merge_group:
pull_request:

# When pushing branches (and/or updating PRs), we do want to cancel previous
# build runs. We assume they are stale now; and do not want to spend CI time and
# resources on continuing to continue those runs. This is what the concurrency.group
# value lets us express. When using merge queues, we now have to consider
# - runs triggers by commits per pull-request
# we want to cancel any previous run. So they should all get the same group (per PR)
# - runs refs/heads/gh-readonly-queue/<target branch name> (they should all get their
# unique git ref, we don't want to cancel any of the ones in the queue)
# - if it's neither, we fall back to the run_id (this is a unique number for each
# workflow run; it does not change if you "rerun" a job)
concurrency:
group: ${{ github.workflow }}-${{ github.event.type }}-${{ startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.ref || github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
check-cabal-gild:
runs-on: ubuntu-latest

strategy:
fail-fast: false

env:
CARDANO_GUILD_VERSION: "1.5.0.1"

steps:
- name: Download cardano-gild
run: |
cardano_gild_path="$(mktemp -d)"
version="${{env.CARDANO_GUILD_VERSION}}"
curl -sL \
"https://github.com/tfausak/cabal-gild/releases/download/$version/cabal-gild-$version-linux-x64.tar.gz" \
| tar -C "$cardano_gild_path" -xz
echo "PATH=$cardano_gild_path:$PATH" >> "$GITHUB_ENV"
- uses: actions/checkout@v3

- name: Run cardano-gild over all modified files
run: |
git add .
git stash
git fetch origin ${{ github.base_ref }} --unshallow
for x in $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}..HEAD "*.cabal" | tr '\n' ' '); do
cabal-gild -i "$x" -o "$x"
done
git --no-pager diff --exit-code
1 change: 1 addition & 0 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,4 @@ test-suite cardano-api-golden
, Test.Golden.Cardano.Api.Value
, Test.Golden.Cardano.Api.ProtocolParameters
, Test.Golden.ErrorsSpec

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
haskell-language-server.src = nixpkgs.haskell-nix.sources."hls-2.6";
hlint = "3.6.1";
stylish-haskell = "0.14.5.0";
cabal-gild = "1.3.1.2";
};
# and from nixpkgs or other inputs
shell.nativeBuildInputs = with nixpkgs; [ gh jq yq-go actionlint shellcheck ];
Expand Down
11 changes: 8 additions & 3 deletions scripts/githooks/haskell-style-lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
# This script validates the staged changes in Haskell files using stylish-haskell and hlint and returns non-zero
# code when there are linting or style issues.
#!/usr/bin/env bash
# This script validates the staged changes in Haskell files using stylish-haskell and hlint, and
# in cabal files using cabal-gild. It returns non-zero code when there are linting
# or style issues.
#
# To set this script as your pre-commit hook, use the following command:
#
Expand All @@ -18,6 +19,10 @@ for x in $(git diff --staged --name-only --diff-filter=ACM "*.hs" | tr '\n' ' ')
hlint "$x" || hlint_rc="1"
done

for x in $(git diff --staged --name-only --diff-filter=ACM "*.cabal" | tr '\n' ' '); do
cabal-gild -i "$x" -o "$x"
done

# fail if there are style issues
git --no-pager diff --exit-code || exit 1
# if there are no style issue, there could be hlint issues:
Expand Down

0 comments on commit 8cbc6d7

Please sign in to comment.