chore: update naming convention and version number when submodules have been updated
This commit is contained in:
parent
49e3f14191
commit
95c315b82d
5 changed files with 132 additions and 71 deletions
53
.github/workflows/update-submodules.yml
vendored
53
.github/workflows/update-submodules.yml
vendored
|
@ -1,39 +1,66 @@
|
||||||
name: Update Submodules
|
name: Update Submodules
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ dev ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update_submodules:
|
check_submodules:
|
||||||
name: Update Submodules
|
name: Check Submodules
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
has_changes: ${{ steps.check.outputs.has_changes }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Create new branch and push changes
|
||||||
|
run: |
|
||||||
|
git submodule update --remote
|
||||||
|
|
||||||
|
- name: Check for changes
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
git diff --quiet || echo "::set-output name=has_changes::true"
|
||||||
|
|
||||||
|
update_submodules:
|
||||||
|
name: Update Submodules
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [check_submodules]
|
||||||
|
if: needs.check_submodules.outputs.has_changes == 'true'
|
||||||
|
steps:
|
||||||
|
|
||||||
- name: Setup Python 3.10.4
|
- name: Setup Python 3.10.4
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: '3.10.4'
|
python-version: '3.10.4'
|
||||||
|
|
||||||
- name: Changing naming convention
|
- name: Setup Poetry
|
||||||
run: |
|
uses: abatilo/actions-poetry@v3
|
||||||
python3 naming.py
|
with:
|
||||||
|
poetry-version: 1.8.2
|
||||||
|
|
||||||
- name: Create new branch and push changes
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
git config user.name github-actions
|
poetry install --no-root
|
||||||
git config user.email github-actions@github.com
|
|
||||||
git submodule update --remote
|
|
||||||
|
|
||||||
- name: Changing naming convention
|
- name: Update Submodule
|
||||||
run: |
|
run: |
|
||||||
python3 naming.py
|
datamodel-codegen --input ./compose-spec/schema/compose-spec.json --output-model-type pydantic_v2.BaseModel --field-constraints --output ./compose_viz/spec/compose_spec.py
|
||||||
git checkout -b $GITHUB_RUN_ID
|
poetry run python ./update-submodules.py
|
||||||
|
|
||||||
|
- name: Execute pre-commit
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
poetry run python -m pre_commit run --all-files
|
||||||
|
|
||||||
- name: Push changes
|
- name: Push changes
|
||||||
run: |
|
run: |
|
||||||
|
git config user.name github-actions
|
||||||
|
git config user.email github-actions@github.com
|
||||||
|
git checkout -b $GITHUB_RUN_ID
|
||||||
git commit -am "chore: update submodules"
|
git commit -am "chore: update submodules"
|
||||||
git push --set-upstream origin $GITHUB_RUN_ID
|
git push --set-upstream origin $GITHUB_RUN_ID
|
||||||
|
|
||||||
|
@ -48,5 +75,5 @@ jobs:
|
||||||
head: process.env.GITHUB_RUN_ID,
|
head: process.env.GITHUB_RUN_ID,
|
||||||
base: 'main',
|
base: 'main',
|
||||||
title: `chore: update submodules (${process.env.GITHUB_RUN_ID})`,
|
title: `chore: update submodules (${process.env.GITHUB_RUN_ID})`,
|
||||||
body: `chore: update submodules (${process.env.GITHUB_RUN_ID})`,
|
body: `Please add the version tag to trigger the release.`,
|
||||||
});
|
});
|
||||||
|
|
20
naming.py
20
naming.py
|
@ -1,20 +0,0 @@
|
||||||
def revise_naming_convention():
|
|
||||||
name_mapping = {
|
|
||||||
"EnvFile1": "EnvFilePath",
|
|
||||||
"Volume1": "AdditionalVolumeOption",
|
|
||||||
"External": "ExternalVolumeNetwork",
|
|
||||||
"External1": "ExternalConfig",
|
|
||||||
}
|
|
||||||
|
|
||||||
with open("./compose_viz/spec/compose_spec.py", "r") as spec_file:
|
|
||||||
spec_content = spec_file.read()
|
|
||||||
|
|
||||||
for origin_name, new_name in name_mapping.items():
|
|
||||||
spec_content.replace(origin_name, new_name)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
revise_naming_convention()
|
|
||||||
print("Revised naming convention successfully!")
|
|
54
update-submodules.py
Normal file
54
update-submodules.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def revise_naming_convention():
|
||||||
|
name_mapping = {
|
||||||
|
"EnvFile1": "EnvFilePath",
|
||||||
|
"Volume1": "AdditionalVolumeOption",
|
||||||
|
"External": "ExternalVolumeNetwork",
|
||||||
|
"External2": "ExternalConfig",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec_content: str
|
||||||
|
with open("./compose_viz/spec/compose_spec.py", "r+") as spec_file:
|
||||||
|
spec_content: str = spec_file.read()
|
||||||
|
|
||||||
|
for origin_name, new_name in name_mapping.items():
|
||||||
|
spec_content = re.sub(rf"\b{origin_name}\b", new_name, spec_content)
|
||||||
|
|
||||||
|
spec_file.seek(0)
|
||||||
|
spec_file.write(spec_content)
|
||||||
|
|
||||||
|
print("Revised naming convention successfully!")
|
||||||
|
|
||||||
|
|
||||||
|
def update_version_number():
|
||||||
|
new_version_number: str
|
||||||
|
with open("./compose_viz/__init__.py", "r+") as init_file:
|
||||||
|
init_content: str = init_file.read()
|
||||||
|
|
||||||
|
version_number = init_content.split(" ")[-1].replace('"', "").strip()
|
||||||
|
major, minor, patch = version_number.split(".")
|
||||||
|
new_version_number = f"{major}.{minor}.{int(patch) + 1}"
|
||||||
|
|
||||||
|
init_file.seek(0)
|
||||||
|
init_file.write(
|
||||||
|
f"""__app_name__ = "compose_viz"
|
||||||
|
__version__ = "{new_version_number}"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
with open("./pyproject.toml", "r+") as pyproject_file:
|
||||||
|
pyproject_content: str = pyproject_file.read()
|
||||||
|
|
||||||
|
pyproject_content = pyproject_content.replace(version_number, new_version_number)
|
||||||
|
|
||||||
|
pyproject_file.seek(0)
|
||||||
|
pyproject_file.write(pyproject_content)
|
||||||
|
|
||||||
|
print(f"Version number updated to {new_version_number} successfully!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
revise_naming_convention()
|
||||||
|
update_version_number()
|
Loading…
Reference in a new issue