Skip to content

Commit

Permalink
ci: Use Python script to move compiled LaTeX files
Browse files Browse the repository at this point in the history
Moves all created PDFs to `release` folder instead of manually specifying each one in the YAML config file
  • Loading branch information
gteufelberger committed Jun 14, 2024
1 parent b2771f8 commit c66c560
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/compile-latex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tagpr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '' }}
Expand Down
32 changes: 32 additions & 0 deletions scripts/move-files.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit c66c560

Please sign in to comment.