Skip to content

Commit

Permalink
Merge pull request #424 from projectsyn/feat/component-template/renov…
Browse files Browse the repository at this point in the history
…ate-postupgrade-tasks

Add logic to generate Renovate `postUpgradeTasks` in the component template
  • Loading branch information
simu authored Mar 21, 2022
2 parents 7de2a2b + 1903a2d commit 9022ac6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 9 deletions.
20 changes: 11 additions & 9 deletions commodore/component-template/{{ cookiecutter.slug }}/.sync.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
:global:
componentName: {{ cookiecutter.name }}
githubUrl: {{ cookiecutter.github_url }}
feature_goldenTests: true
feature_goldenTests: {% if cookiecutter.add_golden == "y" %}true{% else %}false{% endif %}
{%- if cookiecutter.add_matrix == "y" %}
testMatrix:
key: instance
entries:
- defaults

{%- endif %}

docs/antora.yml:
name: {{ cookiecutter.slug }}
title: {{ cookiecutter.name }}
{% if cookiecutter.add_matrix == "y" -%}
{%- if cookiecutter.add_matrix == "y" %}

.github/workflows/test.yaml:
test_makeTarget: test -e instance={% raw %}${{ matrix.instance }}{% endraw %}
{%- if cookiecutter.add_golden == "y" %}
goldenTest_makeTarget: golden-diff -e instance={% raw %}${{ matrix.instance }}{% endraw %}
{%- endif %}
matrix:
key: instance
entries:
- defaults
{% endif -%}
{%- endif -%}
{% endif %}
14 changes: 14 additions & 0 deletions commodore/component-template/{{ cookiecutter.slug }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ gen-golden: clean .compile ## Update the reference version for target `golden-di
golden-diff: commodore_args += -f tests/$(instance).yml
golden-diff: clean .compile ## Diff compile output against the reference version. Review output and run `make gen-golden golden-diff` if this target fails.
@git diff --exit-code --minimal --no-index -- tests/golden/$(instance) compiled/
{%- if cookiecutter.add_matrix == "y" %}

.PHONY: golden-diff-all
golden-diff-all: recursive_target=golden-diff
golden-diff-all: $(test_instances) ## Run golden-diff for all instances. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).

.PHONY: gen-golden-all
gen-golden-all: recursive_target=gen-golden
gen-golden-all: $(test_instances) ## Run gen-golden for all instances. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).

.PHONY: $(test_instances)
$(test_instances):
$(MAKE) $(recursive_target) -e instance=$(basename $(@F))
{%- endif -%}
{%- endif %}

.PHONY: clean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ COMMODORE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) docker.io/projects
JB_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) --entrypoint /usr/local/bin/jb docker.io/projectsyn/commodore:latest install

instance ?= defaults
{%- if cookiecutter.add_matrix == "y" and cookiecutter.add_golden == "y" %}
test_instances = tests/defaults.yml
{%- endif %}
14 changes: 14 additions & 0 deletions commodore/component-template/{{ cookiecutter.slug }}/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
":gitSignOff",
":disableDependencyDashboard"
],
{%- if cookiecutter.add_golden == "y" %}
"postUpgradeTasks": {
"commands": [
{%- if cookiecutter.add_matrix == "y" %}
"make gen-golden-all"
{%- else %}
"make gen-golden"
{%- endif %}
],
"fileFilters": [ "tests/golden/**" ],
"executionMode": "update"
},
"suppressNotifications": [ "artifactErrors" ],
{%- endif %}
"labels": [
"dependency"
]
Expand Down
32 changes: 32 additions & 0 deletions tests/test_component_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for component new command
"""
import json
import os
import pytest
import yaml
Expand Down Expand Up @@ -140,6 +141,37 @@ def test_run_component_new_command(
else:
assert run_step["run"] == "make golden-diff"

with open(tmp_path / "dependencies" / component_name / ".sync.yml") as syncyml:
syncconfig = yaml.safe_load(syncyml)
assert ":global" in syncconfig

globalconfig = syncconfig[":global"]
assert "componentName" in globalconfig
assert "feature_goldenTests" in globalconfig
assert ("testMatrix" in globalconfig) == has_matrix

assert globalconfig["componentName"] == component_name
assert globalconfig["feature_goldenTests"] == has_golden

assert (".github/workflows/test.yaml" in syncconfig) == has_matrix
if has_matrix:
ghconfig = syncconfig[".github/workflows/test.yaml"]
assert ("goldenTest_makeTarget" in ghconfig) == has_golden

with open(
tmp_path / "dependencies" / component_name / "renovate.json"
) as renovatejson:
renovateconfig = json.load(renovatejson)
assert ("postUpgradeTasks" in renovateconfig) == has_golden
if has_golden:
assert len(renovateconfig["postUpgradeTasks"]["commands"]) == 1
cmd = renovateconfig["postUpgradeTasks"]["commands"][0]
expected_cmd = {
"--matrix-tests": "make gen-golden-all",
"--no-matrix-tests": "make gen-golden",
}
assert cmd == expected_cmd[matrix]


def test_run_component_new_command_with_name(tmp_path: P):
"""
Expand Down

0 comments on commit 9022ac6

Please sign in to comment.