Skip to content

Commit

Permalink
update new script and github actions pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
loris.d committed Mar 18, 2024
1 parent 1320c59 commit 761014f
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Update Latest Tag

on:
push:
branches:
- main

jobs:
tag-latest:
runs-on: ubuntu-latest
container:
image: alpine/git
options: --entrypoint ""

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Necessary for tag manipulation

# - name: Configure Git
# run: |
# git config --global user.name "Your Name"
# git config --global user.email "[email protected]"

- name: Remove existing latest tag locally and remotely
run: |
git tag -d latest || true # Ignore error if tag doesn't exist
git push origin :refs/tags/latest || true # Ignore error if tag doesn't exist
- name: Tag HEAD as latest
run: |
git tag latest HEAD
git push origin latest
timeout-minutes: 10
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
.*.sw[a-z]
.coverage
.tox
dist
dist
.DS_Store
.vscode/*
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
language: python
entry: generated_header_separated
files: '^Dreamcatcher/Source/.*\.h$'
additional_dependencies: []
- id: dcfiles_updated
name: Check if the committed dcfiles are updated to the latest version
entry: python ./.gitlab/scripts/dcfiles-updated.py
language: python
files: '.*\.dc$'
additional_dependencies: []
54 changes: 54 additions & 0 deletions pre_commit_hooks/dcfiles-updated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2014-2024 Zuru Tech HK Limited, All rights reserved.

"""pre-commit hook that verifies if the .dc files passed are updated to the latest version"""
import io
import json
import re
import sys


def verify_file(file_name, version):
"""Verifies if the .dc file schema is at the passed version"""
with io.open(file_name, "r", encoding="utf-8") as fp:
dcfile = json.load(fp)

if not dcfile["schema"].endswith(f"v{version}/schema.json"):
return False

return True


def main():
"""Entrypoint"""

version = ""
with io.open(
"Dreamcatcher/Plugins/BIMCore/Source/DCInterfaces/Public/Source/ExportData/ExpStructs.h",
"r",
encoding="utf-8",
) as fp:
for line in fp:
if "DCFILE_VERSION" in line:
result = re.search(r"DCFILE_VERSION = \"v(\d+)\.(\d+)\.(\d+)\"", line)
if not result:
print("Unable to extract DCFILE_VERSION value", file=sys.stderr)
return 1
version = f"{result.group(1)}.{result.group(2)}.{result.group(3)}"
break
if not version:
print("Unable to find DCFILE_VERSION", file=sys.stderr)
return 1

for dcfile in sys.argv[1:]:
if not dcfile.startswith("-"):
if not verify_file(dcfile, version):
print(
f"{dcfile} not updated to the latest schema version: {version}",
file=sys.stderr,
)
return 1
return 0


if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ console_scripts =
copyright_updater = pre_commit_hooks.copyright_updater:main
generated_header_separated = pre_commit_hooks.generated_header_separated:main
check_locks = soft_lock.pre_commit:main
dcfiles_updated = pre_commit_hooks.dcfiles_updated:main

[bdist_wheel]
universal = True
Expand Down

0 comments on commit 761014f

Please sign in to comment.