Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/update-syntax-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Update syntax-description

on:
schedule:
- cron: "0 7 * * 1" # Run every Monday at 7am UTC
# | | | | |
# | | | | day of the week (0-6) (Sunday to Saturday)
# | | | month (1-12)
# | | day of the month (1-31)
# | hour (0-23)
# minute (0-59)
workflow_dispatch: # Enables manual trigger

jobs:
update_syntax_desc:
name: Update syntax-description
runs-on: ubuntu-24.04
permissions:
contents: write
pull-requests: write
steps:
- name: Checks-out repository
uses: actions/checkout@v4
with:
ref: "main"
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install cf-remote
- name: Install cfengine
run: |
cf-remote --version master download --edition community ubuntu24 amd64 hub
sudo dpkg -i ~/.cfengine/cf-remote/packages/cfengine-community*.deb

- name: Extract new syntax-description
run: |
(
sudo cf-promises --syntax-description json
) > new.json
echo "" >> new.json
- name: Set Git user
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Update contents of syntax-description
run: |
if ! cmp -s new.json ./src/cfengine_cli/syntax-description.json; then
cat new.json > ./src/cfengine_cli/syntax-description.json
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
rm new.json
fi
- name: Create Pull Request
if: env.CHANGES_DETECTED == 'true'
uses: cfengine/create-pull-request@v6
with:
title: Updated syntax-description.json
body: Automated update to syntax-description.json [the `update-syntax-description` workflow](https://github.com/cfengine/cfengine-cli/tree/main/.github/workflows/update-syntax-description.yml).
reviewers: |
simonthalvorsen
olehermanse
larsewi
nickanderson
craigcomstock
branch: update-syntax-description
branch-suffix: timestamp
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ cfengine = "cfengine_cli.main:main"
[tool.setuptools]
license-files = [] # Workaround bug in setuptools https://github.com/astral-sh/uv/issues/9513

[tool.setuptools.package-data]
cfengine_cli = ["*.json"] # syntax-description.json

[tool.pyright]
include = ["src"]
venvPath = "."
Expand Down
51 changes: 45 additions & 6 deletions src/cfengine_cli/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,56 @@
from cfbs.validate import validate_config
from cfbs.cfbs_config import CFBSConfig
from cfbs.utils import find
from cfengine_cli.policy_language import (
DEPRECATED_PROMISE_TYPES,
ALLOWED_BUNDLE_TYPES,
BUILTIN_PROMISE_TYPES,
BUILTIN_FUNCTIONS,
)
from cfengine_cli.utils import UserError

LINT_EXTENSIONS = (".cf", ".json")


def _load_syntax_description(path: str | None = None) -> dict:
"""Load and return the parsed syntax-description.json file."""
if path is None:
path = os.path.join(os.path.dirname(__file__), "syntax-description.json")
with open(path, "r") as f:
return json.load(f)


def _derive_syntax_sets(data: dict) -> tuple:
"""Derive the four sets used for linting from a loaded syntax-description dict.

Returns: (ALLOWED_BUNDLE_TYPES, BUILTIN_PROMISE_TYPES, BUILTIN_FUNCTIONS, DEPRECATED_PROMISE_TYPES)
"""
builtin_body_types = set(data.get("bodyTypes", {}).keys())

allowed_bundle_types = data.get("bundleTypes", {}).keys()

builtin_promise_types = set(data.get("promiseTypes", {}).keys())

builtin_functions = set(data.get("functions", {}).keys())

deprecated_promise_types = {
"defaults",
"guest_environments",
} # Has to be hardcoded, not tagged in syntax-description.json

return (
builtin_body_types,
allowed_bundle_types,
builtin_promise_types,
builtin_functions,
deprecated_promise_types,
)


_SYNTAX_DATA = _load_syntax_description()
(
_,
ALLOWED_BUNDLE_TYPES,
BUILTIN_PROMISE_TYPES,
BUILTIN_FUNCTIONS,
DEPRECATED_PROMISE_TYPES,
) = _derive_syntax_sets(_SYNTAX_DATA)


def _qualify(name: str, namespace: str) -> str:
"""If name is already qualified (contains ':'), return as-is. Otherwise prepend namespace."""
assert '"' not in namespace
Expand Down
239 changes: 0 additions & 239 deletions src/cfengine_cli/policy_language.py

This file was deleted.

Loading
Loading