Rename PDF back to original #16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PDF Monitor Workflow | |
on: | |
push: | |
paths: | |
- '**/*.pdf' | |
jobs: | |
run-python-script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.12 | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
version: 1.5.1 | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
- name: Load cached venv | |
id: cached-poetry-dependencies | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Install dependencies | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction --no-root | |
- name: Find Changed PDF Files | |
id: find_pdfs | |
run: | | |
if [ $(git rev-parse --is-shallow-repository) = true ]; then | |
# For shallow clones, fetch the full history | |
git fetch --unshallow | |
fi | |
if [ $(git rev-list --count HEAD) -eq 1 ]; then | |
# If only one commit exists, list all PDFs | |
pdf_files=$(git ls-files '*.pdf') | |
else | |
# For subsequent commits, list changed PDFs | |
pdf_files=$(git diff --name-only HEAD^ HEAD | grep '.pdf$') | |
fi | |
echo "pdf_files=$pdf_files" >> $GITHUB_ENV | |
- name: Run Python Script | |
if: env.pdf_files != '' | |
run: | | |
for pdf_file in ${{ env.pdf_files }}; do | |
poetry run python main.py "$pdf_file" | |
done | |
- name: Commit and Push Changes | |
if: ${{ env.pdf_files != '' }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
if git diff --cached --quiet; then | |
echo "No changes to commit" | |
else | |
git commit -m "Automated commit of changes made by PDF Monitor Workflow" | |
git push | |
fi |