Skip to content

Commit

Permalink
ci(java): run dependency test on Java 8 and 11 (#639)
Browse files Browse the repository at this point in the history
Redo fix in #633 with proper jinja templating format
  • Loading branch information
chingor13 authored Jun 19, 2020
1 parent 873bd44 commit 4f2c9f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion synthtool/gcp/templates/java_library/.kokoro/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
21 changes: 17 additions & 4 deletions tests/test_language_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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)

0 comments on commit 4f2c9f7

Please sign in to comment.