diff --git a/synthtool/gcp/templates/java_library/.github/workflows/ci.yaml b/synthtool/gcp/templates/java_library/.github/workflows/ci.yaml index abab8a501..610a25f8c 100644 --- a/synthtool/gcp/templates/java_library/.github/workflows/ci.yaml +++ b/synthtool/gcp/templates/java_library/.github/workflows/ci.yaml @@ -36,11 +36,14 @@ jobs: JOB_TYPE: test dependencies: runs-on: ubuntu-latest + strategy: + matrix: + java: [8, 11] steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: - java-version: 8 + java-version: ${{'{{matrix.java}}'}} - run: java -version - run: .kokoro/dependencies.sh linkage-monitor: diff --git a/synthtool/gcp/templates/java_library/.kokoro/dependencies.sh b/synthtool/gcp/templates/java_library/.kokoro/dependencies.sh index cf3bb4347..cee4f11e7 100755 --- a/synthtool/gcp/templates/java_library/.kokoro/dependencies.sh +++ b/synthtool/gcp/templates/java_library/.kokoro/dependencies.sh @@ -41,8 +41,10 @@ echo "****************** DEPENDENCY LIST COMPLETENESS CHECK *******************" ## Run dependency list completeness check function completenessCheck() { # Output dep list with compile scope generated using the original pom + # Running mvn dependency:list on Java versions that support modules will also include the module of the dependency. + # This is stripped from the output as it is not present in the flattened pom. msg "Generating dependency list using original pom..." - mvn dependency:list -f pom.xml -Dsort=true | grep '\[INFO] .*:.*:.*:.*:.*' | grep -v ':test$' >.org-list.txt + mvn dependency:list -f pom.xml -Dsort=true | grep '\[INFO] .*:.*:.*:.*:.*' | sed -e s/\\s--\\smodule.*// | grep -v ':test$' >.org-list.txt # Output dep list generated using the flattened pom (test scope deps are ommitted) msg "Generating dependency list using flattened pom..." diff --git a/tests/test_language_java.py b/tests/test_language_java.py index 3c035ad93..6a2acb17a 100644 --- a/tests/test_language_java.py +++ b/tests/test_language_java.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import glob import os import shutil import tempfile import xml.etree.ElementTree as ET +import yaml from pathlib import Path from synthtool.languages import java import requests_mock @@ -83,6 +83,13 @@ def assert_valid_xml(file): except ET.ParseError: pytest.fail(f"unable to parse XML: {file}") + def assert_valid_yaml(file): + with open(file, "r") as stream: + try: + yaml.safe_load(stream) + except yaml.YAMLError: + pytest.fail(f"unable to parse YAML: {file}") + with tempfile.TemporaryDirectory() as tempdir: workdir = shutil.copytree( FIXTURES / "java_templates" / "standard", Path(tempdir) / "standard" @@ -95,8 +102,14 @@ def assert_valid_xml(file): java.common_templates(template_path=TEMPLATES_PATH) assert os.path.isfile("README.md") - # ensure pom.xml files are valid XML - for file in glob.glob("**/pom.xml", recursive=True): - assert_valid_xml(file) + # lint xml, yaml files + # use os.walk because glob ignores hidden directories + for (dirpath, _, filenames) in os.walk(tempdir): + for file in filenames: + (_, ext) = os.path.splitext(file) + if ext == ".xml": + assert_valid_xml(os.path.join(dirpath, file)) + elif ext == ".yaml" or ext == ".yml": + assert_valid_yaml(os.path.join(dirpath, file)) finally: os.chdir(cwd)