Skip to content

Commit

Permalink
Merge pull request #22 from mxstack/rnixx-gh-actions
Browse files Browse the repository at this point in the history
Add basic CI config file generation for github actions.
  • Loading branch information
rnixx authored Feb 6, 2024
2 parents 761252e + 71c9cb8 commit abf239d
Show file tree
Hide file tree
Showing 19 changed files with 273 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:

- run: npm install -g @mermaid-js/mermaid-cli

- name: Install dependencies
- name: Install Project
run: make install

- name: Sphinx build
- name: Generate Docs
run: make docs

- name: Deploy
- name: Deploy Docs
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
if: ${{ github.event_name == 'workflow_dispatch' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/codestyle.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: psf/black@stable

- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Dependencies
- name: Install Project
run: make install

- name: ruff
run: make ruff-check

- name: isort
run: make isort-check
- name: Run checks
run: make check
18 changes: 9 additions & 9 deletions .github/workflows/test.yaml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test mxmake
name: Tests

on: [push]

Expand All @@ -10,18 +10,18 @@ jobs:
fail-fast: false
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v3

- name: Install project
- name: Install Project
run: make install

- name: Run tests
- name: Run Tests
run: make test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: mypy
name: Typechecks

on: [push]

Expand All @@ -14,8 +14,8 @@ jobs:
with:
python-version: 3.9

- name: Install Dependencies
- name: Install Project
run: make install

- name: mypy
run: make mypy
- name: Run Typechecks
run: make typecheck
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 1.0a3.dev0 (unreleased)

- Add `typecheck` target and use it for mypy instead of `check` target.

- Add basic CI config file generation for github actions.

- Add `ruff` domain to `qa` topic.

- Fix exporting path in `jsdoc` target.
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ DIRTY_TARGETS?=
CLEAN_TARGETS?=
PURGE_TARGETS?=
CHECK_TARGETS?=
TYPECHECK_TARGETS?=
FORMAT_TARGETS?=

# Defensive settings for make: https://tech.davis-hansson.com/p/make/
Expand Down Expand Up @@ -511,7 +512,7 @@ mypy-clean: mypy-dirty
@rm -rf .mypy_cache

INSTALL_TARGETS+=$(MYPY_TARGET)
CHECK_TARGETS+=mypy
TYPECHECK_TARGETS+=mypy
CLEAN_TARGETS+=mypy-clean
DIRTY_TARGETS+=mypy-dirty

Expand Down Expand Up @@ -556,5 +557,8 @@ runtime-clean:
.PHONY: check
check: $(CHECK_TARGETS)

.PHONY: typecheck
typecheck: $(TYPECHECK_TARGETS)

.PHONY: format
format: $(FORMAT_TARGETS)
17 changes: 17 additions & 0 deletions src/mxmake/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mxmake.parser import MakefileParser
from mxmake.templates import ci_template
from mxmake.templates import get_template_environment
from mxmake.templates import template
from mxmake.topics import collect_missing_dependencies
Expand Down Expand Up @@ -197,6 +198,22 @@ def init_command(args: argparse.Namespace):
else:
print("Skip generation of mx configuration file, file already exists")

# ci generation
print("\nDo you want to create CI related files?")
yn = inquirer.text(message="y/N")
if yn in ["y", "Y"]:
# ci_template
ci_choice = inquirer.prompt(
[
inquirer.Checkbox(
"ci", message="Generate CI files", choices=ci_template.templates
)
]
)
for template_name in ci_choice["ci"]:
factory = template.lookup(template_name)
factory(get_template_environment()).write()


init_parser = command_parsers.add_parser("init", help="Initialize project")
init_parser.set_defaults(func=init_command)
Expand Down
76 changes: 75 additions & 1 deletion src/mxmake/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from jinja2 import PackageLoader
from mxmake.topics import Domain
from mxmake.topics import load_topics
from mxmake.utils import gh_actions_path
from mxmake.utils import mxenv_path
from mxmake.utils import mxmake_files
from mxmake.utils import ns_name
Expand Down Expand Up @@ -378,7 +379,7 @@ def write(self) -> None:


##############################################################################
# dependencies.rst template
# dependencies.md template
##############################################################################


Expand All @@ -404,3 +405,76 @@ def write(self) -> None:
raise NotImplementedError(
"Dependencies template is not supposed to be written to file system"
)


##############################################################################
# CI
##############################################################################


class ci_template:
templates: typing.List = list()

def __init__(self, name: str) -> None:
self.name = name

def __call__(self, ob: typing.Type["Template"]) -> typing.Type["Template"]:
template(self.name)(ob)
self.templates.append(self.name)
return ob


class GHActionsTemplate(Template):
template_variables = dict()

@property
def target_folder(self) -> str:
return gh_actions_path()


##############################################################################
# gh-actions-docs template
##############################################################################


@ci_template("gh-actions-docs")
class GHActionsDocs(GHActionsTemplate):
description: str = "Github action for generating docs"
target_name = "docs.yml"
template_name = "gh-actions-docs.yml"


##############################################################################
# gh-actions-lint template
##############################################################################


@ci_template("gh-actions-lint")
class GHActionsLint(GHActionsTemplate):
description: str = "Github action to run linting"
target_name = "lint.yml"
template_name = "gh-actions-lint.yml"


##############################################################################
# gh-actions-test template
##############################################################################


@ci_template("gh-actions-test")
class GHActionsTest(GHActionsTemplate):
description: str = "Github action to run tests"
target_name = "test.yml"
template_name = "gh-actions-test.yml"


##############################################################################
# gh-actions-typecheck template
##############################################################################


@ci_template("gh-actions-typecheck")
class GHActionsTypecheck(GHActionsTemplate):
description: str = "Github action to running static type checks"
target_name = "typecheck.yml"
template_name = "gh-actions-typecheck.yml"
4 changes: 4 additions & 0 deletions src/mxmake/templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CLEAN_TARGETS?=
PURGE_TARGETS?=
{% if additional_targets["qa"] %}
CHECK_TARGETS?=
TYPECHECK_TARGETS?=
FORMAT_TARGETS?=
{% endif %}
{{ sections.read() }}
Expand Down Expand Up @@ -80,6 +81,9 @@ runtime-clean:
.PHONY: check
check: $(CHECK_TARGETS)

.PHONY: typecheck
typecheck: $(TYPECHECK_TARGETS)

.PHONY: format
format: $(FORMAT_TARGETS)
{% endif %}
31 changes: 31 additions & 0 deletions src/mxmake/templates/gh-actions-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Docs

on: [push, workflow_dispatch]

jobs:
docs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/setup-node@v3
with:
node-version: 16

- run: npm install -g @mermaid-js/mermaid-cli

- name: Install Project
run: make install

- name: Generate Docs
run: make docs

- name: Deploy Docs
uses: peaceiris/actions-gh-pages@v3
if: {{ "${{ github.event_name == 'workflow_dispatch' }}" }}
with:
publish_branch: gh-pages
github_token: {{ "${{ secrets.GITHUB_TOKEN }}" }}
publish_dir: docs/html/
force_orphan: true
21 changes: 21 additions & 0 deletions src/mxmake/templates/gh-actions-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint

on: [push]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Project
run: make install

- name: Run checks
run: make check
27 changes: 27 additions & 0 deletions src/mxmake/templates/gh-actions-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tests

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v3

- name: Install Project
run: make install

- name: Run Tests
run: make test
21 changes: 21 additions & 0 deletions src/mxmake/templates/gh-actions-typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Typechecks

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Project
run: make install

- name: Run Typechecks
run: make typecheck
2 changes: 2 additions & 0 deletions src/mxmake/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def wrapper(*a):
tempdir = tempfile.mkdtemp()
os.environ["MXMAKE_FILES"] = tempdir
os.environ["MXMAKE_MXENV_PATH"] = tempdir
os.environ["MXMAKE_GH_ACTIONS_PATH"] = tempdir
try:
if self.reset_registry:
with reset_template_registry():
Expand All @@ -51,6 +52,7 @@ def wrapper(*a):
shutil.rmtree(tempdir)
del os.environ["MXMAKE_FILES"]
del os.environ["MXMAKE_MXENV_PATH"]
del os.environ["MXMAKE_GH_ACTIONS_PATH"]

return wrapper

Expand Down
Loading

0 comments on commit abf239d

Please sign in to comment.