From 41f26af8c08881d07878c80b38f5886d4d3fb29e Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Mon, 26 Feb 2024 14:56:45 -0300 Subject: [PATCH] CI: automatically update the repo every 5 days --- .github/workflows/deploy.yaml | 41 +++++++++++++++++++++++++++++++++++ scripts/run_param_parse.py | 8 ++++--- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..a5a5805 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,41 @@ +name: Run Python Script and Commit Changes + +on: + push: + branches: + - main + schedule: + - cron: '0 0 */5 * *' # Runs every 5 days at midnight + workflow_dispatch: # Allows manual triggering + +jobs: + run-and-commit: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 # fetch all history for all tags and branches + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' # Set the Python version you need + + - name: Install dependencies + run: | + python -m pip install --upgrade pip GitPython packaging lxml emit + # Add any other dependencies here + + - name: Run Python script + run: python scripts/run_param_parse.py + + - name: Commit and push if changed + run: | + git config --global user.email "CI@example.com" + git config --global user.name "CI" + git status + git add . + git diff --staged --quiet || git commit -m "Update metadata" + git push + diff --git a/scripts/run_param_parse.py b/scripts/run_param_parse.py index 9900ddc..ec52a01 100755 --- a/scripts/run_param_parse.py +++ b/scripts/run_param_parse.py @@ -122,16 +122,18 @@ def run(self): except Exception as exception: print(exception) - output = f'/tmp/output' + output = Path(__file__).parent.parent subprocess.run(['mkdir', '-p', output]) dest = f"{output}/{folder_name}" subprocess.run(['mkdir', '-p', dest]) for data in glob.glob(f'{dest}/*'): os.remove(data) for data in glob.glob(f'{self.repository_path}/Parameter*'): - shutil.move(data, dest) + shutil.copy2(data, dest) + os.remove(data) for data in glob.glob(f'{self.repository_path}/apm.pdef.*'): - shutil.move(data, dest) + shutil.copy2(data, dest) + os.remove(data)