test_task:
  env:
    ELVISH_TEST_TIME_SCALE: 20
    CODECOV_TOKEN: ENCRYPTED[fcfbb034d9341821345216d5da5de529e582b85a2dde43da484e9827166ce1770d8e1da4ed2f32ddb7f4eb4fba593158]
    TEST_FLAG: -race
  go_modules_cache:
    fingerprint_script: cat go.sum
    folder: $GOPATH/pkg/mod
  matrix:
    - name: Test on Linux
      container:
        image: golang:latest
    - name: Test on Linux (Old Supported Go Version)
      container:
        image: golang:1.14
      env:
        # This should have the same coverage as the previous task, so skip it.
        SKIP_UPLOAD_COVERAGE: 1
    - name: Test on Linux (Gccgo)
      container:
        image: debian:unstable-slim
      setup_script:
        - apt-get -y update
        - apt-get -y install ca-certificates gccgo-go
      env:
        # This should have the same coverage as the previous task, so skip it.
        SKIP_UPLOAD_COVERAGE: 1
        # Gccgo doesn't support race test
        TEST_FLAG: ""
      # Gccgo is buggy. Allow failures until it could reliably build and test
      # Elvish.
      allow_failures: true
    - name: Test on macOS
      osx_instance:
        image: catalina-base
      setup_script: brew install go
      env:
        GOPATH: $HOME/go
    - name: Test on FreeBSD
      freebsd_instance:
        image_family: freebsd-12-1
      setup_script: pkg install -y go bash
      env:
        GOPATH: $HOME/go
        # For some reason the FreeBSD runner often has problem reaching codecov.
        # Skip it to prevent the coverage from fluctuating, and make the FreeBSD
        # task faster. There are very few files that are built on FreeBSD but not
        # Linux, so losing this part of the data makes very little difference.
        SKIP_UPLOAD_COVERAGE: 1
  go_version_script: go version
  test_script: go test $TEST_FLAG ./...
  upload_coverage_script:
    - test -z $SKIP_UPLOAD_COVERAGE || exit 0
    - go test -coverprofile=cover -coverpkg=./pkg/... ./pkg/...
    - curl -s https://codecov.io/bash -o codecov && bash codecov -f cover -t $CODECOV_TOKEN || true

checkstyle_go_task:
  name: Check the style of .go files
  container:
    image: golang:latest
  env:
    PATH: $HOME/go/bin:$PATH
  setup_script: go get golang.org/x/tools/cmd/goimports
  check_script: make checkstyle-go

checkstyle_md_task:
  name: Check the style of .md files
  container:
    image: node:latest
  env:
    PATH: $HOME/.npm-packages/bin:$PATH
  setup_script: npm install --global prettier@2.0.5
  check_script: make checkstyle-md

deploy_task:
  name: Build binaries and deploy to bintray
  only_if: $CIRRUS_PR == ""
  env:
    BINTRAY_TOKEN: ENCRYPTED[1a1820d17a2014de6b1798d379f86aa24bbd8acd5149656a98bfdf33746c78c85fefc8e6e522fedacdf8c4bf92bb25a0]
  go_modules_cache:
    fingerprint_script: cat go.sum
    folder: $GOPATH/pkg/mod
  container:
    image: theelves/cirrus-builder
  go_version_script: go version
  deploy_script: ./tools/cirrus-deploy.sh
