about summary refs log tree commit diff
path: root/third_party/bazel/rules_haskell/.circleci/config.yml
blob: 1ec2b1fc0518fed1a0567d4154d3c63609aa866b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
version: 2

# NOTE:
#   Disk cache:
#       We don't want to keep old artifacts around so we always build from
#       scratch on master builds and upload the new cache afterwards. Because
#       Circle doesn't allow skipping a "restore_cache" we create a dummy
#       "empty" cache that's only ever pulled on master. Alternatively we could
#       ask Bazel to clean up old items (LRU style) but the documentation is
#       very terse and I could not figure how to do it:
#           https://docs.bazel.build/versions/master/remote-caching.html
#       It also appears that there's ongoing work but the feature is not ready:
#           https://github.com/bazelbuild/bazel/issues/5139
#
#       Currently the disk cache is only implemented for the Darwin builds,
#       which were the slowest ones. There is no reason why a disk cache
#       couldn't be used for the other jobs: I just haven't gotten around to
#       doing it.

jobs:
  build-linux-ghc-bindist:
    docker:
      - image: debian
    working_directory: ~/rules_haskell
    resource_class: large
    steps:
      - checkout
      - run:
          name: Setup test environment
          command: |
            apt-get update
            apt-get install -y wget gnupg golang make libgmp3-dev libtinfo-dev pkg-config zip g++ zlib1g-dev unzip python bash-completion locales
            echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
            locale-gen
            wget "https://github.com/bazelbuild/bazel/releases/download/0.24.0/bazel_0.24.0-linux-x86_64.deb"
            dpkg -i bazel_0.24.0-linux-x86_64.deb
            echo "common:ci --build_tag_filters -requires_hackage,-requires_zlib,-requires_doctest,-requires_c2hs,-requires_threaded_rts,-dont_test_with_bindist" > .bazelrc.local
      - run:
          name: Build tests
          command: |
            bazel build --config ci //tests/...
      - run:
          name: Run tests
          command: |
            # Run the start script test.
            # Doesn't use the test suite binary, because that depends on nixpkgs dependencies.
            ./tests/run-start-script.sh
            # TODO: enable all tests for bindists
            # (this will require tests to both work with nixpkgs and hazel backends)

  # ATTN: when you change anything here, don’t forget to copy it to the build-darwin section
  build-linux-nixpkgs:
    docker:
      - image: nixos/nix:2.1.3
    working_directory: ~/rules_haskell
    resource_class: large
    steps:
      - checkout
      - run:
          name: System dependencies
          command: |
            set -e
            apk --no-progress update
            apk --no-progress add bash ca-certificates

            mkdir -p /etc/nix
            # CircleCI and Nix sandboxing don't play nice. See
            # https://discourse.nixos.org/t/nixos-on-ovh-kimsufi-cloning-builder-process-operation-not-permitted/1494/5
            echo "sandbox = false" > /etc/nix/nix.conf
            # No builders and no local jobs ensures that everything has to come from a binary cache
            # If we want to add packages that are not cached by the offical NixOS binary cache,
            # we need to manually build them (e.g. `nix-build -A <dependency> --max-jobs <no-cpu-cores>`).
            # This is a sanity check.
            echo "builders =" >> /etc/nix/nix.conf
            echo "max-jobs = 0" >> /etc/nix/nix.conf
      - run:
          name: Configure
          command: |
            echo "build:ci --host_platform=@io_tweag_rules_haskell//haskell/platforms:linux_x86_64_nixpkgs" > .bazelrc.local
      - run:
          name: Build tests
          command: |
            nix-shell --arg docTools false --pure --run \
              'bazel build --config ci //tests/...'
      - run:
          name: Run tests
          # bazel does not support recursive bazel call, so we
          # cannot use bazel run here because the test runner uses
          # bazel
          command: |
            nix-shell --arg docTools false --pure --run \
              'bazel build --config ci //tests:run-tests'
            # TODO(Profpatsch) re-add a nixpkgs startup script
            # and enable this test again
            nix-shell --arg docTools false --pure --run \
              './bazel-ci-bin/tests/run-tests --skip "/startup script/"'
            nix-shell --arg docTools false --pure --run \
              'bazel coverage //tests/... --config ci --build_tag_filters "coverage-compatible" --test_tag_filters "coverage-compatible" --test_output=all'

  build-darwin:
    macos:
      xcode: "9.0"
    steps:
      - checkout
      - run:
          name: Install Nix
          command: |
            curl https://nixos.org/nix/install | sh

      - run:
          name: Install cachix
          shell: /bin/bash -eilo pipefail
          command: |
            nix-env -iA cachix -f https://github.com/NixOS/nixpkgs/tarball/db557aab7b690f5e0e3348459f2e4dc8fd0d9298

      - run:
          name: Run cachix
          shell: /bin/bash -eilo pipefail
          command: |
            cachix use tweag
            cachix push tweag --watch-store
          background: true

      - run:
          name: Configure
          command: |
            mkdir -p ~/.cache/bazel/

            echo "build:ci --host_platform=@io_tweag_rules_haskell//haskell/platforms:darwin_x86_64_nixpkgs" >> .bazelrc.local
            echo "build:ci --disk_cache=~/.cache/bazel/" >> .bazelrc.local
            echo "common:ci --test_tag_filters -dont_test_on_darwin" >> .bazelrc.local

      - restore_cache:
          keys: # see note about 'Disk cache'
              - v1-rules_haskell-empty-{{ .Branch }}-
              - v1-rules_haskell-cache-{{ .Branch }}-
              - v1-rules_haskell-cache-master-

      - run:
          name: Build tests
          shell: /bin/bash -eilo pipefail
          command: |
            nix-shell --arg docTools false --pure --run \
              'bazel build --config ci //tests/...'
      - run:
          name: Run tests
          shell: /bin/bash -eilo pipefail
          command: |

            # Keep CI awake
            while true; do echo "."; sleep 60; done &

            nix-shell --arg docTools false --pure --run \
              'bazel build --config ci //tests:run-tests'
            # XXX 2019-01-22 Disable start script checking on Darwin
            # due to a clash between binutils and clang.
            nix-shell --arg docTools false --pure --run \
              './bazel-ci-bin/tests/run-tests --skip "/startup script/"'
            nix-shell --arg docTools false --pure --run \
              'bazel coverage //tests/... --config ci --build_tag_filters "coverage-compatible" --test_tag_filters "coverage-compatible" --test_output=all'


        # see note about 'Disk cache'
      - save_cache:
          key: v1-rules_haskell-cache-{{ .Branch }}-{{ .BuildNum }}
          paths:
              - ~/.cache/bazel/

      - run:
          name: Clean up cache
          shell: /bin/bash -eilo pipefail
          command: |
            rm -rf ~/.cache/bazel/
            mkdir -p ~/.cache/bazel/

      - save_cache:
          key: v1-rules_haskell-empty-master-{{ .BuildNum }}
          paths:
              - ~/.cache/bazel/

workflows:
  version: 2
  build:
    jobs:
      - build-linux-ghc-bindist
      - build-linux-nixpkgs
      - build-darwin:
          context: org-global # for the cachix token