elves/elvish

View on GitHub
.cirrus.yml

Summary

Maintainability
Test Coverage
test_arm_task:
  env:
    ELVISH_TEST_TIME_SCALE: "20"
    TEST_FLAG: -race
  name: Test on Linux ARM64
  arm_container:
    # The Alpine image has segmentation faults when running test -race, so
    # use Debian instead.
    image: golang:1.22-bookworm
  go_version_script: go version
  test_script: go test $TEST_FLAG ./...

test_bsd_task:
  env:
    ELVISH_TEST_TIME_SCALE: "20"
    TEST_FLAG: -race
    GO_VERSION: "1.22.0"
    PATH: /usr/local/go/bin:$PATH
  matrix:
    - name: Test on FreeBSD
      freebsd_instance:
        # Find latest version on https://www.freebsd.org/releases/
        image_family: freebsd-14-0
      setup_script:
        # go test -race is not compatible with ASLR, which has been enabled by
        # default since FreeBSD 13
        # (https://wiki.freebsd.org/AddressSpaceLayoutRandomization). LLVM
        # issue: https://github.com/llvm/llvm-project/issues/53256
        #
        # There's also a Go bug where using go test -race with ASLR fails
        # to run the tests and still reports tests as passing:
        # https://github.com/golang/go/issues/65425
        sysctl kern.elf64.aslr.enable=0
    - name: Test on NetBSD
      compute_engine_instance:
        image_project: pg-ci-images
        # Find latest version in the "VERSION:" variable for the NetBSD image in
        # https://github.com/anarazel/pg-vm-images/blob/main/.cirrus.yml
        image: family/pg-ci-netbsd-vanilla-9-3
        platform: netbsd
    - name: Test on OpenBSD
      compute_engine_instance:
        image_project: pg-ci-images
        # Find latest version in the "VERSION:" variable for the OpenBSD image in
        # https://github.com/anarazel/pg-vm-images/blob/main/.cirrus.yml
        image: family/pg-ci-openbsd-vanilla-7-3
        platform: openbsd
  go_toolchain_cache:
    fingerprint_key: $CIRRUS_OS-$GO_VERSION
    folder: /usr/local/go
    populate_script: |
      curl -L -o go.tar.gz https://go.dev/dl/go$GO_VERSION.$CIRRUS_OS-amd64.tar.gz
      mkdir -p /usr/local
      tar -C /usr/local -xzf go.tar.gz
  go_version_script: go version
  test_script: go test $TEST_FLAG ./...

build_binaries_task:
  name: Build binaries
  only_if: $CIRRUS_BRANCH == 'master'
  alias: binaries
  env:
    CGO_ENABLED: "0"
  container:
    # Keep the Go version part in sync with
    # https://github.com/elves/up/blob/master/Dockerfile
    image: golang:1.22.0-alpine
  go_modules_cache:
    fingerprint_script: cat go.sum
    folder: ~/go/pkg/mod
  go_build_cache:
    folder: ~/.cache/go-build
  # Git is not required for building the binaries, but we need to include for Go
  # to include VCS information in the binary. Also install coreutils to get a
  # touch command that supports specifying the timezone.
  setup_script: apk add zip git coreutils
  # _bin is in .gitignore, so Git won't consider the repo dirty. This will
  # impact the binary, which encodes VCS information.
  build_binaries_script: |
    go run ./cmd/elvish ./tools/buildall.elv -name elvish-HEAD -variant official ./cmd/elvish _bin/
  binaries_artifacts:
    path: _bin/**
  binary_checksums_artifacts:
    path: _bin/*/*.sha256sum

check_binary_checksums_task:
  name: Check binary checksums ($HOST)
  only_if: $CIRRUS_BRANCH == 'master'
  container:
    image: alpine:latest
  depends_on: binaries
  matrix:
    - env:
        HOST: cdg
    - env:
        HOST: hkg
  setup_script: apk add git curl
  # Enable auto cancellation - if there is another push, only the task to
  # compare the website against the newer commit should continue.
  auto_cancellation: "true"
  wait_website_update_script: |
    ts=$(git show -s --format=%ct HEAD)
    wait=10
    while true; do
      if website_ts=$(curl -sSf https://$HOST.elv.sh/commit-ts.txt); then
        if test "$website_ts" -ge "$ts"; then
          echo "website ($website_ts) >= CI ($ts)"
          exit 0
        else
          echo "website ($website_ts) < CI ($ts)"
        fi
      else
        echo "website has no commit-ts.txt yet"
      fi
      sleep $wait
      test $wait -lt 96 && wait=`echo "$wait * 2" | bc`
    done
  check_binary_checksums_script: |
    curl -o checksums.zip https://api.cirrus-ci.com/v1/artifact/build/$CIRRUS_BUILD_ID/binaries/binary_checksums.zip
    unzip checksums.zip
    cd _bin

    ret=0
    for f in */elvish-HEAD.sha256sum */elvish-HEAD.exe.sha256sum; do
      website_sum=$(curl -sS https://$HOST.dl.elv.sh/$f | awk '{print $1}')
      ci_sum=$(cat $f | awk '{print $1}')
      if test "$website_sum" = "$ci_sum"; then
        echo "$f: website == CI ($ci_sum)"
      else
        echo "$f: website ($website_sum) != CI ($ci_sum)"
        ret=1
      fi
    done
    exit $ret