diff --git a/project/.pre-commit-config.yaml.j2 b/project/.pre-commit-config.yaml.j2 index 8388bcd..a15465f 100755 --- a/project/.pre-commit-config.yaml.j2 +++ b/project/.pre-commit-config.yaml.j2 @@ -136,4 +136,14 @@ repos: - -e - lint-tests-pre-commit - -- + +{%- if "github.com" in source_url %} + + - repo: https://github.com/Mateusz-Grzelinski/actionlint-py + rev: v1.7.1.15 + hooks: + - id: actionlint + additional_dependencies: + - shellcheck-py>=0.9.0.5 +{%- endif %} # <---- Code Analysis -------------------------------------------------------------------------- diff --git a/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows == 'enhanced' %}test-action.yml{% endif %}.j2 b/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows == 'enhanced' %}test-action.yml{% endif %}.j2 index 4dde87c..c75b6ff 100644 --- a/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows == 'enhanced' %}test-action.yml{% endif %}.j2 +++ b/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows == 'enhanced' %}test-action.yml{% endif %}.j2 @@ -85,7 +85,7 @@ jobs: n=0 until [ "$n" -ge 5 ] do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then + if bash codecov.sh -R "$(pwd)" -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then break fi n=$((n+1)) @@ -118,7 +118,7 @@ jobs: n=0 until [ "$n" -ge 5 ] do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then + if bash codecov.sh -R "$(pwd)" -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then break fi n=$((n+1)) @@ -176,12 +176,14 @@ jobs: - name: Download libeay32.dll run: | - export PY_LOC=$(which python.exe) - echo ${PY_LOC} - export PY_DIR=$(dirname ${PY_LOC}) - echo ${PY_DIR} - curl https://repo.saltproject.io/windows/dependencies/64/libeay32.dll --output ${PY_DIR}/libeay32.dll - ls -l ${PY_DIR} + PY_LOC="$(which python.exe)" + export PY_LOC + echo "${PY_LOC}" + PY_DIR="$(dirname "${PY_LOC}")" + export PY_DIR + echo "${PY_DIR}" + curl https://repo.saltproject.io/windows/dependencies/64/libeay32.dll --output "${PY_DIR}/libeay32.dll" + ls -l "${PY_DIR}" shell: bash - name: Install Nox @@ -238,7 +240,7 @@ jobs: n=0 until [ "$n" -ge 5 ] do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then + if bash codecov.sh -R "$(pwd)" -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then break fi n=$((n+1)) @@ -271,7 +273,7 @@ jobs: n=0 until [ "$n" -ge 5 ] do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then + if bash codecov.sh -R "$(pwd)" -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then break fi n=$((n+1)) @@ -384,7 +386,7 @@ jobs: n=0 until [ "$n" -ge 5 ] do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then + if bash codecov.sh -R "$(pwd)" -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then break fi n=$((n+1)) @@ -417,7 +419,7 @@ jobs: n=0 until [ "$n" -ge 5 ] do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then + if bash codecov.sh -R "$(pwd)" -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then break fi n=$((n+1)) diff --git a/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows in ['org', 'enhanced'] %}tag.yml{% endif %}.j2 b/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows in ['org', 'enhanced'] %}tag.yml{% endif %}.j2 index a0c4e95..1237bd5 100644 --- a/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows in ['org', 'enhanced'] %}tag.yml{% endif %}.j2 +++ b/project/{% if 'github.com' in source_url %}.github{% endif %}/workflows/{% if workflows in ['org', 'enhanced'] %}tag.yml{% endif %}.j2 @@ -24,7 +24,7 @@ jobs: - name: Extract tag name id: get_version - run: echo "version=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_OUTPUT + run: echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT" call_central_workflow: needs: get_tag_version diff --git a/tests/conftest.py b/tests/conftest.py index 7ae1394..b7f3e63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,6 +35,11 @@ def author_email(request): return getattr(request, "param", "foo@b.ar") +@pytest.fixture +def loaders(copier_yaml, request): + return getattr(request, "param", copier_yaml["loaders"]["choices"]) + + @pytest.fixture(params=(False,)) def no_saltext_namespace(request): return request.param @@ -53,13 +58,21 @@ def source_url(project_name, request): raise ValueError(f"Invalid parameter for source_url: '{request.param}'") +@pytest.fixture +def workflows(source_url, request): + default = "org" if "github.com/salt-extensions/" in source_url else "enhanced" + return getattr(request, "param", default) + + @pytest.fixture(params=((),)) -def answers(author, author_email, no_saltext_namespace, project_name, request): +def answers(author, author_email, loaders, no_saltext_namespace, project_name, workflows, request): defaults = { "project_name": project_name, "author": author, "author_email": author_email, + "loaders": loaders, "no_saltext_namespace": no_saltext_namespace, + "workflows": workflows, } defaults.update(request.param) return {k: v for k, v in defaults.items() if v is not None} diff --git a/tests/test_basics.py b/tests/test_basics.py index 9b5dc54..9d00905 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -2,18 +2,17 @@ from plumbum import ProcessExecutionError from plumbum import local -from tests.helpers.copier_hlp import load_copier_yaml from tests.helpers.venv import ProjectVenv -COPIER_CONF = load_copier_yaml() - pytestmark = [ pytest.mark.usefixtures( "author", "author_email", "project_name", "no_saltext_namespace", + "loaders", "source_url", + "workflows", ), ] @@ -62,6 +61,8 @@ def _commit_with_pre_commit(venv, max_retry=3, message="initial commit"): raise saved_err +# We need to test both org and enhanced workflows (with actionlint/shellcheck) +@pytest.mark.parametrize("source_url", ("org", "non_org"), indirect=True) def test_first_commit_works(project): """ Ensure the generated project can be committed after generation @@ -77,7 +78,6 @@ def test_first_commit_works(project): "answers", ( { - "loaders": COPIER_CONF["loaders"]["choices"], "test_containers": True, }, ), @@ -92,15 +92,6 @@ def test_testsuite_works(project, project_venv): @pytest.mark.parametrize("no_saltext_namespace", (False, True), indirect=True) -@pytest.mark.parametrize( - "answers", - ( - { - "loaders": COPIER_CONF["loaders"]["choices"], - }, - ), - indirect=True, -) def test_docs_build_works(project, project_venv): with ProjectVenv(project) as venv, local.cwd(project): _commit_with_pre_commit(venv, max_retry=3)