diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7e8348b --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length=100 +exclude= + .git, + .venv \ No newline at end of file diff --git a/.github/workflows/bump-submitty.yml b/.github/workflows/bump-submitty.yml new file mode 100644 index 0000000..95c7697 --- /dev/null +++ b/.github/workflows/bump-submitty.yml @@ -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/github-action-json-property@v0.2.0 + 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/peter-evans-create-pull-request@v23.07.00 + 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 }})." diff --git a/.github/workflows/localization-ci.yml b/.github/workflows/localization-ci.yml new file mode 100644 index 0000000..2a72e49 --- /dev/null +++ b/.github/workflows/localization-ci.yml @@ -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 diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..5bbd9ac --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -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 + # + # [:] + # + - uses: submitty/action-pr-title@main diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cafc1c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv/ \ No newline at end of file diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..95af6ab --- /dev/null +++ b/.yamllint @@ -0,0 +1,10 @@ +extends: default + +rules: + line-length: disable + truthy: disable + document-start: disable + +ignore: + .git + .venv diff --git a/bin/update-version.py b/bin/update-version.py new file mode 100644 index 0000000..a81b428 --- /dev/null +++ b/bin/update-version.py @@ -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[\'\"])(?P[\w\.]+?)\s*?(?P=q1)" + r",\s*?(?P[\'\"])(?P.+?)(? 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() diff --git a/config.json b/config.json new file mode 100644 index 0000000..f8e4e6a --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "submitty_version": "v23.08.00" +} diff --git a/lang/en_US.json b/lang/en_US.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/lang/en_US.json @@ -0,0 +1 @@ +{}