287 lines
10 KiB
YAML
287 lines
10 KiB
YAML
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 devtools
|
|
- run:
|
|
name: Run linter
|
|
command: |
|
|
# Note: For checking this locally, use `make lint`. Or, if using
|
|
# `nix`, run `nix-shell --run postgrest-lint`
|
|
postgrest-lint
|
|
- run:
|
|
name: Run style check
|
|
command: |
|
|
# 'Note: For checking this locally, use `make style`. Or, if using
|
|
# `nix`, run `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: circleci/buildpack-deps:trusty
|
|
environment:
|
|
- PGHOST=localhost
|
|
- image: circleci/postgres:9.4
|
|
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
|
|
# ncat utility from nmap needed to test socket connection with curl < 7.40
|
|
sudo apt-get install -y libgmp-dev postgresql-client nmap
|
|
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: |
|
|
POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) \
|
|
stack test
|
|
- run:
|
|
name: run io tests
|
|
command: |
|
|
export PATH="~/.local/bin:$PATH"
|
|
stack install --fast -j1
|
|
test/io-tests.sh
|
|
|
|
# Run memory usage tests based on stack and docker.
|
|
stack-test-memory:
|
|
docker:
|
|
- image: circleci/buildpack-deps:trusty
|
|
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:
|
|
docker:
|
|
- image: nixos/nix:2.3
|
|
steps:
|
|
- checkout
|
|
- 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
|
|
- setup_remote_docker
|
|
- run:
|
|
name: Publish Docker images
|
|
command: |
|
|
export DOCKER_REPO=postgrest
|
|
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
|
postgrest-release-dockerhub
|
|
postgrest-release-dockerhubdescription
|
|
|
|
# Build everything in default.nix and push to the Cachix binary cache.
|
|
nix-build:
|
|
docker:
|
|
- image: nixos/nix:2.3
|
|
steps:
|
|
- checkout
|
|
- 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: 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 tests against all supported PostgreSQL versions.
|
|
nix-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: Install testing scripts
|
|
command: nix-env -f default.nix -iA tests tests.ioTests tests.memoryTests
|
|
# Our utility scripts use cabal to run the tests, which will pick up all
|
|
# the libraries that are built with Nix. So this should only ever build
|
|
# the PostgREST itself and be reasonably quick. We accelerate that part
|
|
# further by caching `~/.cabal` and `dist-newstyle`.
|
|
#
|
|
# CircleCI looks for caches by prefix. When saving to the the cache
|
|
# below, we append the current time to the key ('-{{ epoch }}'), so a new
|
|
# cache will always be uploaded. If the `postgrest.cabal` and
|
|
# `nix/nixpkgs-version.nix` files are unchanged, the latest matching
|
|
# cache will be used. If there is no cache for those files, CircleCI will
|
|
# try the next, more general key and use the latest cache that matches
|
|
# it.
|
|
- restore_cache:
|
|
keys:
|
|
- nix-test-{{ checksum "postgrest.cabal" }}-{{ checksum "nix/nixpkgs-version.nix" }}
|
|
- nix-test-{{ checksum "postgrest.cabal" }}
|
|
- nix-test
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 9.4
|
|
command: postgrest-test-spec-postgresql-9.4
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 9.5
|
|
command: postgrest-test-spec-postgresql-9.5
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 9.6
|
|
command: postgrest-test-spec-postgresql-9.6
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 10
|
|
command: postgrest-test-spec-postgresql-10
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 11
|
|
command: postgrest-test-spec-postgresql-11
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 12
|
|
command: postgrest-test-spec-postgresql-12
|
|
- run:
|
|
name: Run the spec tests against PostgreSQL 13
|
|
command: postgrest-test-spec-postgresql-13
|
|
- run:
|
|
name: Run io tests
|
|
command: postgrest-test-io
|
|
- run:
|
|
name: Run memory tests
|
|
command: postgrest-test-memory
|
|
- save_cache:
|
|
paths:
|
|
- "~/.cabal"
|
|
- "dist-newstyle"
|
|
key: nix-test-{{ checksum "postgrest.cabal" }}-{{ checksum "nix/nixpkgs-version.nix" }}-{{ epoch }}
|
|
|
|
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]+)*/
|
|
- stack-test:
|
|
filters:
|
|
tags:
|
|
only: /v[0-9]+(\.[0-9]+)*/
|
|
- stack-test-memory:
|
|
filters:
|
|
tags:
|
|
only: /v[0-9]+(\.[0-9]+)*/
|
|
- nix-build:
|
|
filters:
|
|
tags:
|
|
only: /v[0-9]+(\.[0-9]+)*/
|
|
- nix-test:
|
|
filters:
|
|
tags:
|
|
only: /v[0-9]+(\.[0-9]+)*/
|
|
requires:
|
|
- nix-build
|
|
- release:
|
|
requires:
|
|
- style-check
|
|
- stack-test
|
|
- stack-test-memory
|
|
- nix-build
|
|
- nix-test
|
|
filters:
|
|
tags:
|
|
only: /v[0-9]+(\.[0-9]+)*/
|
|
branches:
|
|
ignore: /.*/
|