Skip to content

Commit 4f2c9f7

Browse files
authored
ci(java): run dependency test on Java 8 and 11 (#639)
Redo fix in #633 with proper jinja templating format
1 parent 873bd44 commit 4f2c9f7

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

synthtool/gcp/templates/java_library/.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ jobs:
3636
JOB_TYPE: test
3737
dependencies:
3838
runs-on: ubuntu-latest
39+
strategy:
40+
matrix:
41+
java: [8, 11]
3942
steps:
4043
- uses: actions/checkout@v2
4144
- uses: actions/setup-java@v1
4245
with:
43-
java-version: 8
46+
java-version: ${{'{{matrix.java}}'}}
4447
- run: java -version
4548
- run: .kokoro/dependencies.sh
4649
linkage-monitor:

synthtool/gcp/templates/java_library/.kokoro/dependencies.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ echo "****************** DEPENDENCY LIST COMPLETENESS CHECK *******************"
4141
## Run dependency list completeness check
4242
function completenessCheck() {
4343
# Output dep list with compile scope generated using the original pom
44+
# Running mvn dependency:list on Java versions that support modules will also include the module of the dependency.
45+
# This is stripped from the output as it is not present in the flattened pom.
4446
msg "Generating dependency list using original pom..."
45-
mvn dependency:list -f pom.xml -Dsort=true | grep '\[INFO] .*:.*:.*:.*:.*' | grep -v ':test$' >.org-list.txt
47+
mvn dependency:list -f pom.xml -Dsort=true | grep '\[INFO] .*:.*:.*:.*:.*' | sed -e s/\\s--\\smodule.*// | grep -v ':test$' >.org-list.txt
4648

4749
# Output dep list generated using the flattened pom (test scope deps are ommitted)
4850
msg "Generating dependency list using flattened pom..."

tests/test_language_java.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import glob
1615
import os
1716
import shutil
1817
import tempfile
1918
import xml.etree.ElementTree as ET
19+
import yaml
2020
from pathlib import Path
2121
from synthtool.languages import java
2222
import requests_mock
@@ -83,6 +83,13 @@ def assert_valid_xml(file):
8383
except ET.ParseError:
8484
pytest.fail(f"unable to parse XML: {file}")
8585

86+
def assert_valid_yaml(file):
87+
with open(file, "r") as stream:
88+
try:
89+
yaml.safe_load(stream)
90+
except yaml.YAMLError:
91+
pytest.fail(f"unable to parse YAML: {file}")
92+
8693
with tempfile.TemporaryDirectory() as tempdir:
8794
workdir = shutil.copytree(
8895
FIXTURES / "java_templates" / "standard", Path(tempdir) / "standard"
@@ -95,8 +102,14 @@ def assert_valid_xml(file):
95102
java.common_templates(template_path=TEMPLATES_PATH)
96103
assert os.path.isfile("README.md")
97104

98-
# ensure pom.xml files are valid XML
99-
for file in glob.glob("**/pom.xml", recursive=True):
100-
assert_valid_xml(file)
105+
# lint xml, yaml files
106+
# use os.walk because glob ignores hidden directories
107+
for (dirpath, _, filenames) in os.walk(tempdir):
108+
for file in filenames:
109+
(_, ext) = os.path.splitext(file)
110+
if ext == ".xml":
111+
assert_valid_xml(os.path.join(dirpath, file))
112+
elif ext == ".yaml" or ext == ".yml":
113+
assert_valid_yaml(os.path.join(dirpath, file))
101114
finally:
102115
os.chdir(cwd)

0 commit comments

Comments
 (0)