Skip to content

Conversation

@virkt25
Copy link
Contributor

@virkt25 virkt25 commented Apr 12, 2018

Simpler approach to #1251

A simple script clone's loopback.io, bootstrap's it and attempts to build the site. If it fails, CI will fail.


Not adding it as a regular test since the script is not Windows compatible.


The 2 items from #1251 with regards to changes to loopback.io repo would still need to happen. (DONE)

fixes #1232

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

bin/docs.test.sh Outdated

rm -rf loopback.io
git clone https://github.com/strongloop/loopback.io.git
npm run bootstrap
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to clone loopback.io into sandbox instead of creating its own location.

Copy link
Contributor

Choose a reason for hiding this comment

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

The other option is to have loopback.io repo checked out somewhere else and try the following:

cd loopback.io
npm i ~/Projects/loopback-next/docs --no-save

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call for using sandbox.


We would still need to run the other commands (fetch-readmes, bundle install, jekyll build) since it's the build step that verifies the site hasn't broken due to formatting errors in docs, missing files, etc.

Copy link
Contributor

@raymondfeng raymondfeng Apr 12, 2018

Choose a reason for hiding this comment

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

Make it a npm script of loopback.io package, such as npm run build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like this? loopbackio/loopback.io#666

@shimks
Copy link
Contributor

shimks commented Apr 13, 2018

Can we turn the shell script into a js script so that it can work on windows (or is that not the problem with Windows compatibility)?

@virkt25
Copy link
Contributor Author

virkt25 commented Apr 13, 2018

The problem is the requirement of having ruby installed on the machine + the fact that jekyll doesn't officially support Windows (See https://jekyllrb.com/docs/windows/) ... as such I don't think a script is worth the effort because if it fails, people are disappointed but if it doesn't exist there is no expectation of it working on Windows.


jobs:
include:
- stage: loopback.io
Copy link
Contributor

Choose a reason for hiding this comment

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

When does this job run? For all builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, it would run for all PRs. I'm not sure how to run it if there are changes to just the @loopback/docs folder.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty worrisome then.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the shell script, we should use git diff --name-only to find out if any files are changed under docs. If not, skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any reason this is worrisome? Besides Travis taking longer?

I did find some inspiration for skipping a stage early here facebook/react#2000 I can try something similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

Taking longer is worrisome.

Copy link
Contributor

Choose a reason for hiding this comment

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

