Skip to content

Commit 2d94192

Browse files
authored
DX: set PRETTIER_LEGACY_CLI when Prettier v4 alpha (#41)
* FIX: checkout branch
1 parent a06ab1f commit 2d94192

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

.github/workflows/pre-commit.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,31 @@ jobs:
6969
- if: needs.determine-hooks.outputs.skipped-hooks != 'ALL'
7070
name: Run pre-commit hooks that don't work on pre-commit.ci
7171
run: |-
72-
for hook in ${{ needs.determine-hooks.outputs.skipped-hooks }}; do
72+
export skipped_hooks='${{ needs.determine-hooks.outputs.skipped-hooks }}'
73+
if [[ $skipped_hooks == *"prettier"* ]]; then
74+
export PRETTIER_LEGACY_CLI=1
75+
fi
76+
for hook in $skipped_hooks; do
7377
pre-commit run $hook --all-files --color always
7478
done
7579
- id: diff
7680
if: always()
7781
name: Determine changed files
7882
run: |
83+
some_file_in_root=$(git ls-files --directory | grep -E '^[^/]+$' | head -n1)
84+
diff_files="$some_file_in_root $(git diff --name-only)"
7985
delimiter="$(openssl rand -hex 8)"
8086
echo "diff<<${delimiter}" >> $GITHUB_OUTPUT
81-
git diff --name-only | tee -a $GITHUB_OUTPUT
87+
for file in $diff_files; do
88+
echo "$file" | tee -a $GITHUB_OUTPUT
89+
done
8290
echo "${delimiter}" >> $GITHUB_OUTPUT
83-
echo
84-
git diff --color
91+
# https://github.com/actions/upload-artifact/issues/174#issuecomment-934330651
8592
shell: bash
8693
- if: always() && steps.diff.outputs.diff != ''
8794
uses: actions/upload-artifact@v3
8895
with:
96+
if-no-files-found: error
8997
name: pre-commit-changes
9098
path: ${{ steps.diff.outputs.diff }}
9199

@@ -109,14 +117,20 @@ jobs:
109117
if: always()
110118
name: Determine changed files
111119
run: |
120+
some_file_in_root=$(git ls-files --directory | grep -E '^[^/]+$' | head -n1)
121+
diff_files="$some_file_in_root $(git diff --name-only)"
112122
delimiter="$(openssl rand -hex 8)"
113123
echo "diff<<${delimiter}" >> $GITHUB_OUTPUT
114-
git diff --name-only | tee -a $GITHUB_OUTPUT
124+
for file in $diff_files; do
125+
echo "$file" | tee -a $GITHUB_OUTPUT
126+
done
115127
echo "${delimiter}" >> $GITHUB_OUTPUT
128+
# https://github.com/actions/upload-artifact/issues/174#issuecomment-934330651
116129
shell: bash
117130
- if: always() && steps.diff.outputs.diff != ''
118131
uses: actions/upload-artifact@v3
119132
with:
133+
if-no-files-found: error
120134
name: pre-commit-changes
121135
path: ${{ steps.diff.outputs.diff }}
122136

@@ -147,6 +161,7 @@ jobs:
147161
git remote set-url origin https://x-access-token:${{ secrets.token }}@github.com/${{ github.repository }}
148162
git config user.name "GitHub"
149163
git config user.email "[email protected]"
164+
git checkout -b ${{ github.head_ref }}
150165
git add -A
151166
git commit -m "MAINT: implement updates from pre-commit hooks"
152167
git config pull.rebase true

0 commit comments

Comments
 (0)