Add CI job to build and test with stack #43
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build & test | |
| on: [push] | |
| env: | |
| BAZEL_ARGS: --repository_cache=~/repo-cache --disk_cache=~/disk-cache | |
| # Bump this number to invalidate the GH actions cache | |
| cache-version: 0 | |
| jobs: | |
| run-tests-with-ubuntu: | |
| name: Run Tests with ubuntu runner | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: cachix/install-nix-action@v22 | |
| - name: Configure | |
| run: | | |
| mkdir -p ~/repo-cache ~/disk-cache | |
| echo build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host > .bazelrc.local | |
| - name: Mount Bazel cache | |
| uses: actions/cache/restore@v3 | |
| if: github.ref != 'refs/heads/master' | |
| id: restore-cache | |
| with: | |
| path: | | |
| ~/repo-cache | |
| ~/disk-cache | |
| key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| restore-keys: | | |
| repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}- | |
| - run: | | |
| nix-shell --pure --run "bazel test --test_output=all //... $BAZEL_ARGS" | |
| - uses: actions/cache/save@v3 | |
| if: github.ref == 'refs/heads/master' | |
| with: | |
| path: | | |
| ~/repo-cache | |
| ~/disk-cache | |
| key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| run-tests-with-stack: | |
| name: Run Tests with stack | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: cachix/install-nix-action@v22 | |
| - name: Configure | |
| run: | | |
| mkdir -p ~/repo-cache ~/disk-cache | |
| echo build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host > .bazelrc.local | |
| - name: Get Stack snapshot install directory | |
| id: stack-snapshot | |
| # NOTE: `stack path` must run at least once prior to caching to ensure the directory | |
| # exists and is populated. | |
| run: | | |
| stack --nix path --snapshot-install-root | |
| echo "dir=$(stack --nix path --snapshot-install-root)" > "${GITHUB_OUTPUT}" | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.stack-snapshot.outputs.dir }} | |
| key: ${{ runner.os }}-stack-${{ hashFiles('**/*.cabal') }} | |
| restore-keys: ${{ runner.os }}-stack- | |
| - name: Build | |
| run: | | |
| stack --nix build | |
| - name: Test | |
| if: ${{ runner.os == 'Linux' }} | |
| run: | | |
| stack --nix test | |
| run-tests-with-darwin: | |
| name: Run Tests with darwin runner | |
| runs-on: macos-11 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| - name: Install NixOS | |
| uses: cachix/install-nix-action@v22 | |
| with: | |
| nix_path: nixpkgs=./nixpkgs.nix | |
| - name: Configure | |
| run: | | |
| mkdir -p ~/repo-cache ~/disk-cache | |
| echo build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host > .bazelrc.local | |
| - name: Mount Bazel cache | |
| uses: actions/cache/restore@v3 | |
| if: github.ref != 'refs/heads/master' | |
| id: restore-cache | |
| with: | |
| path: | | |
| ~/repo-cache | |
| ~/disk-cache | |
| key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| restore-keys: | | |
| repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}- | |
| - name: Prefetch Stackage snapshot | |
| shell: bash | |
| run: | | |
| set -e -o pipefail | |
| nix-shell --pure --run "cmd='bazel fetch @stackage//... $BAZEL_ARGS'; \$cmd || \$cmd || \$cmd" | |
| - name: Build all | |
| shell: bash | |
| run: | | |
| set -e -o pipefail | |
| nix-shell --pure --run 'bazel build //... $BAZEL_ARGS' | |
| - name: Run tests | |
| shell: bash | |
| run: | | |
| set -e -o pipefail | |
| # Keep CI awake | |
| while true; do echo "."; sleep 60; done & | |
| nix-shell --pure --run 'bazel test //... $BAZEL_ARGS' | |
| - uses: actions/cache/save@v3 | |
| if: github.ref == 'refs/heads/master' | |
| with: | |
| path: | | |
| ~/repo-cache | |
| ~/disk-cache | |
| key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}-${{ github.run_id }}-${{ github.run_attempt }} | |