diff --git a/.github/actions/common_setup/action.yaml b/.github/actions/common_setup/action.yaml index 5045edf7..ab3209ee 100644 --- a/.github/actions/common_setup/action.yaml +++ b/.github/actions/common_setup/action.yaml @@ -30,13 +30,13 @@ runs: fi - name: Install Nix - uses: cachix/install-nix-action@v16 + uses: cachix/install-nix-action@v27 with: extra_nix_config: | system-features = kvm trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= substituters = https://hydra.iohk.io https://cache.nixos.org/ - - uses: cachix/cachix-action@v10 + - uses: cachix/cachix-action@v15 with: name: typeable authToken: "${{ inputs.authToken }}" diff --git a/.github/workflows/github-actions-image.yaml b/.github/workflows/github-actions-image.yaml index 57cf6488..79e3fefd 100644 --- a/.github/workflows/github-actions-image.yaml +++ b/.github/workflows/github-actions-image.yaml @@ -9,29 +9,34 @@ on: types: [prereleased] jobs: - check-formatting: - name: Check Haskell formatting +# check-formatting: +# name: Check Haskell formatting +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# +# - name: Common setup +# uses: ./.github/actions/common_setup +# with: +# authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} +# +# - name: Run fourmolu +# run: | +# nix-shell nix/ci.nix -j auto --run "git ls-files '*.hs' | xargs fourmolu -m inplace -o -XRecursiveDo -o -XTypeApplications -o -XPatternSynonyms -o -XBangPatterns" +# git diff --exit-code + + check_versions: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + submodules: recursive - name: Common setup uses: ./.github/actions/common_setup with: authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} - - name: Run fourmolu - run: | - nix-shell nix/ci.nix -j auto --run "git ls-files '*.hs' | xargs fourmolu -m inplace -o -XRecursiveDo -o -XTypeApplications -o -XPatternSynonyms -o -XBangPatterns" - git diff --exit-code - - check_versions: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - name: Check library version if: github.event_name == 'release' run: | @@ -154,13 +159,18 @@ jobs: tag: ${{ github.ref }} dist: - needs: check_versions + needs: [check_versions, Linux] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: submodules: recursive + - name: Common setup + uses: ./.github/actions/common_setup + with: + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + - name: Cache uses: actions/cache@v1 with: @@ -179,7 +189,7 @@ jobs: - name: Build dist run: | - stack sdist --pvp-bounds both --test-tarball + stack sdist --pvp-bounds both echo "distPath=$(stack path | awk -F ": " '/dist-dir/ {print $2}')" >> $GITHUB_ENV - name: Upload compaREST sources artifact @@ -203,7 +213,7 @@ jobs: env: HACKAGE_KEY: ${{ secrets.HACKAGE_KEY }} run: | - stack upload --pvp-bounds both --test-tarball --candidate . + stack upload --pvp-bounds both --candidate . macOS: needs: check_versions @@ -242,39 +252,39 @@ jobs: file: compaREST-macOS-x86.zip tag: ${{ github.ref }} - Linux-Windows: - needs: check_versions - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Common setup - uses: ./.github/actions/common_setup - with: - authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} - - - name: Build Windows binary - run: | - cp -LR $(nix-build -A WindowsCompaRESTBin -j auto --no-out-link)/bin compaREST - - - name: Upload Windows compaREST bundle - uses: actions/upload-artifact@v2 - with: - name: compaREST binary – Windows - path: compaREST - - - name: Zip Release Assets - if: github.event_name == 'release' - shell: bash - run: | - zip -r compaREST-Windows.zip compaREST - - - name: Upload compaREST binary – Windows to release - if: github.event_name == 'release' - uses: svenstaro/upload-release-action@2.2.1 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: compaREST-Windows.zip - tag: ${{ github.ref }} +# Linux-Windows: +# needs: check_versions +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# with: +# submodules: recursive +# +# - name: Common setup +# uses: ./.github/actions/common_setup +# with: +# authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} +# +# - name: Build Windows binary +# run: | +# cp -LR $(nix-build -A WindowsCompaRESTBin -j auto --no-out-link)/bin compaREST +# +# - name: Upload Windows compaREST bundle +# uses: actions/upload-artifact@v2 +# with: +# name: compaREST binary – Windows +# path: compaREST +# +# - name: Zip Release Assets +# if: github.event_name == 'release' +# shell: bash +# run: | +# zip -r compaREST-Windows.zip compaREST +# +# - name: Upload compaREST binary – Windows to release +# if: github.event_name == 'release' +# uses: svenstaro/upload-release-action@2.2.1 +# with: +# repo_token: ${{ secrets.GITHUB_TOKEN }} +# file: compaREST-Windows.zip +# tag: ${{ github.ref }} diff --git a/default.nix b/default.nix index 66a7daff..bcff6c65 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,13 @@ { sources ? import ./nix/sources.nix , haskellNix ? import sources.haskellNix { inherit system; } -, pkgs ? import haskellNix.sources.nixpkgs-2105 (haskellNix.nixpkgsArgs // { inherit system; }) +, pkgs ? import haskellNix.sources.nixpkgs-2311 (haskellNix.nixpkgsArgs // { inherit system; }) , system ? builtins.currentSystem , nix-filter ? import sources.nix-filter }: let masterPkgs = import sources.nixpkgs { inherit system; }; + yq = import ./nix/yq.nix { pkgs = masterPkgs; }; + diffYaml = import ./nix/diff-yaml.nix { pkgs = masterPkgs; }; hsPkgs = pkgs.haskell-nix.stackProject { src = nix-filter { @@ -97,6 +99,18 @@ let }; WindowsCompaRESTBin = hsPkgs.projectCross.mingwW64.hsPkgs.compaREST.components.exes.compaREST; + + # We use the static version so that we don't have to rebuild everything on CI. + # The only binaries build on CI are static. + test = hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.tests.compaREST-tests.overrideAttrs (final: old: { + buildInputs = old.buildInputs ++ [ diffYaml yq ]; + nativeBuildInputs = old.nativeBuildInputs ++ (with masterPkgs; [ makeWrapper ]); + + postInstall = '' + wrapProgram $out/bin/compaREST-tests \ + --prefix PATH : ${masterPkgs.lib.makeBinPath [ diffYaml yq ]} + ''; + }); in { inherit @@ -106,9 +120,6 @@ in compaRESTBin hsPkgs macOSCompaRESTBundle - WindowsCompaRESTBin; - - # We use the static version so that we don't have to rebuild everything on CI. - # The only binaries build on CI are static. - test = hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.tests.compaREST-tests; + WindowsCompaRESTBin + test; } diff --git a/nix/ci.nix b/nix/ci.nix index 397143da..13064637 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -1,6 +1,11 @@ { sources ? import ./sources.nix , pkgs ? import sources.nixpkgs { } }: + +let + yq = import ./yq.nix { inherit pkgs; }; + diff-yaml = import ./diff-yaml.nix { inherit pkgs; }; +in pkgs.mkShell { - packages = [ pkgs.haskellPackages.fourmolu ]; + packages = [ pkgs.haskellPackages.fourmolu diff-yaml yq ]; } diff --git a/nix/diff-yaml.nix b/nix/diff-yaml.nix new file mode 100644 index 00000000..d2630249 --- /dev/null +++ b/nix/diff-yaml.nix @@ -0,0 +1,20 @@ +{ pkgs ? import {} }: + +let + inherit (pkgs) stdenv; + yq = import ./yq.nix { inherit pkgs; }; +in +stdenv.mkDerivation { + name = "diff-yaml"; + + src = ../scripts/diff-yaml; + + buildInputs = [ pkgs.bash yq ]; + + phases = [ "installPhase" ]; + + installPhase = '' + mkdir -p $out/bin + cp $src $out/bin/diff-yaml + ''; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 00000000..e4169443 --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,11 @@ +{ sources ? import ./sources.nix +, pkgs ? import sources.nixpkgs { } +}: + +let + patched-yq = import ./yq.nix { inherit pkgs; }; + diffYaml = import ./diff-yaml.nix { inherit pkgs; }; +in +pkgs.mkShell { + buildInputs = with pkgs; [ pkg-config diffYaml patched-yq zlib ]; +} diff --git a/nix/sources.json b/nix/sources.json index d17905c8..d1acd53e 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "https://input-output-hk.github.io/haskell.nix", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "50c6984263f14c110551a74d36020d0f39160019", - "sha256": "1nbv78127dq01vyhgaw7l6hnz2qdsv115vv2gy4vvayh0y39km91", + "rev": "4413d8325d6359a6be774ef07d9a310ab96c4d25", + "sha256": "0il11752dv2pn47i3kynjfgikfwn2rm4naray89xm8dlgafk90mj", "type": "tarball", - "url": "https://github.com/input-output-hk/haskell.nix/archive/50c6984263f14c110551a74d36020d0f39160019.tar.gz", + "url": "https://github.com/input-output-hk/haskell.nix/archive/4413d8325d6359a6be774ef07d9a310ab96c4d25.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": { @@ -17,22 +17,22 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "9cb7ef336bb71fd1ca84fc7f2dff15ef4b033f2a", - "sha256": "1ajyqr8zka1zlb25jx1v4xys3zqmdy3prbm1vxlid6ah27a8qnzh", + "rev": "f7c538837892dd2eb83567c9f380a11efb59b53f", + "sha256": "0xl33k24vfc29cg9lnp95kvcq69qbq5fzb7jk9ig4lgrhaarh651", "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/9cb7ef336bb71fd1ca84fc7f2dff15ef4b033f2a.tar.gz", + "url": "https://github.com/nmattia/niv/archive/f7c538837892dd2eb83567c9f380a11efb59b53f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nix-filter": { - "branch": "master", + "branch": "main", "description": "a small self-container source filtering lib", "homepage": "", "owner": "numtide", "repo": "nix-filter", - "rev": "38bc843f1ce76958a9f6f0a1e4e3455221c8ecf6", - "sha256": "1lgznp706q5ngyl4zm39j0dlrpam2ds5miiwmc9j9vq4jg5z8sfg", + "rev": "3342559a24e85fc164b295c3444e8a139924675b", + "sha256": "08xia32g5jzaiyhfl3kzxslzbr4w1i56i0mhy5gpfggv8gqy8sym", "type": "tarball", - "url": "https://github.com/numtide/nix-filter/archive/38bc843f1ce76958a9f6f0a1e4e3455221c8ecf6.tar.gz", + "url": "https://github.com/numtide/nix-filter/archive/3342559a24e85fc164b295c3444e8a139924675b.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { @@ -41,10 +41,10 @@ "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "276f639ac2cbfa55beb554e13cc091ecf8a65b19", - "sha256": "1y4ddnwb6y2l0lbs3661ymjlj3m9r2ibv6pfajjdyarmjb7qph1c", + "rev": "3c89ee1b7bc3121a8f7d2303163e45320bb75eba", + "sha256": "1jx033mxi3pcz0whplzni2d7dra95r3pn3vgdrjlrbj26x19j49z", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/276f639ac2cbfa55beb554e13cc091ecf8a65b19.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/3c89ee1b7bc3121a8f7d2303163e45320bb75eba.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/nix/yq.nix b/nix/yq.nix new file mode 100644 index 00000000..05425e22 --- /dev/null +++ b/nix/yq.nix @@ -0,0 +1,26 @@ +{ pkgs ? import {} }: + +# Make yq work inside whatever `stack test` launches. +# Nuke this when https://github.com/kislyuk/yq/pull/193 is merged +# and nixpkgs includes that fix. + +let + yq-patch = pkgs.writeText "yq-tty-fix.patch" '' +diff --git a/yq/__init__.py b/yq/__init__.py +index d95ac4b..ae7d59e 100644 +--- a/yq/__init__.py ++++ b/yq/__init__.py +@@ -110,7 +110,7 @@ def cli(args=None, input_format="yaml", program_name="yq"): + in_place = args.in_place + delattr(args, "in_place") + +- if sys.stdin.isatty() and not args.input_streams: ++ if (sys.stdin is None or sys.stdin.isatty()) and not args.input_streams: + parser.print_help() + sys.exit(2) + elif not args.input_streams: + ''; +in +pkgs.yq.overrideAttrs (final: old: { + patches = old.patches ++ [ yq-patch ]; +}) diff --git a/scripts/diff-yaml b/scripts/diff-yaml new file mode 100755 index 00000000..8d633ed5 --- /dev/null +++ b/scripts/diff-yaml @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -e + +# Normalise YAML files passed as inputs, then run diff on them. + +check_util() { + local util=$1 + + if [ -z $util ]; then + echo "Error: $util not found in PATH" + exit 1 + fi +} + +DIFF=`which diff` +check_util $DIFF + +YQ=`which yq` +check_util $YQ + +# Only normalise YAML files. +# Print anything else as is. +normalise() { + local file=$1 + local contents=($YQ -y -S '.' $file) + + # if $contents contains actual YAML data, print it + if [[ $? == 0 ]]; then + echo $contents + else + cat $file + fi +} + +$DIFF -u <(normalise $1) <(normalise $2) diff --git a/stack.yaml b/stack.yaml index 5e4560ca..16129afc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-22.17 +resolver: lts-22.23 packages: - . @@ -16,4 +16,6 @@ extra-deps: allow-newer: true nix: - packages: [pkg-config zlib] +# packages: [pkg-config yq zlib] + shell-file: ./nix/shell.nix + pure: false diff --git a/test/Spec/Golden/Extra.hs b/test/Spec/Golden/Extra.hs index ae5f800b..24d85fc4 100644 --- a/test/Spec/Golden/Extra.hs +++ b/test/Spec/Golden/Extra.hs @@ -59,7 +59,7 @@ goldenInputsTree :: s -> (t -> IO BSL.ByteString) -> IO TestTree -goldenInputsTree name filepath golden inp f = do +goldenInputsTree name filepath golden inp f = runTestInputTree golden f <$> getGoldenInputs name filepath inp runTestInputTree :: @@ -72,7 +72,7 @@ runTestInputTree golden f (TestInputNode name rest) = runTestInputTree golden f (TestInputLeaf name t path) = goldenVsStringDiff name - (\ref new -> ["diff", "-u", ref, new]) + (\ref new -> ["diff-yaml", ref, new]) (path golden) (f t)