Skip to content

Commit

Permalink
Add actionlint with shellcheck integration to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Aug 18, 2024
1 parent c7cc4f3 commit 0317ede
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
10 changes: 10 additions & 0 deletions project/.pre-commit-config.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def author_email(request):
return getattr(request, "param", "[email protected]")


@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
Expand All @@ -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}
Expand Down
17 changes: 4 additions & 13 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
]

Expand Down Expand Up @@ -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
Expand All @@ -77,7 +78,6 @@ def test_first_commit_works(project):
"answers",
(
{
"loaders": COPIER_CONF["loaders"]["choices"],
"test_containers": True,
},
),
Expand All @@ -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)
Expand Down

0 comments on commit 0317ede

Please sign in to comment.