-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test: build loopback.io to validate docs package #1254
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
Conversation
bin/docs.test.sh
Outdated
|
|
||
| rm -rf loopback.io | ||
| git clone https://github.com/strongloop/loopback.io.git | ||
| npm run bootstrap |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
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)? |
|
The problem is the requirement of having |
|
|
||
| jobs: | ||
| include: | ||
| - stage: loopback.io |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking longer is worrisome.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
git describe --abbrev=0gives us the latest release taggit 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/ | |||
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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 |
18f138e to
84d81ea
Compare
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
caeafda to
2d429a3
Compare
b-admike
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intentional?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.iostage exits early with success if no changes to@loopback/docsloopback.iostage builds successfully with changes to@loopback/docsloopback.iostage fails if a change to@loopback/docswill 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", |
There was a problem hiding this comment.
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>
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 testpasses on your machinepackages/cliwere updatedexamples/*were updated