Skip to content

Commit

Permalink
✨ Add cpp test of validator into pr checks (#33371)
Browse files Browse the repository at this point in the history
* Ignore bazel output files

* Add validator c++ tests to amp tasks

* Add a circle step to install bazel

* Install bazel by install_dependencies.sh

* Rename validator-cpp-test to validator-cpp

* Fix that validatorCpp didn't inherit stdio

* Add description to validatorCpp

* Create a new script for validator dependecies

Co-authored-by: Raghu Simha <rsimha@ampproject.org>

* Fix a bug that uses incorrect install script

* Fix a bug that description is attached to incorrect object

* Use sh to call script

* Add exec permission to install_validator_dependencies.sh

* Add bazel arg of repo_env and cxxopt

* Lint js code

* Add .out.cpponly files to validator target matchers

* Run c++ tests in circle ci only when validator files are changed

* Separate JS tests and C++ tests

* Fix job name

* Add cpp tests to workflow jobs

* Undo the separation of JS tests and C++ tests

* Remove unused file

* Use xlarge executer

* Reorder tasks in validator tests

* No longer explicitly install curl and gnupg

* Reorder tasks in push flow

Co-authored-by: Raghu Simha <rsimha@ampproject.org>
  • Loading branch information
antiphoton and rsimha committed Mar 23, 2021
1 parent f29f552 commit 998fd11
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ jobs:
- fail_fast
'Validator Tests':
executor:
name: amphtml-medium-executor
name: amphtml-xlarge-executor
steps:
- setup_vm
- run:
name: 'Install Protobuf'
command: pip3 install --user protobuf
name: 'Install Validator Dependencies'
command: ./.circleci/install_validator_dependencies.sh
- run:
name: 'Validator Tests'
command: node build-system/pr-check/validator-tests.js
Expand Down
37 changes: 37 additions & 0 deletions .circleci/install_validator_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# Copyright 2021 The AMP HTML Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.

# Script used by AMP's CI builds to install AMP Validator dependencies on
# CircleCI.

set -e

GREEN() { echo -e "\033[0;32m$1\033[0m"; }

echo $(GREEN "Adding Bazel repo...")
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

echo $(GREEN "Installing Bazel...")
sudo apt update
sudo apt install bazel

echo $(GREEN "Installing Clang...")
sudo apt install clang

echo $(GREEN "Installing Protobuf...")
pip3 install --user protobuf
1 change: 1 addition & 0 deletions amp.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ createTask('test-report-upload', 'testReportUpload', 'test-report-upload');
createTask('unit', 'unit', 'unit');
createTask('update-packages', 'updatePackages', 'update-packages');
createTask('validator', 'validator', 'validator');
createTask('validator-cpp', 'validatorCpp', 'validator');
createTask('validator-webui', 'validatorWebui', 'validator');
createTask('visual-diff', 'visualDiff', 'visual-diff');

Expand Down
3 changes: 2 additions & 1 deletion build-system/pr-check/build-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function isOwnersFile(file) {
}

/**
* Checks if the given file is of the form validator-.*\.(html|out|protoascii)
* Checks if the given file is of the form validator-.*\.(html|out|out.cpponly|protoascii)
*
* @param {string} file
* @return {boolean}
Expand All @@ -109,6 +109,7 @@ function isValidatorFile(file) {
return (
name.startsWith('validator-') &&
(name.endsWith('.out') ||
name.endsWith('.out.cpponly') ||
name.endsWith('.html') ||
name.endsWith('.protoascii'))
);
Expand Down
11 changes: 8 additions & 3 deletions build-system/pr-check/validator-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const {runCiJob} = require('./ci-job');
const jobName = 'validator-tests.js';

function pushBuildWorkflow() {
timedExecOrDie('amp validator');
timedExecOrDie('amp validator-webui');
timedExecOrDie('amp validator');
timedExecOrDie('amp validator-cpp');
}

function prBuildWorkflow() {
Expand All @@ -45,12 +46,16 @@ function prBuildWorkflow() {
return;
}

if (buildTargetsInclude(Targets.VALIDATOR_WEBUI)) {
timedExecOrDie('amp validator-webui');
}

if (buildTargetsInclude(Targets.RUNTIME, Targets.VALIDATOR)) {
timedExecOrDie('amp validator');
}

if (buildTargetsInclude(Targets.VALIDATOR_WEBUI)) {
timedExecOrDie('amp validator-webui');
if (buildTargetsInclude(Targets.VALIDATOR)) {
timedExecOrDie('amp validator-cpp');
}
}

Expand Down
17 changes: 17 additions & 0 deletions build-system/tasks/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ async function validator() {
});
}

/**
* Simple wrapper around the C++ validator tests
*/
async function validatorCpp() {
execOrDie(
`bazel test --repo_env=CC=clang --cxxopt='-std=c++17' validator_test`,
{
cwd: 'validator/cpp/engine',
stdio: 'inherit',
}
);
}

/**
* Simple wrapper around the python based validator webui build.
*/
Expand All @@ -45,6 +58,7 @@ async function validatorWebui() {

module.exports = {
validator,
validatorCpp,
validatorWebui,
};

Expand All @@ -53,6 +67,9 @@ validator.flags = {
'update_tests': 'Updates validation test output files',
};

validatorCpp.description = 'Builds and tests the AMP C++ validator.';
// TODO(antiphoton): Add the ability to update validation test output files.

validatorWebui.description = 'Builds and tests the AMP validator web UI.';
validatorWebui.flags = {
'update_tests': 'Updates validation test output files',
Expand Down
2 changes: 2 additions & 0 deletions validator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ dist/
node_modules/
# The Python interpreter generates these.
*.pyc
# These directories are generated by bazel
bazel-*

0 comments on commit 998fd11

Please sign in to comment.