-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ruchernchong/1-run-python-script-when-a-pd…
…f-file-is-added-or-updated Add GHA workflow to monitor for PDF changes
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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 | ||
cache: pip | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- 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 | ||
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 |
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