From c66c5605650b3d8d6683b3a37513dbec3bae23a5 Mon Sep 17 00:00:00 2001 From: Georg Teufelberger Date: Fri, 14 Jun 2024 15:31:55 +0200 Subject: [PATCH] ci: Use Python script to move compiled LaTeX files Moves all created PDFs to `release` folder instead of manually specifying each one in the YAML config file --- .github/workflows/compile-latex.yml | 4 +--- .github/workflows/tagpr.yml | 4 +--- scripts/move-files.py | 32 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 scripts/move-files.py diff --git a/.github/workflows/compile-latex.yml b/.github/workflows/compile-latex.yml index 5c5d37d..22e2e10 100644 --- a/.github/workflows/compile-latex.yml +++ b/.github/workflows/compile-latex.yml @@ -19,9 +19,7 @@ jobs: - name: Rename files and move to single release folder run: | mkdir --parents release - mv src/dacs-sw/control-station-installation/main.pdf release/dacs-sw-control-station-installation.pdf - mv src/dacs-sw/template/main.pdf release/dacs-sw-template.pdf - mv src/dacs-sw/database-ingestion/main.pdf release/dacs-sw-database-ingestion.pdf + python3 scripts/move-files.py - name: Upload PDF files uses: actions/upload-artifact@v4 diff --git a/.github/workflows/tagpr.yml b/.github/workflows/tagpr.yml index d708d28..e24ddfe 100644 --- a/.github/workflows/tagpr.yml +++ b/.github/workflows/tagpr.yml @@ -33,9 +33,7 @@ jobs: if: ${{ steps.tagpr.outputs.tag != '' }} run: | mkdir --parents release - mv src/dacs-sw/control-station-installation/main.pdf release/dacs-sw-control-station-installation.pdf - mv src/dacs-sw/template/main.pdf release/dacs-sw-template.pdf - mv src/dacs-sw/database-ingestion/main.pdf release/dacs-sw-database-ingestion.pdf + python3 scripts/move-files.py - name: Make release with PDFs if: ${{ steps.tagpr.outputs.tag != '' }} diff --git a/scripts/move-files.py b/scripts/move-files.py new file mode 100644 index 0000000..f85aa74 --- /dev/null +++ b/scripts/move-files.py @@ -0,0 +1,32 @@ +import os +import shutil + + +# Define folders +base_folder = "src" +release_folder = "release" + +# Ensure the release folder exists +if not os.path.exists(release_folder): + os.makedirs(release_folder) + +# Go through all subdirectories +for root, dirs, files in os.walk(base_folder): + for file in files: + if file != "main.pdf": + # Skip file if it's not `main.pdf` + continue + + # Construct the original file path + old_path = os.path.join(root, file) + + # Create the new file name with '-' instead of '/' + relative_path = os.path.relpath(old_path, base_folder) + new_filename = relative_path.replace(os.sep, "-") + + # Construct the new file path + new_path = os.path.join(release_folder, new_filename) + + # Move and rename the file + shutil.move(old_path, new_path) + print(f"Moved {old_path} to {new_path}")