mirror of
				https://github.com/XRPLF/rippled.git
				synced 2025-11-04 11:15:56 +00:00 
			
		
		
		
	The change updates how clang-format is called in CI and locally, and adds prettier to the pre-commit hook. Proto files are now also formatted, while external files are excluded.
		
			
				
	
	
		
			76 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
# This workflow checks if the code is properly formatted.
 | 
						|
name: Check format
 | 
						|
 | 
						|
# This workflow can only be triggered by other workflows.
 | 
						|
on: workflow_call
 | 
						|
 | 
						|
concurrency:
 | 
						|
  group: ${{ github.workflow }}-${{ github.ref }}-format
 | 
						|
  cancel-in-progress: true
 | 
						|
 | 
						|
defaults:
 | 
						|
  run:
 | 
						|
    shell: bash
 | 
						|
 | 
						|
jobs:
 | 
						|
  pre-commit:
 | 
						|
    runs-on: ubuntu-latest
 | 
						|
    container: ghcr.io/xrplf/ci/tools-rippled-pre-commit
 | 
						|
    steps:
 | 
						|
      # The $GITHUB_WORKSPACE and ${{ github.workspace }} might not point to the
 | 
						|
      # same directory for jobs running in containers. The actions/checkout step
 | 
						|
      # is *supposed* to checkout into $GITHUB_WORKSPACE and then add it to
 | 
						|
      # safe.directory (see instructions at https://github.com/actions/checkout)
 | 
						|
      # but that is apparently not happening for some container images. We
 | 
						|
      # therefore preemptively add both directories to safe.directory. See also
 | 
						|
      # https://github.com/actions/runner/issues/2058 for more details.
 | 
						|
      - name: Configure git safe.directory
 | 
						|
        run: |
 | 
						|
          git config --global --add safe.directory $GITHUB_WORKSPACE
 | 
						|
          git config --global --add safe.directory ${{ github.workspace }}
 | 
						|
      - name: Checkout repository
 | 
						|
        uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
 | 
						|
      - name: Check configuration
 | 
						|
        run: |
 | 
						|
          echo 'Checking path.'
 | 
						|
          echo ${PATH} | tr ':' '\n'
 | 
						|
 | 
						|
          echo 'Checking environment variables.'
 | 
						|
          env | sort
 | 
						|
 | 
						|
          echo 'Checking pre-commit version.'
 | 
						|
          pre-commit --version
 | 
						|
 | 
						|
          echo 'Checking clang-format version.'
 | 
						|
          clang-format --version
 | 
						|
 | 
						|
          echo 'Checking NPM version.'
 | 
						|
          npm --version
 | 
						|
 | 
						|
          echo 'Checking Node.js version.'
 | 
						|
          node --version
 | 
						|
 | 
						|
          echo 'Checking prettier version.'
 | 
						|
          prettier --version
 | 
						|
      - name: Format code
 | 
						|
        run: pre-commit run --show-diff-on-failure --color=always --all-files
 | 
						|
      - name: Check for differences
 | 
						|
        env:
 | 
						|
          MESSAGE: |
 | 
						|
            One or more files did not conform to the formatting. Maybe you did
 | 
						|
            not run 'pre-commit' before committing, or your version of
 | 
						|
            'clang-format' or 'prettier' has an incompatibility with the ones
 | 
						|
            used here (see the "Check configuration" step above).
 | 
						|
 | 
						|
            Run 'pre-commit run --all-files' in your repo, and then commit and
 | 
						|
            push the changes.
 | 
						|
        run: |
 | 
						|
          DIFF=$(git status --porcelain)
 | 
						|
          if [ -n "${DIFF}" ]; then
 | 
						|
            # Print the files that changed to give the contributor a hint about
 | 
						|
            # what to expect when running pre-commit on their own machine.
 | 
						|
            git status
 | 
						|
            echo "${MESSAGE}"
 | 
						|
            exit 1
 | 
						|
          fi
 |