Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit e3f6315

Browse files
sungchun12Sung Won Chungdlawin
authored
Update ruff formatter to work differently between forks and native branches (#821)
* add unformatted file * test github action * add conditional suggestion * fix condition * try again * try again * try diff output * fork repo conditions * fix format test * helpful error message * put it in the name * shorten sentence * fix formatting * revert changes * consistent behavior to skipping database tests * ruff format * verify none * ruff format * empty string or none condition --------- Co-authored-by: Sung Won Chung <[email protected]> Co-authored-by: Dan Lawin <[email protected]>
1 parent 40b3c87 commit e3f6315

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.github/workflows/formatter.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,25 @@ jobs:
2121
uses: actions/checkout@v3
2222
if: github.event_name == 'workflow_dispatch'
2323

24-
- name: Check files using the ruff formatter
24+
# This is used for forked PRs as write permissions are required to format files
25+
- name: Run and commit changes with `ruff format .` locally on your forked branch to fix errors if they appear
26+
if: ${{ github.event.pull_request.head.repo.fork == true }}
27+
uses: chartboost/ruff-action@v1
28+
id: ruff_formatter_suggestions
29+
with:
30+
args: format --diff
31+
32+
# This only runs if the PR is NOT from a forked repo
33+
- name: Format files using ruff
34+
if: ${{ github.event.pull_request.head.repo.fork == false }}
2535
uses: chartboost/ruff-action@v1
2636
id: ruff_formatter
2737
with:
2838
args: format
2939

40+
# This only runs if the PR is NOT from a forked repo
3041
- name: Auto commit ruff formatting
42+
if: ${{ github.event.pull_request.head.repo.fork == false }}
3143
uses: stefanzweifel/git-auto-commit-action@v5
3244
with:
33-
commit_message: 'style fixes by ruff'
45+
commit_message: 'style fixes by ruff'

tests/test_dbt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def test_integration_basic_dbt(self):
4646
# 1 with a diff
4747
assert diff_string.count(" Rows Added Rows Removed") == 1
4848

49+
@unittest.skipIf(
50+
not os.environ.get("MOTHERDUCK_TOKEN"),
51+
"MOTHERDUCK_TOKEN doesn't exist or is empty if this is run from a forked branch pull request",
52+
)
4953
def test_integration_motherduck_dbt(self):
5054
artifacts_path = os.getcwd() + "/tests/dbt_artifacts"
5155
test_project_path = os.environ.get("DATA_DIFF_DBT_PROJ") or artifacts_path

0 commit comments

Comments
 (0)