From caccdfd863fa67c9f21f2eede2da463c713396a3 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 21 Feb 2019 11:07:55 -0500 Subject: [PATCH] feat: Switch to Notion.js --- .envrc | 108 ------------------------------------------- .nvmrc | 1 - .travis.yml | 5 +- Dockerfile | 6 ++- Makefile | 2 + README.md | 18 ++++---- bin/get-node-version | 8 ++++ bin/get-yarn-version | 8 ++++ package.json | 4 ++ 9 files changed, 36 insertions(+), 124 deletions(-) delete mode 100644 .nvmrc create mode 100755 bin/get-node-version create mode 100755 bin/get-yarn-version diff --git a/.envrc b/.envrc index 68ede0d0..f1fec719 100644 --- a/.envrc +++ b/.envrc @@ -11,113 +11,6 @@ layout_poetry() { set -e -# nvm based on https://github.com/steve-ross/direnv-helpers - -__prompt_install_nvm(){ - _log warn "Couldn't find nvm (node version manager)..." - read -p "Should I install it? " -n 1 -r - echo # (optional) move to a new line - if [[ $REPLY =~ ^[Yy]$ ]]; then - _log info "Installing NVM" - curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash - __source_nvm # make sure nvm is sourced - else - log_error "Install nvm first and make sure it is in your path and try again" - _log warn "To install NVM visit https://github.com/creationix/nvm#installation" - exit - fi -} - -__source_nvm(){ - local NVM_PATH=$(find_up .nvm/nvm.sh) - [ -s "$NVM_PATH" ] && \. "$NVM_PATH" # This loads nvm -} - -__load_or_install_nvm(){ - local NVM_PATH=$(find_up .nvm/nvm.sh) - if [ -z "$NVM_PATH" ]; then - # didn't find it - __prompt_install_nvm - else - # source NVM - __source_nvm - fi -} - -__direnv_nvm_use_node(){ - local NVM_PATH=$(find_up .nvm/nvm.sh) - # load version direnv way - local NVM_NODE_VERSION_DIR=versions/node - local NODE_VERSION=$(< .nvmrc) - - # two possible locations for node versions in nvm... - local ALT_NVM_PATH="${NVM_PATH/\/nvm.sh}" - local TYPICAL_NVM_PATH="${NVM_PATH/nvm.sh/$NVM_NODE_VERSION_DIR}" - - # set the nvm path to the typical place NVM stores node versions - local NVM_PATH="$TYPICAL_NVM_PATH" - - #check alt path (seems old versions are here) - if [ -d "$ALT_NVM_PATH/v$NODE_VERSION" ]; then - NVM_PATH="$ALT_NVM_PATH" - fi - - export NODE_VERSIONS=$NVM_PATH - export NODE_VERSION_PREFIX="v" - - use node -} - -__nvm_use_or_install_version(){ - local version=$(< .nvmrc) - local nvmrc_node_version=$(nvm version "$version") - if [ "$nvmrc_node_version" = "N/A" ]; then - _log warn "Installing missing node version" - local install_output=$(nvm install "$version") - fi - nvm use -} - -_log() { - local msg=$* - local color_normal - local color_success - - color_normal=$(tput sgr0) - color_success=$(tput setaf 2) - color_warn=$(tput setaf 3) - color_info=$(tput setaf 5) - - # default color - current_color="${color_normal}" - - if ! [[ -z $2 ]]; then - local message_type=$1 - # remove message type from the string (plus a space) - msg=${msg/$message_type /} - if [ "$message_type" = "warn" ]; then - current_color="${color_warn}" - fi - if [ "$message_type" = "info" ]; then - current_color="${color_info}" - fi - if [ "$message_type" = "success" ]; then - current_color="${color_success}" - fi - fi - - if [[ -n $DIRENV_LOG_FORMAT ]]; then - # shellcheck disable=SC2059 - printf "${current_color}${DIRENV_LOG_FORMAT}${color_normal}\n" "$msg" >&2 - fi -} - -requires_nvm(){ - __load_or_install_nvm - __nvm_use_or_install_version - __direnv_nvm_use_node -} - # check if python version is set in current dir if [ -f ".python-version" ] ; then if [ ! -d ".venv" ] ; then @@ -128,6 +21,5 @@ if [ -f ".python-version" ] ; then source .venv/bin/activate fi -requires_nvm layout node layout_poetry diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index dba04c1e..00000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -8.11.3 diff --git a/.travis.yml b/.travis.yml index 6bb74515..85f3b301 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ services: - redis-server - postgresql python: - - "3.7" + - '3.7' cache: yarn: true directories: @@ -18,8 +18,7 @@ env: - PIP_DISABLE_PIP_VERSION_CHECK=on install: - curl -sSL https://raw.githubusercontent.com/sdispater/poetry/0.12.10/get-poetry.py | python - - nvm install $(cat .nvmrc) - - npm install -g yarn@1.7.0 + - curl -sSLf https://get.notionjs.com | bash - PATH=$HOME/.poetry/bin:$PATH NODE_ENV= make script: - git --version diff --git a/Dockerfile b/Dockerfile index 0970b53d..b07d8b38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,9 +39,11 @@ RUN set -ex \ # install nvm, node, and npm # gpg keys listed at https://github.com/nodejs/node COPY .nvmrc /usr/src/zeus/ -ENV YARN_VERSION 1.7.0 +ARG YARN_VERSION 1.13.0 +ENV YARN_VERSION $YARN_VERSION +ARG NODE_VERSION 8.11.3 +ENV NODE_VERSION $NODE_VERSION RUN set -x \ - && export NODE_VERSION=$(cat /usr/src/zeus/.nvmrc) \ && export GNUPGHOME="$(mktemp -d)" \ && export NPM_CONFIG_CACHE="$(mktemp -d)" \ && apt-get update && apt-get install -y --no-install-recommends dirmngr gnupg && rm -rf /var/lib/apt/lists/* \ diff --git a/Makefile b/Makefile index 0102ad15..cd488e42 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,8 @@ reset-db: drop-db db build-docker-image: docker build \ -t zeus \ + --build-arg NODE_VERSION=$(shell bin/get-node-version | tr -d '\n') \ + --build-arg YARN_VERSION=$(shell bin/get-yarn-version | tr -d '\n') \ --build-arg BUILD_REVISION=$(shell git rev-parse HEAD | tr -d '\n') \ . diff --git a/README.md b/README.md index 8689119d..1010b489 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ If you want to use Zeus with a build system that's not currently supported, see ### Supported Artifact Types -While you can upload any kind of Artifact to zeus (e.g. ``.html`` output), the platform has knowledge of certain types +While you can upload any kind of Artifact to zeus (e.g. `.html` output), the platform has knowledge of certain types and will grant additional functionality if they're present. The recommended way to support artifacts is to configure a post-build step (on both failure and success) to do something similar to the following: @@ -70,14 +70,14 @@ Webpack stats can be generated with: webpack --profile --json > webpack-stats.json ``` -They should be submitted with the ``application/x-webpack-stats+json`` type. +They should be submitted with the `application/x-webpack-stats+json` type. ## Contributing ### Requirements - Python 3.7 -- Node +- Node (and [Notion.js](https://www.notionjs.com/)) - Postgres 9.4+ Note: If you're using pyenv for Python and macOS Mojave and having issues installing 3.7.1, take a look here: @@ -97,7 +97,7 @@ make poetry run zeus init ``` -Note, before running any future Python commands (including ``zeus``), you'll +Note, before running any future Python commands (including `zeus`), you'll need to activate the environment: ```shell @@ -106,7 +106,7 @@ poetry shell You can also setup [direnv](https://direnv.net/) to automatically activate the environment. -Once dependencies are resolved, bootstrap the database (see ``Makefile`` for details): +Once dependencies are resolved, bootstrap the database (see `Makefile` for details): ```shell make db @@ -169,8 +169,8 @@ zeus ### Data Model - Most models contain a GUID (UUID) primary key. -- Some generalized models (such as ``ItemStat``) are keyed by GUID, and do not contain backrefs or constraints. -- Access is controlled at the repository level, and is generally enforced if you use the ``{ModelClass}.query`` utilities. +- Some generalized models (such as `ItemStat`) are keyed by GUID, and do not contain backrefs or constraints. +- Access is controlled at the repository level, and is generally enforced if you use the `{ModelClass}.query` utilities. ``` zeus @@ -202,7 +202,6 @@ zeus └── Identity ``` - ### Hooks A subset of APIs are exposed using simple hook credentials. These credentials are coupled to a provider (e.g. `travis-ci`) and a single repository. @@ -264,7 +263,6 @@ And here's how you upload an artifact: zeus upload -b $MY_BUILD_ID -j $MY_JOB_ID -t 'text/xml+coverage' coverage.xml ``` - ### Updating data with `curl` Here's an example of how you can publish job details without the native webhooks with `curl` from Travis: @@ -290,4 +288,4 @@ curl $ZEUS_HOOK_BASE/builds/$TRAVIS_BUILD_NUMBER/jobs/$TRAVIS_JOB_NUMBER \ -d "{\"status\": \"$1\", \"result\": \"$2\", \"url\": \"https://travis-ci.org/${TRAVIS_REPO_SLUG}/jobs/${TRAVIS_JOB_ID}\", \"allow_failure\": ${TRAVIS_ALLOW_FAILURE}}" ``` -From there you can submit artifacts using ``zeus-cli`` and its standard mechanisms. +From there you can submit artifacts using `zeus-cli` and its standard mechanisms. diff --git a/bin/get-node-version b/bin/get-node-version new file mode 100755 index 00000000..df84dc06 --- /dev/null +++ b/bin/get-node-version @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +import json + +with open("package.json") as fp: + data = json.load(fp) + +print(data["toolchain"]["node"]) diff --git a/bin/get-yarn-version b/bin/get-yarn-version new file mode 100755 index 00000000..972958c9 --- /dev/null +++ b/bin/get-yarn-version @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +import json + +with open("package.json") as fp: + data = json.load(fp) + +print(data["toolchain"]["yarn"]) diff --git a/package.json b/package.json index 1c06f1e8..e4c90bb0 100644 --- a/package.json +++ b/package.json @@ -163,5 +163,9 @@ "rules": { "react/no-deprecated": "off" } + }, + "toolchain": { + "node": "8.11.3", + "yarn": "1.13.0" } }