Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: remove vendored yarn, and use volta for Travis + GHA #19069

Merged
merged 30 commits into from May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 3 additions & 11 deletions .github/workflows/acceptance.yml
Expand Up @@ -37,7 +37,6 @@ jobs:
DJANGO_VERSION: ">=1.11,<1.12"

# Node configuration
# node's version is pinned by .nvmrc and is autodetected by `nvm install`.
NODE_OPTIONS: --max-old-space-size=4096
NODE_ENV: development

Expand Down Expand Up @@ -119,16 +118,14 @@ jobs:
# Checkout codebase
- uses: actions/checkout@v2

# Install node
- uses: volta-cli/action@v1

# See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
- name: Get yarn cache dir
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

# Use nvmrc so we don't have yet another place node version is defined
- name: Get node version from .nvmrc
id: nvmrc
run: echo "::set-output name=version::$(cat .nvmrc)"

# yarn cache
- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
Expand All @@ -138,11 +135,6 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-

# Setup node
- uses: actions/setup-node@v1
with:
node-version: ${{ steps.nvmrc.outputs.version }}

# Use `.python-version` to avoid duplication
# XXX: can't actually read from .python-version because GitHub Actions
# does not support our version (2.7.16)
Expand Down
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

1 change: 0 additions & 1 deletion .pre-commit-config.yaml
@@ -1,7 +1,6 @@
exclude: >
(?x)(
LICENSE$|
^bin/yarn$|
\.snap$|
\.map$|
\.map\.js$|
Expand Down
72 changes: 44 additions & 28 deletions .travis.yml
Expand Up @@ -10,7 +10,7 @@ cache:
yarn: true
directories:
- "${HOME}/virtualenv/python$(python -c 'import platform; print(platform.python_version())')"
- '$NODE_DIR'
- '$VOLTA_HOME'
- node_modules
- '${HOME}/google-cloud-sdk'

Expand All @@ -32,8 +32,9 @@ env:
- MIGRATIONS_TEST_MIGRATE=0
# Use this to override the django version in the requirements file.
- DJANGO_VERSION=">=1.11,<1.12"
# node's version is pinned by .nvmrc and is autodetected by `nvm install`.
- NODE_DIR="${HOME}/.nvm/versions/node/v$(< .nvmrc)"
- VOLTA_VERSION=0.8.1
- VOLTA_HOME="${HOME}/.volta"
- PATH="${HOME}/.volta/bin:${PATH}"
- NODE_OPTIONS=--max-old-space-size=4096
- PYTEST_SENTRY_DSN=https://6fd5cfea2d4d46b182ad214ac7810508@sentry.io/2423079
- SENTRY_KAFKA_HOSTS=localhost:9092
Expand Down Expand Up @@ -62,6 +63,21 @@ base_install: &base_install |-

[ "$TRAVIS_PULL_REQUEST" != "false" ] || export PYTEST_SENTRY_ALWAYS_REPORT=1

install_volta: &install_volta |-
command -v volta && exit 0
wget --quiet "https://github.com/volta-cli/volta/releases/download/v$VOLTA_VERSION/volta-$VOLTA_VERSION-linux-openssl-1.0.tar.gz"
tar -xzf "volta-$VOLTA_VERSION-linux-openssl-1.0.tar.gz" -C "${HOME}/bin"
# Running `volta -v` triggers setting up the shims in VOLTA_HOME (otherwise node won't work)
volta -v

install_node_dependencies: &install_node_dependencies
# Running `node -v` and `yarn -v` triggers Volta to install the versions set in the project.
# There might be a more readable `volta install` in the future that would replace this magic.
# Tracking: https://github.com/volta-cli/volta/issues/653#issuecomment-628909923
node -v
yarn -v
yarn install --frozen-lockfile
joshuarli marked this conversation as resolved.
Show resolved Hide resolved

start_snuba: &start_snuba |-
docker run \
--name sentry_clickhouse \
Expand Down Expand Up @@ -94,14 +110,15 @@ after_script:
pip install -U codecov
codecov -e TEST_SUITE
fi
- ./bin/yarn global add @zeus-ci/cli
- $(./bin/yarn global bin)/zeus upload -t "text/xml+xunit" .artifacts/*junit.xml
- $(./bin/yarn global bin)/zeus upload -t "text/xml+coverage" .artifacts/*coverage.xml
- $(./bin/yarn global bin)/zeus upload -t "text/xml+coverage" .artifacts/coverage/cobertura-coverage.xml
- $(./bin/yarn global bin)/zeus upload -t "text/html+pytest" .artifacts/*pytest.html
- $(./bin/yarn global bin)/zeus upload -t "text/plain+pycodestyle" .artifacts/*pycodestyle.log
- $(./bin/yarn global bin)/zeus upload -t "text/xml+checkstyle" .artifacts/*checkstyle.xml
- $(./bin/yarn global bin)/zeus upload -t "application/webpack-stats+json" .artifacts/*webpack-stats.json
- yarn global add @zeus-ci/cli
- export PATH="$(yarn global bin):${PATH}"
- zeus upload -t "text/xml+xunit" .artifacts/*junit.xml
- zeus upload -t "text/xml+coverage" .artifacts/*coverage.xml
- zeus upload -t "text/xml+coverage" .artifacts/coverage/cobertura-coverage.xml
- zeus upload -t "text/html+pytest" .artifacts/*pytest.html
- zeus upload -t "text/plain+pycodestyle" .artifacts/*pycodestyle.log
- zeus upload -t "text/xml+checkstyle" .artifacts/*checkstyle.xml
- zeus upload -t "application/webpack-stats+json" .artifacts/*webpack-stats.json

base_postgres: &postgres_default
python: 2.7
Expand All @@ -128,20 +145,19 @@ base_acceptance: &acceptance_default
- postgresql
before_install:
- *base_install
- *install_volta
- *start_snuba
- find "$NODE_DIR" -type d -empty -delete
- nvm install
- docker ps -a
install:
- ./bin/yarn install --frozen-lockfile
- *install_node_dependencies
- python setup.py install_egg_info
- pip install -U -e ".[dev]"
- |
CHROME_MAJOR_VERSION="$(dpkg -s google-chrome-stable | sed -nr 's/Version: ([0-9]+).*/\1/p')"
wget -N "https://chromedriver.storage.googleapis.com/$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION})/chromedriver_linux64.zip" -P ~/
- unzip ~/chromedriver_linux64.zip -d ~/
- rm ~/chromedriver_linux64.zip
- sudo install -m755 ~/chromedriver /usr/local/bin/
- install -m755 ~/chromedriver -C "${HOME}/bin"
before_script:
- psql -c 'create database sentry;' -U postgres

Expand All @@ -154,13 +170,13 @@ matrix:
- language: generic
name: 'Linter (Javascript)'
env: TEST_SUITE=lint-js
install:
- find "$NODE_DIR" -type d -empty -delete
before_install:
# Under a "generic" language environment, this will make travis pyenv error because there
# is no pyenv python installed.
- rm .python-version
- nvm install
- ./bin/yarn install --frozen-lockfile
- *install_volta
install:
- *install_node_dependencies

- python: 3.7
name: 'pre-commit hooks (includes python linting + format check) and dependency scanning'
Expand Down Expand Up @@ -206,19 +222,17 @@ matrix:
name: 'Frontend [test]'
env: TEST_SUITE=js
before_install:
- find "$NODE_DIR" -type d -empty -delete
- nvm install
- *install_volta
install:
- ./bin/yarn install --frozen-lockfile
- *install_node_dependencies

- python: 2.7
name: 'Frontend [build]'
env: TEST_SUITE=js-build
before_install:
- find "$NODE_DIR" -type d -empty -delete
- nvm install
- *install_volta
install:
- ./bin/yarn install --frozen-lockfile
- *install_node_dependencies

- python: 2.7
name: 'Command Line'
Expand Down Expand Up @@ -298,14 +312,16 @@ matrix:

# Deploy 'storybook' (component & style guide)
- name: 'Storybook Deploy'
language: node_js
language: generic
env: STORYBOOK_BUILD=1
before_install:
# travis pyenv will attempt to use .python-version, but the appropriate python version won't be installed.
# since we don't need python here, we have to remove this.
- rm .python-version
install: ./bin/yarn install --frozen-lockfile
script: ./bin/yarn run storybook-build
- *install_volta
install:
- *install_node_dependencies
script: yarn run storybook-build
after_success: .travis/deploy-storybook.sh
after_failure: skip

Expand Down
1 change: 0 additions & 1 deletion .yarnrc
Expand Up @@ -4,4 +4,3 @@

disable-self-update-check true
lastUpdateCheck 1562193150687
BYK marked this conversation as resolved.
Show resolved Hide resolved
yarn-path "./bin/yarn"
17 changes: 8 additions & 9 deletions Makefile
@@ -1,6 +1,5 @@
PIP := python -m pip --disable-pip-version-check
WEBPACK := NODE_ENV=production ./bin/yarn webpack
YARN := ./bin/yarn
WEBPACK := NODE_ENV=production yarn webpack

# Currently, this is only required to install black via pre-commit.
REQUIRED_PY3_VERSION := $(shell awk 'FNR == 2' .python-version)
Expand Down Expand Up @@ -80,17 +79,17 @@ setup-git: ensure-venv setup-git-config
@echo ""

node-version-check:
@test "$$(node -v)" = v"$$(cat .nvmrc)" || (echo 'node version does not match .nvmrc. Recommended to use https://github.com/volta-cli/volta'; exit 1)
@test "$$(node -v)" = v10.16.3 || (echo 'node version does not match 10.16.3. Recommended to use https://github.com/volta-cli/volta'; exit 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: I think this test should not exist or if it does, we should be reading this value from package.json file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unfortunately, I wouldn't want to have people install jq. Would you be fine with a shitty grep for this?

My opinion is that it's not worth the effort, given that we rarely change node versions. When we do, it'd be easy to change this value. (It'd error pretty quickly in CI anyways.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unfortunately, I wouldn't want to have people install jq. Would you be fine with a shitty grep for this?

Yes, I'd be okay with a shitty grep. I'll even save you from the hassle:

awk 'BEGIN { RS=",|: {\n"; FS="\""; } $2 == "node" { print $4 }' package.json

My opinion is that it's not worth the effort, given that we rarely change node versions. When we do, it'd be easy to change this value. (It'd error pretty quickly in CI anyways.)

Trust me, when we need to change the node version, and we will soon as they are releasing a new security update soon, this will become a problem. Even worse, 6 months later, when someone who is not you (or even you) wants to update this, it will again be a big headache.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't see why it would be a "big headache" to update one thing that is even caught by CI.

Thanks for the awk, I'll put it in. Just to clarify, I don't have a problem with doing this at all, I'm just interested in why you're so averse to this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, your awk doesn't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, your awk doesn't work.

It works on my machine 😛 Joking aside, I think this is one of those shitty BSD/GNU/whatever differences as I tested this on Ubuntu and guessing you are trying this on macOS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the awk, I'll put it in. Just to clarify, I don't have a problem with doing this at all, I'm just interested in why you're so averse to this.

For anyone reading this who is not me or Josh, we discussed this over Slack. Summary: because it is not obvious or easy to find/remember that this needs be changed until it fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity it's GNU awk vs BSD awk. I can come up with a fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, comments just refreshed.


install-js-dev: node-version-check
@echo "--> Installing Yarn packages (for development)"
# Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
NODE_ENV=development $(YARN) install --frozen-lockfile
NODE_ENV=development yarn install --frozen-lockfile
# A common problem is with node packages not existing in `node_modules` even though `yarn install`
# says everything is up to date. Even though `yarn install` is run already, it doesn't take into
# account the state of the current filesystem (it only checks .yarn-integrity).
# Add an additional check against `node_modules`
$(YARN) check --verify-tree || $(YARN) install --check-files
yarn check --verify-tree || yarn install --check-files

install-py-dev: ensure-pinned-pip
@echo "--> Installing Sentry (for development)"
Expand Down Expand Up @@ -154,24 +153,24 @@ test-cli:

test-js-build: node-version-check
@echo "--> Running type check"
@$(YARN) run tsc
@yarn run tsc
@echo "--> Building static assets"
@$(WEBPACK) --profile --json > .artifacts/webpack-stats.json

test-js: node-version-check
@echo "--> Running JavaScript tests"
@$(YARN) run test
@yarn run test
@echo ""

test-js-ci: node-version-check
@echo "--> Running CI JavaScript tests"
@$(YARN) run test-ci
@yarn run test-ci
@echo ""

# builds and creates percy snapshots
test-styleguide:
@echo "--> Building and snapshotting styleguide"
@$(YARN) run snapshot
@yarn run snapshot
@echo ""

test-python:
Expand Down