From ac417241c2d9d1d3fbe3acf64a19c6efc311d3d2 Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Mon, 14 Oct 2024 00:21:09 +0800 Subject: [PATCH] Use poetry in workflow --- .github/workflows/pdf-monitor.yml | 33 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pdf-monitor.yml b/.github/workflows/pdf-monitor.yml index ebee37a..728933c 100644 --- a/.github/workflows/pdf-monitor.yml +++ b/.github/workflows/pdf-monitor.yml @@ -11,15 +11,30 @@ 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: | @@ -27,7 +42,7 @@ jobs: # 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') @@ -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: | @@ -53,4 +70,4 @@ jobs: else git commit -m "Automated commit of changes made by PDF Monitor Workflow" git push - fi \ No newline at end of file + fi