version: 2 jobs: # Make sure that there are no outstanding linting hints and that # auto-formatting does not result in any changes. style-check: docker: - image: nixos/nix:2.3 steps: - checkout - run: name: Install linting and styling scripts command: nix-env -f default.nix -iA style - run: name: Run linter command: | # Note: For checking this locally, use `nix-shell --run postgrest-lint` postgrest-lint - run: name: Run style check command: | # 'Note: For checking this locally, use `nix-shell --run postgrest-style` postgrest-style-check # Run tests based on stack and docker against the oldest PostgreSQL version # that we support. stack-test: docker: - image: cimg/base:2021.03 environment: - PGHOST=localhost - image: circleci/postgres:9.5 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.3.1/stack-2.3.1-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.3.1-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev postgresql-client sudo apt-get install -y --only-upgrade binutils stack setup - run: name: build src and tests dependencies command: | stack build --fast -j1 --only-dependencies stack build --fast --test --no-run-tests --only-dependencies - save_cache: paths: - "~/.stack" - ".stack-work" key: v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests - run: name: run spec tests command: | test/create_test_db "postgres://circleci@localhost" postgrest_test stack test # Run memory usage tests based on stack and docker. stack-test-memory: docker: - image: cimg/base:2021.03 environment: - PGHOST=localhost - TERM=xterm - image: circleci/postgres:12 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-prof-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.3.1/stack-2.3.1-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.3.1-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev postgresql-client stack setup - run: name: build dependencies with profiling enabled command: | stack build --profile -j1 --only-dependencies - save_cache: paths: - "~/.stack" - ".stack-work" key: v1-stack-prof-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install with profiling enabled command: | stack install --profile -j1 - run: name: run memory usage tests command: | export PATH="~/.local/bin:$PATH" test/create_test_db "postgres://circleci@localhost" postgrest_test test/memory-tests.sh # Publish a new release. This only runs when a release is tagged (see # workflow below). release: machine: true steps: - checkout - run: name: Install Nix command: | curl -L https://nixos.org/nix/install | sh echo "source $HOME/.nix-profile/etc/profile.d/nix.sh" >> $BASH_ENV - run: name: Change postgrest.cabal if nightly command: | if test "$CIRCLE_TAG" = "nightly" then cabal_nightly_version=$(git show -s --format='%cd' --date='format:%Y%m%d') sed -i "s/^version:.*/version:$cabal_nightly_version/" postgrest.cabal fi - run: name: Install and use the Cachix binary cache command: | nix-env -iA cachix -f https://cachix.org/api/v1/install cachix use postgrest - run: name: Install release scripts command: nix-env -f default.nix -iA release - run: name: Publish GitHub release command: | export GITHUB_USERNAME="$CIRCLE_PROJECT_USERNAME" export GITHUB_REPONAME="$CIRCLE_PROJECT_REPONAME" postgrest-release-github $CIRCLE_TAG - run: name: Publish Docker images command: | export DOCKER_REPO=postgrest postgrest-docker-login postgrest-release-dockerhub $CIRCLE_TAG if test "$CIRCLE_TAG" != "nightly" then postgrest-release-dockerhubdescription fi # Build everything in default.nix, push to the Cachix binary cache and run tests nix-build-test: machine: true steps: - checkout - run: name: Install Nix command: | curl -L https://nixos.org/nix/install | sh echo "source $HOME/.nix-profile/etc/profile.d/nix.sh" >> $BASH_ENV - run: name: Install and use the Cachix binary cache command: | nix-env -iA cachix -f https://cachix.org/api/v1/install cachix use postgrest - run: name: Change postgrest.cabal if nightly command: | if test "$CIRCLE_TAG" = "nightly" then cabal_nightly_version=$(git show -s --format='%cd' --date='format:%Y%m%d') sed -i "s/^version:.*/version:$cabal_nightly_version/" postgrest.cabal fi - run: name: Build all derivations from default.nix and push results to Cachix command: | # Only push to the cache when CircleCI makes the CACHIX_SIGNING_KEY # available (e.g. not for pull requests). if [ -n "${CACHIX_SIGNING_KEY:-""}" ]; then echo "Building and caching all derivations..." nix-build | cachix push postgrest else echo "Building all derivations (caching skipped for outside pull requests)..." nix-build fi - run: name: Install testing scripts command: nix-env -f default.nix -iA tests tests.memoryTests - run: name: Skip tests on build failure command: circleci-agent step halt when: on_fail - run: name: Run the spec tests against PostgreSQL 9.5 command: postgrest-with-postgresql-9.5 postgrest-test-spec when: always - run: name: Run the spec tests against PostgreSQL 9.6 command: postgrest-with-postgresql-9.6 postgrest-test-spec when: always - run: name: Run the spec tests against PostgreSQL 10 command: postgrest-with-postgresql-10 postgrest-test-spec when: always - run: name: Run the spec tests against PostgreSQL 11 command: postgrest-with-postgresql-11 postgrest-test-spec when: always - run: name: Run the spec tests against PostgreSQL 12 command: postgrest-with-postgresql-12 postgrest-test-spec when: always - run: name: Check the spec tests for idempotence against PostgreSQL 13 command: postgrest-test-spec-idempotence when: always - run: name: Run io tests command: postgrest-test-io when: always - run: name: Run memory tests command: postgrest-test-memory when: always - run: name: Run coverage command: postgrest-coverage - run: name: Upload coverage to codecov command: bash <(curl -s https://codecov.io/bash) -f coverage/codecov.json workflows: version: 2 build-test-release: jobs: - style-check: # Make sure that this job also runs when releases are tagged. filters: tags: only: - /v[0-9]+(\.[0-9]+)*/ - nightly - stack-test: filters: tags: only: - /v[0-9]+(\.[0-9]+)*/ - nightly - stack-test-memory: filters: tags: only: - /v[0-9]+(\.[0-9]+)*/ - nightly - nix-build-test: filters: tags: only: - /v[0-9]+(\.[0-9]+)*/ - nightly - release: requires: - style-check - stack-test - stack-test-memory - nix-build-test filters: tags: only: - /v[0-9]+(\.[0-9]+)*/ - nightly branches: ignore: /.*/