Skip to content

Commit

Permalink
Use poetry in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Oct 13, 2024
1 parent 3a9fdce commit ac41724
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions .github/workflows/pdf-monitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,38 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
cache: pip
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- 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')
Expand All @@ -36,12 +51,14 @@ jobs:
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
python main.py "$pdf_file"
poetry run python main.py "$pdf_file"
done
- name: Commit and Push Changes
if: ${{ env.pdf_files != '' }}
run: |
Expand All @@ -53,4 +70,4 @@ jobs:
else
git commit -m "Automated commit of changes made by PDF Monitor Workflow"
git push
fi
fi

0 comments on commit ac41724

Please sign in to comment.