git diff --name-only origin/master docs/ will tell if the local repo has diff from the origin/master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is what I can see to optimize:

  1. git describe --abbrev=0 gives us the latest release tag
  2. git diff --name-only <tag> -- docs/ show docs/* changed since last release

bin/docs.test.sh Outdated
@@ -0,0 +1,9 @@
#!/bin/bash

rm -rf sandbox/loopback.io/
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider adding checks for status codes returned by those commands or would Travis handle it if any of them fail (I guess they are interdependent so maybe this is not needed)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If any command exits with anything but a 0, Travis will fail the build stage.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @b-admike's point was that the shell script only reports the last command's exit code to travis.

@raymondfeng
Copy link
Contributor

raymondfeng commented Apr 13, 2018

My improved version of the shell script:

#!/bin/bash
# Make sure we use the correct repo root dir
DIR=`dirname $0`
REPO_ROOT=$DIR/..
pushd $REPO_ROOT >/dev/null
rm -rf sandbox/loopback.io/
# Shadow clone is faster
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
npm run bootstrap
pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null
# The following 3 lines will be replaced with npm run build
bundle install
npm run fetch-readmes
bundle exec jekyll build
popd >/dev/null
popd >/dev/null

@virkt25 virkt25 force-pushed the docs-test-1 branch 2 times, most recently from 18f138e to 84d81ea Compare April 16, 2018 03:31
bin/docs.test.sh Outdated
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
npm run bootstrap
pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null
# The following 3 lines will be replaced with npm run build
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raymondfeng I don't think bundle install should be a part of the build script in loopback.io since the script can be used there ... and on local, it's a one time install process. If you agree, I already have the changes ready to land for loopback.io after which I can update this script.

.travis.yml Outdated
- stage: loopback.io
before_install:
- |
if git diff --name-only --quiet origin/master docs/; then
Copy link
Member

Choose a reason for hiding this comment

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

Can we use $TRAVIS_BRANCH instead of origin/master? I am worried that a hard-coded branch name origin/master will not work in the future, once we create branches like v4.x.

See https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables

Copy link
Contributor Author

@virkt25 virkt25 Apr 16, 2018

Choose a reason for hiding this comment

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

I think it might be even better to use $TRAVIS_COMMIT_RANGE. I'll make the change.

nvm, it doesn't do what I thought it did, I'll use $TRAVIS_BRANCH

bin/docs.test.sh Outdated
rm -rf sandbox/loopback.io/
# Shadow clone is faster
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
npm run bootstrap
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, all other packages have been already bootstrapped and all we need is to bootstrap sandbox/loopback.io. To speed things up, can we tell lerna to bootstrap this single package only? Something along the following lines:

lerna bootstrap --scope loopback.io-workflow-scripts

Note that loopback.io-workflow-scripts is the package name as defined in loopback.io's package.json file:

https://github.com/strongloop/loopback.io/blob/cb67ad4c437503d7726845c09851b3256eceed16/package.json#L2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

npm run bootstrap is normally called by the before_script hook which is skipped for the loopback.io stage so we can run bootstrap only once after we've had an opportunity to clone the loopback.io repo into the sandbox.

Copy link
Member

Choose a reason for hiding this comment

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

I see, I did not realise before_script is being skipped. However, do we still need to bootstrap all packages to test the website? Isn't it enough to bootstrap loopback.io and perhaps docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I wonder if bootstrapping only the loopback.io package is enough to make it bootstrap any packages that are dependencies (aka docs).

bin/docs.test.sh Outdated
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
npm run bootstrap
pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null
# The following 3 lines will be replaced with npm run build
Copy link
Member

Choose a reason for hiding this comment

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

Should we reword this comment as a TODO? Should this PR wait until npm run build is implemented in loopback.io?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already implemented. See loopbackio/loopback.io#666

Will merge it today, just wanted to make sure @raymondfeng was ok with excluding the bundle install from the build script.

@virkt25 virkt25 force-pushed the docs-test-1 branch 2 times, most recently from caeafda to 2d429a3 Compare April 19, 2018 17:01
Copy link
Contributor

@b-admike b-admike left a comment

Choose a reason for hiding this comment

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

:shipit:

bin/docs.test.sh Outdated
rm -rf sandbox/loopback.io/
# Shadow clone is faster
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
./node_modules/lerna/bin/lerna.js bootstrap --scope loopback.io-workflow-scripts
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use the full path. lerna bootstrap is good enough as npm sets up the path.

@@ -0,0 +1,17 @@
#!/bin/bash

set -ev
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. These are the recommended flags by Travis (https://docs.travis-ci.com/user/customizing-the-build#Implementing-Complex-Build-Steps) to make sure the build fails if any command in the script fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok then.

@@ -0,0 +1,17 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename it to verify-docs.sh?

bundle install
npm run build
popd >/dev/null
popd >/dev/null
Copy link
Contributor

@raymondfeng raymondfeng Apr 19, 2018

Choose a reason for hiding this comment

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

Maybe we should clean up sandbox/loopback.io after the verification is done. If we run the script locally, the loopback.io package will be left over on disk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm ... my reason to leave it was in case we wanted to locally start the server to view the site (verify formatting / etc. beyond the test which makes sure Jekyll doesn't break).

May we can add scripts to clean the sandbox? or maybe we can have a local script for build:site ... and verify:docs would do a cleanup by default?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1. Or the same script can have an arg to control if we are building or verifying.

git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
./node_modules/lerna/bin/lerna.js bootstrap --scope loopback.io-workflow-scripts
pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null
bundle install
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, npm run build doesn't install Ruby Gems ... this allows the build script in loopback.io to be used for build without triggering install since the gems only need to be installed once.

Copy link
Contributor

Choose a reason for hiding this comment

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

As bundle install is an one time thing, why do we want to run it every time?

./node_modules/lerna/bin/lerna.js bootstrap --scope loopback.io-workflow-scripts
pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null
bundle install
npm run build
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we record the exit code of the command above and exit the script with it? Otherwise, can travis still detect the failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment above with regards to the set -ev. If my understanding about the flag is incorrect please let me know. I did make commits to this PR to verify the following and they all worked as expected:

  • loopback.io stage exits early with success if no changes to @loopback/docs
  • loopback.io stage builds successfully with changes to @loopback/docs
  • loopback.io stage fails if a change to @loopback/docs will break Jekyll

package.json Outdated
"pretest": "npm run clean && npm run build",
"test": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path",
"verify:docs": "npm run build:site && node packages/build/bin/run-clean \"sandbox/loopback.io\"",
"build:site": "/bin/bash ./bin/verify-docs.sh",
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to refer /bin/bash as the shebang in the script already uses bash.

Co-Authored-By: Raymond Feng <raymondfeng@users.noreply.github.com>
@virkt25 virkt25 merged commit 3a3c6fa into master Apr 20, 2018
@virkt25 virkt25 deleted the docs-test-1 branch April 20, 2018 22:25
@virkt25 virkt25 removed the review label Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs] Local Site Scaffolding

6 participants