Skip to content

Commit

Permalink
ci: Switch to Nix
Browse files Browse the repository at this point in the history
Previously we were installing

- PHP using Travis’s built-in mechanism that downloads distributions-specific tarballs (PHP 7.1 is not compatible with focal),
- Composer using itself,
- Python using pyenv (quite slow),
- Python libraries using pip,
- Node using nvm,
- jq using apt,
- PHP dependencies using Composer,
- client-side dependencies using npm.

Switching to Nix will allow us to get rid of all except the last two methods and achieve fully reproducible environment across both CI and developers’ machines.

The travis config is based on https://github.com/cachix/travis-ci-example.

Also allows us to switch distribution to focal.
  • Loading branch information
jtojnar committed Dec 16, 2020
1 parent b03e916 commit 467c828
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
79 changes: 43 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
# This file lints the code, builds a package and then deploys it.
# For the deployment, $BINTRAY_USER, $BINTRAY_KEY and $GH_TOKEN environment
# variables need to be set.
language: php
# This file lints the code, runs tests, builds a package and then deploys it.
# The following environment variables need to be set:
# - “$BINTRAY_USER” and “$BINTRAY_KEY” for pushing built package to Bintray
# - “$GH_TOKEN” to avoid Composer being throttled by GitHub
# - “$CACHIX_AUTH_TOKEN” for uploading built Nix packages to Cachix
language: nix
dist: focal
nix: 2.3.9
sudo: false

dist: xenial
env:
global:
- CACHIX_CACHE=fossar
- COMPOSER_NO_INTERACTION=1

matrix:
include:
- php: 8.0
- php: 7.4
- php: 7.3
- php: 7.2
- php: 7.1
- php: 7.0
env: CS_FIXER=true LINT_JS=true
- php: 5.6
env: DEPLOY=true
- env: PHP=80
- env: PHP=74
- env: PHP=73
- env: PHP=72
- env: PHP=71
- env: PHP=70 CS_FIXER=true LINT_JS=true
- env: PHP=56 DEPLOY=true
fast_finish: true
env:
- COMPOSER_NO_INTERACTION=1

addons:
apt:
packages:
- jq

cache:
directories:
- vendor
- $HOME/.composer/cache

before_install:
- nvm install 12
- pyenv install 3.6.3
- pyenv global 3.6.3
- pip3 install requests bcrypt
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi
- composer self-update
# Nix & Cachix set-up.
- echo "trusted-users = $USER" | sudo tee -a /etc/nix/nix.conf
- sudo systemctl restart nix-daemon
- nix-env -iA nixpkgs.cachix
- cachix use $CACHIX_CACHE
- nix path-info --all > /tmp/store-path-pre-build

# Update flake.nix to match the current CI job from matrix.
- sed -i "s/matrix.php = \"php\";/matrix.php = \"php${PHP}\";/" flake.nix

- if [ -n "$GH_TOKEN" ]; then nix-shell --run "composer config github-oauth.github.com ${GH_TOKEN}"; fi

install:
- phpenv config-rm xdebug.ini
- npm run install-dependencies
- nix-shell --run "npm run install-dependencies"

script:
- if [ "$LINT_JS" = true ]; then npm run lint:client; fi
- npm run lint:server
- if [ "$CS_FIXER" = true ]; then npm run cs:server; fi
- npm run test:server
- npm run test:integration
- if [ "$LINT_JS" = true ]; then nix-shell --run "npm run lint:client"; fi
- nix-shell --run "npm run lint:server"
- if [ "$CS_FIXER" = true ]; then nix-shell --run "npm run cs:server"; fi
- nix-shell --run "npm run test:server"
- nix-shell --run "npm run test:integration"

after_success:
# Upload built Nix packages to Cachix.
- comm -13 <(sort /tmp/store-path-pre-build | grep -v '\.drv$') <(nix path-info --all | grep -v '\.drv$' | sort) | cachix push $CACHIX_CACHE

before_deploy:
- git config --global user.email 'Travis CI'
- git config --global user.name '[email protected]'
- source utils/package.sh
- source utils/bintray.sh
- nix-shell --run "source utils/package.sh"
- nix-shell --run "source utils/bintray.sh"

deploy:
- provider: bintray
Expand Down
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

outputs = { self, flake-compat, nixpkgs, utils }:
let
matrix.php = "php";

mkDevShell = pkgs: phpPackage:
let
php = pkgs.${phpPackage}.withExtensions ({ enabled, all }: with all; enabled ++ [
Expand All @@ -31,6 +33,7 @@
pkgs.zola
pkgs.nodejs_latest
python
pkgs.jq
] ++ (with php.packages; [
composer
psalm
Expand All @@ -50,7 +53,7 @@
packages = {
inherit (pkgs) php56 php70 php71 php72;
};
devShell = mkDevShell pkgs "php";
devShell = mkDevShell pkgs matrix.php;
}
);
}

0 comments on commit 467c828

Please sign in to comment.