Skip to content

Commit

Permalink
added the github bot making modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
uchendui committed Nov 28, 2023
1 parent ed8a44e commit 89ada89
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/bib_file_formatter.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Formatting .bib files
on:
push:
pull_request:

jobs:
lint-bib-files:
Expand All @@ -12,28 +11,63 @@ jobs:
with:
fetch-depth: 0

- name: Installing GitHub CLI
- name: Setting up environment
run: |
echo "Updating and installing necessary packages..."
sudo apt -y update && sudo apt -y upgrade
sudo apt -y install software-properties-common
sudo apt install -y gh jq nodejs npm
echo "Installation complete."
- name: Installing bibtex-tidy
run: |
echo "Installing bibtex-tidy..."
sudo npm install -g bibtex-tidy
echo "bibtex-tidy installed successfully."
- name: Linting .bib files job has been triggered
run: |
echo "The job was automatically triggered by a ${{ github.event_name }} event."
- name: Running bibtex-tidy on modified .bib files
run: |
echo "Finding modified .bib files in the last commit..."
files=$(git diff --name-only HEAD^ HEAD | grep '\.bib$')
if [ -z "$files" ]; then
echo "No .bib files modified in this commit."
exit 0
fi
for file in $files; do
echo "Running bibtex-tidy on $file..."
bibtex-tidy --omit=abstract,file,shorttitle,annote,keywords,issn,doi --curly --numeric --months --tab --align=13 --blank-lines --sort=key --duplicates=key --merge=combine --sort-fields --strip-comments --trailing-commas --remove-empty-fields $file
ret=$?
if [ $ret -ne 0 ]; then
echo "Linting failed on $file. Please correct any errors and run the job again."
exit 1
else
echo "$file linted successfully."
fi
done
echo "All modified .bib files have been linted successfully."
- name: Committing and pushing changes
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# incase there are changes while running the job
git stash
# Fetch the latest state of whichever branch the workflow is running on and try to merge
git fetch origin ${{ github.ref }}
git merge origin/${{ github.ref }}
# We have to apply our stashed changes
git stash apply
git add -u
git diff-index --quiet HEAD || git commit -m "Format .bib files"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 89ada89

Please sign in to comment.