Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Make comment action follow github best practices

Isaac Miller7e1d5019900d
diff --git a/.github/workflows/pr_comment.yml b/.github/workflows/pr_comment.yml
new file mode 100644
index 000000000..87afb5094
--- /dev/null
+++ b/.github/workflows/pr_comment.yml
@@ -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
+ });
diff --git a/.github/workflows/ruff_lint.yml b/.github/workflows/ruff_lint.yml
deleted file mode 100644
index dd396c736..000000000
--- a/.github/workflows/ruff_lint.yml
+++ /dev/null
@@ -1,51 +0,0 @@
-name: Lint
-
-on:
- pull_request_target:
- types: [opened, synchronize, reopened]
-
-env:
- POETRY_VERSION: "1.6.1"
-
-jobs:
- fix:
- name: Apply Ruff Fix
- runs-on: ubuntu-latest
- permissions:
- contents: write
- pull-requests: write
- # Note that 'pull_request_target' has higher permissions than 'pull_request'\
- # Do not change any events that run arbitrary code to use 'pull_request_target'
- if: github.event_name == 'pull_request_target'
- steps:
- - uses: actions/checkout@v4
- - uses: actions/setup-python@v5
- - uses: chartboost/ruff-action@v1
- with:
- args: check . --fix-only --exit-non-zero-on-fix -v
-
- comment_if_ruff_fail:
- name: Comment on Ruff Failure
- runs-on: ubuntu-latest
- permissions:
- contents: read
- pull-requests: write
- needs: fix
- # Note that 'pull_request_target' has higher permissions than 'pull_request'\
- # Do not change any events that run arbitrary code to use 'pull_request_target'
- if: ${{ failure() && needs.fix.result == 'failure' && github.event_name == 'pull_request_target' }}
- steps:
- # - run: echo 'It seems like there are issues with the formatting. Please run `ruff check . --fix-only` and commit to address these issues.'
- - name: Comment on Ruff Failure
- uses: actions/github-script@v6
- with:
- script: |
- const issue_number = context.issue.number;
- const message = 'It seems like there are issues with the formatting. Please run `ruff check . --fix-only` and commit to address these issues.';
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: issue_number,
- body: message
- });
- console.log('Commented on the issue.');
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index 15da587b4..f5c8d5f3f 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -1,4 +1,4 @@
-name: Fix, Test, and Build
+name: Check for Ruff Fix, Test, and Build
on:
pull_request:
@@ -8,6 +8,43 @@ env:
POETRY_VERSION: "1.6.1"
jobs:
+ fix:
+ name: Check Ruff Fix
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ pull-requests: write
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ - name: Ruff Fix Attempt
+ id: ruff_fix
+ uses: chartboost/ruff-action@v1
+ with:
+ 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:
+ name: ruff-fix-outcome
+ path: ruff_fix_outcome.txt
+
+ - name: Fail Workflow if Ruff Fix Failed
+ if: env.RUFF_FAILED == 'true'
+ run: |
+ echo "Ruff fix failed, failing the workflow."
+ exit 1
+
test:
name: Run Tests
runs-on: ubuntu-latest