-
Notifications
You must be signed in to change notification settings - Fork 93
chore: add prettier actions #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
coderbyheart
merged 11 commits into
softwarecrafters:main
from
aalemayhu:chore/add-prettier
Jul 20, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f20e40e
chore: add prettier actions
aalemayhu 896c044
Update .github/workflows/format.yaml
coderbyheart 600c6e5
Update .github/workflows/format.yaml
coderbyheart 9cfe190
fix: cleanup
coderbyheart ad20368
fix: use npx (which installs)
coderbyheart 8ad4da4
fix: push to current branch
coderbyheart 6b50ee8
fix: checkout fork if PR
coderbyheart 703cf63
fix: just format main
coderbyheart 3eee9f1
ci: can we write?
coderbyheart 762ba0b
fix: comment if needed
coderbyheart 342499f
fix: only commit to main
coderbyheart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| name: Format Code with Prettier | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| prettier: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| repository: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} | ||
| ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
|
|
||
| - name: Check Prettier formatting | ||
| id: prettier-check | ||
| run: | | ||
| if prettier --check .; then | ||
| echo "needs_formatting=false" >> $GITHUB_OUTPUT | ||
| echo "✅ Code is already formatted" | ||
| exit 0 | ||
| else | ||
| echo "needs_formatting=true" >> $GITHUB_OUTPUT | ||
| echo "❌ Code needs formatting" | ||
| exit 1 | ||
| fi | ||
| continue-on-error: true | ||
|
|
||
| - name: Run Prettier | ||
| if: steps.prettier-check.outputs.needs_formatting == 'true' | ||
| run: npx prettier --write . | ||
|
|
||
| - name: Commit and push formatted code | ||
| if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'push' | ||
coderbyheart marked this conversation as resolved.
Show resolved
Hide resolved
coderbyheart marked this conversation as resolved.
Show resolved
Hide resolved
coderbyheart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| run: | | ||
| # Configure git user | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| # Stage changes | ||
| git add . | ||
|
|
||
| # Only commit if there are changes | ||
| if [ -n "$(git diff --cached)" ]; then | ||
| git commit -m "chore: format code with Prettier [skip ci]" | ||
| git push | ||
| else | ||
| echo "🎉 No formatting changes to commit." | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| target/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "semi": true, | ||
| "trailingComma": "es5", | ||
| "singleQuote": true, | ||
| "printWidth": 100, | ||
| "tabWidth": 2, | ||
| "useTabs": false, | ||
| "bracketSpacing": true, | ||
| "arrowParens": "avoid" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.