Skip to content

Commit

Permalink
Merge pull request stanfordnlp#565 from stanfordnlp/add-pr-comment-ruff
Browse files Browse the repository at this point in the history
ci(dspy): Fix failing tests coming from forks
  • Loading branch information
okhat authored Mar 7, 2024
2 parents 1d300c8 + 958cd6a commit 91c9ddf
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 160 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/pr_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Comment for PR

on:
workflow_run:
workflows: ["Check for Ruff Fix, Test, and Build"]
types:
- completed

jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: "Download Ruff Fix Outcome Artifact"
uses: actions/download-artifact@v2
with:
name: ruff-fix-outcome
path: artifacts

- name: "Read Ruff Fix Outcome"
id: ruff_outcome
run: |
outcome=$(cat artifacts/ruff_fix_outcome.txt)
echo "RUFF_FIX_OUTCOME=$outcome" >> $GITHUB_ENV
- name: "Comment on PR if Ruff Fix Failed"
if: env.RUFF_FIX_OUTCOME == 'true'
uses: actions/github-script@v5
with:
script: |
const pr_number = ${{ github.event.workflow_run.pull_requests[0].number }};
const message = 'It seems like there are issues with the formatting. Please run `ruff check . --fix-only` and commit to address these issues.';
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_number,
body: message
});
50 changes: 34 additions & 16 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
name: Fix, Test, and Build
name: Lint, Test, and Build

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

env:
POETRY_VERSION: "1.6.1"

jobs:
fix:
name: Apply Ruff Fix
name: Check Ruff Fix
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: chartboost/ruff-action@v1
- name: Ruff Fix Attempt
id: ruff_fix
uses: chartboost/ruff-action@v1
with:
args: --fix-only
- uses: stefanzweifel/git-auto-commit-action@v5
args: --fix-only --exit-non-zero-on-fix
continue-on-error: true

- name: Determine Ruff Fix Outcome
run: |
if [ ${{ steps.ruff_fix.outcome }} == 'failure' ]; then
echo "RUFF_FAILED=true" >> $GITHUB_ENV
echo ${{ steps.ruff_fix.outcome }} > ruff_fix_outcome.txt
else
echo "RUFF_FAILED=false" >> $GITHUB_ENV
echo ${{ steps.ruff_fix.outcome }} > ruff_fix_outcome.txt
fi
- uses: actions/upload-artifact@v2
with:
commit_message: "Automatic Style fixes"
name: ruff-fix-outcome
path: ruff_fix_outcome.txt

- name: Fail Workflow if Ruff Fix Failed
if: steps.ruff_fix.outcome == 'failure'
run: |
echo "Ruff fix failed, failing the workflow."
echo "Please run 'ruff check . --fix-only' locally and push the changes."
exit 1
test:
name: Run Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
Expand Down Expand Up @@ -64,10 +84,9 @@ jobs:
strategy:
matrix:
python-version: ["3.9"]
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
Expand Down Expand Up @@ -97,10 +116,9 @@ jobs:
strategy:
matrix:
python-version: ["3.9"]
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
Expand Down
Loading

0 comments on commit 91c9ddf

Please sign in to comment.