File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 1515    steps :
1616    - uses : actions/checkout@v4 
1717      with :
18-         ref : ${{ github.head_ref }} 
1918        token : ${{ secrets.GITHUB_TOKEN }} 
20-          
19+ 
2120    - name : Setup Node.js 
2221      uses : actions/setup-node@v4 
2322      with :
3231
3332    - name : Format code 
3433      run : npm run format 
35-       
34+ 
35+     #  For pushes to main or PRs from same repo, commit formatting changes
3636    - name : Commit changes 
37+       if : github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository 
3738      uses : stefanzweifel/git-auto-commit-action@v5 
3839      with :
3940        commit_message : " style: format code with prettier" 
40-         branch : ${{ github.head_ref }} 
41+         branch : ${{ github.event_name == 'push' && 'main' || github.head_ref }} 
42+ 
43+     #  For PRs from forks, fail the check if there are formatting changes required
44+     - name : Check for uncommitted changes 
45+       if : github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository 
46+       run : | 
47+         if [[ -n "$(git status --porcelain)" ]]; then 
48+           echo "::error::Code formatting issues found. Please run 'npm run format' locally and commit the changes." 
49+           git diff 
50+           exit 1 
51+         fi 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments