diff --git a/.github/workflows/retraction-check.yml b/.github/workflows/retraction-check.yml new file mode 100644 index 0000000..d734932 --- /dev/null +++ b/.github/workflows/retraction-check.yml @@ -0,0 +1,42 @@ +name: Retraction Check + +on: + workflow_dispatch: # Allows manual trigger + schedule: + - cron: '0 8 * * 1' # Runs every Monday at 08:00 UTC + push: + paths: + - sample.bib + +jobs: + retraction_check: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install retraction_check + + - name: Run retraction check + id: retraction + run: | + python -m retraction_check.check_bib sample.bib > findings.txt + grep -v "No retracted papers found." findings.txt > findings_only.txt || true + + - name: Create issue if retractions found + if: success() && hashFiles('findings_only.txt') != '' + uses: peter-evans/create-issue-from-file@v5 + with: + title: "Retraction Watch: Retracted Papers Detected in Bibliography" + content-filepath: findings_only.txt + labels: retraction, automated-check diff --git a/README.md b/README.md index e1d710e..f8ad9b0 100644 --- a/README.md +++ b/README.md @@ -84,3 +84,91 @@ pipenv run check-all - Python 3.8+ - bibtexparser - requests + +## Example: Automated Retraction Check with GitHub Actions + +You can automate retraction checks for your bibliography file using GitHub Actions. The following workflow runs the check on demand, on a schedule, or on every commit to a specific branch. If any retractions are found, it will open a GitHub issue listing the findings. + +```yaml +name: Retraction Check + +on: + workflow_dispatch: # Allows manual trigger + schedule: + - cron: '0 8 * * 1' # Runs every Monday at 08:00 UTC + push: + paths: + - yourfile.bib # Change this to your personal bib file to make sure the workflow runs every time the bibfile changes + +jobs: + retraction_check: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + + - name: Run retraction check + id: retraction + run: | + python -m retraction_check.check_bib path/to/your/bibfileyourfile.bib > findings.txt + grep -v "No retracted papers found." findings.txt > findings_only.txt || true + + - name: Create issue if retractions found + if: success() && hashFiles('findings_only.txt') != '' + uses: peter-evans/create-issue-from-file@v5 + with: + title: "Retraction Watch: Retracted Papers Detected in Bibliography" + content-filepath: findings_only.txt + labels: retraction, automated-check +``` + +- Replace `yourfile.bib` with the path to your bibliography file. +- The workflow will create an issue only if retractions are found. +- You can trigger the workflow manually, on a schedule, or on every commit to the specified branch. + +## Example: Automated Retraction Check with GitLab CI + +You can also automate retraction checks for your bibliography file using GitLab CI/CD. The following example runs the check on every push to the default branch and creates an issue if retractions are found (requires a GitLab personal access token with API scope stored as `GITLAB_TOKEN`). + +```yaml +retraction_check: + image: python:3.11 + stage: test + script: + - pip install . + - python -m retraction_check.check_bib path/to/yourfile.bib > findings.txt + - grep -v "No retracted papers found." findings.txt > findings_only.txt || true + # Only create an issue if findings_only.txt is not empty + - | + if [ -s findings_only.txt ]; then + curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ + --header "Content-Type: application/json" \ + --data '{ + "title": "Retraction Watch: Retracted Papers Detected in Bibliography", + "description": "$(cat findings_only.txt)", + "labels": "retraction, automated-check" + }' \ + --request POST "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issues" + fi + only: + - main # or your default branch + rules: + - changes: + - path/to/yourfile.bib +``` + +- Replace `path/to/yourfile.bib` with the path to your bibliography file. +- Store a GitLab personal access token with API scope as a CI/CD variable named `GITLAB_TOKEN`. +- The job will create an issue only if retractions are found and the `.bib` file changes.