Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length=100
exclude=
.git,
.venv
50 changes: 50 additions & 0 deletions .github/workflows/bump-submitty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Bump Submitty

on:
repository_dispatch:
types: [version-up]
workflow_dispatch:

jobs:
update-submitty:
runs-on: ubuntu-latest
name: Update Submitty
steps:
- name: Checkout Submitty Repository
uses: actions/checkout@v3
with:
repository: ${{ github.repository_owner }}/Submitty
sparse-checkout: |
site/app/templates
sparse-checkout-cone-mode: false
ref: ${{ github.event.client_payload.ref }}
path: Submitty

- name: Checkout Localization Repository
uses: actions/checkout@v3
with:
path: Localization

- name: Get version
id: version
uses: notiz-dev/[email protected]
with:
path: Localization/config.json
prop_path: submitty_version

- uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Run Version Update
run: python3 Localization/bin/update-version.py -v ${{ github.event.client_payload.ref_name }}

- name: Create Pull Request
uses: Submitty/[email protected]
with:
token: ${{ secrets.SUBMITTYBOT_DEPENDENCY_TOKEN }}
path: Localization
commit-message: update version and base lang to ${{ github.event.client_payload.ref_name }}
branch: bump-submitty/${{ github.event.client_payload.ref_name }}
title: "[Dependency] Update Submitty from ${{ steps.version.outputs.prop }} to ${{ github.event.client_payload.ref_name }}"
body: "Bumps [Submitty](https://github.com/${{ github.repository_owner }}/Submitty) from version [${{ steps.version.outputs.prop }}](https://github.com/${{ github.repository_owner }}/Submitty/releases/tag/${{ steps.version.outputs.prop }}) to [${{ github.event.client_payload.ref_name }}](https://github.com/${{ github.repository_owner }}/Submitty/releases/tag/${{ github.event.client_payload.ref_name }})."
34 changes: 34 additions & 0 deletions .github/workflows/localization-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Localization CI

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
yaml-lint:
name: YAML Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install yamllint
run: sudo apt-get install -y yamllint
- name: Run yamllint
run: yamllint .

python-lint:
name: Python Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install flake8
run: |
python3 -m pip install --upgrade pip
python3 -m pip install flake8 flake8-bugbear
- name: Run flake8
run: python3 -m flake8
20 changes: 20 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Submitty PR Title Check'
on:
pull_request:
# check when PR
# * is created,
# * title is edited, and
# * new commits are added (to ensure failing title blocks merging)
types: [opened, reopened, edited, synchronize]

jobs:
title-check:
runs-on: ubuntu-latest
steps:
#
# pull request titles format rules here:
# https://submitty.org/developer/how_to_contribute#how-to-make-a-pull-request-pr-to-submitty
#
# [<TYPE>:<MODULE>] <SUBJECT>
#
- uses: submitty/action-pr-title@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv/
10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends: default

rules:
line-length: disable
truthy: disable
document-start: disable

ignore:
.git
.venv
105 changes: 105 additions & 0 deletions bin/update-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import json
import re
from argparse import ArgumentParser, Namespace
from collections import OrderedDict
from pathlib import Path


def get_args() -> Namespace:
parser = ArgumentParser(prog='update-version')
parser.add_argument('-v', '--version', required=True)
return parser.parse_args()


def get_template_data() -> dict:
pattern = re.compile(r"localize\s*?\(\s*?(?P<q1>[\'\"])(?P<key>[\w\.]+?)\s*?(?P=q1)"
r",\s*?(?P<q2>[\'\"])(?P<val>.+?)(?<!\\\\)(?P=q2)\s*?.*?\)")

template_path = Path(__file__).parent.parent.parent / 'Submitty' / 'site' / 'app' / 'templates'
if not template_path.is_dir():
raise NotADirectoryError('Could not locate template directory.')

data = dict()

# Loop through template files
for child in template_path.iterdir():
if not child.is_file() or child.suffix != '.twig':
continue

# Split into template blocks {{ }}
body = child.read_text()
parts = [part.split('}}')[0] for part in body.split('{{')[1:]]

for part in parts:
for match in re.finditer(pattern, part):
group = match.groupdict()
tree = group.get('key').split('.')
val = group.get('val')

last_key = tree.pop()

loc = data # Current location in tree (should always be dict)
for key in tree:
if key in loc:
loc = loc[key]
if not isinstance(loc, dict):
raise KeyError('Duplicate template key found: ' + key)
else:
loc[key] = dict()
loc = loc[key]

if not isinstance(loc, dict):
raise KeyError('Duplicate template key found: ' + key)
loc[last_key] = val

return data


def update_data(original: OrderedDict, updated: dict) -> OrderedDict:
result = OrderedDict()

# Update existing keys
for key, val in original.items():
if key not in updated:
continue

if isinstance(val, OrderedDict) and isinstance(updated[key], dict):
result[key] = update_data(val, updated[key])
else:
result[key] = updated[key]

# Add new keys
for key, val in updated.items():
if key not in original:
if isinstance(val, dict):
result[key] = OrderedDict(val)
else:
result[key] = val

return result


def main():
args = get_args()

repo_path = Path(__file__).parent.parent
if not repo_path.is_dir():
raise NotADirectoryError('Could not locate repository.')

# Update version in JSON file
with (repo_path / 'config.json').open() as file:
data = json.load(file, object_pairs_hook=OrderedDict)
data['submitty_version'] = args.version
with (repo_path / 'config.json').open('w') as file:
json.dump(data, file, indent=2)

# Update default lang data
with (repo_path / 'lang' / 'en_US.json').open() as file:
json_data = json.load(file, object_pairs_hook=OrderedDict)
json_data = update_data(json_data, get_template_data())
with (repo_path / 'lang' / 'en_US.json').open('w') as file:
json.dump(json_data, file, indent=4)


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"submitty_version": "v23.08.00"
}
1 change: 1 addition & 0 deletions lang/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}