Auto Format - 546/merge #4201
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
| name: Auto Format | |
| run-name: Auto Format - ${{ github.ref_name }} | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| conditional: | |
| name: Conditional Formatting Check | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| run_format: ${{ steps.conditional_check.outputs.run_format }} | |
| steps: | |
| - name: Checkout Pull Request | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 1 | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| - name: Conditional Check | |
| id: conditional_check | |
| run: | | |
| if [ "${{ github.event.pull_request.draft }}" != "true" ]; then | |
| echo "run_format=true" >> "$GITHUB_OUTPUT" | |
| elif git log -1 --pretty=%B | grep -iq "format"; then | |
| echo "run_format=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "run_format=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| clang: | |
| needs: conditional | |
| if: ${{ needs.conditional.outputs.run_format == 'true' }} | |
| name: Clang | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Acquire Secrets | |
| uses: Gaucho-Racing/vault-pull-secrets@fa8269ea0faa78bd55f8628fd13680dae68908a2 # v1.3.0 | |
| with: | |
| secrets: firmware-monorepo-autoformat.github_pat | |
| - name: Checkout Pull Request | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 1 | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| token: ${{ env.GITHUB_PAT }} | |
| - name: Format C Files | |
| run: | | |
| set -o pipefail | |
| echo "<details open><summary>Clang-Format Output</summary>" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| git ls-files '*.c' '*.h' | parallel clang-format -i --verbose 2>&1 | tee -a $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "</details>" >> $GITHUB_STEP_SUMMARY | |
| - name: Save Changes | |
| uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11.1.1 | |
| if: github.ref_type != 'tag' | |
| env: | |
| HOME: ${{ github.workspace }} | |
| with: | |
| default_author: github_actions | |
| message: "Automatic Clang-Format: Standardized formatting automatically" | |
| fetch: "false" | |
| cmake: | |
| needs: conditional | |
| if: ${{ needs.conditional.outputs.run_format == 'true' }} | |
| name: CMake | |
| runs-on: ubuntu-slim | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Acquire Secrets | |
| uses: Gaucho-Racing/vault-pull-secrets@fa8269ea0faa78bd55f8628fd13680dae68908a2 # v1.3.0 | |
| with: | |
| secrets: firmware-monorepo-autoformat.github_pat | |
| - name: Checkout Pull Request | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| fetch-depth: 1 | |
| token: ${{ env.GITHUB_PAT }} | |
| - name: Setup uv | |
| uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v8.3.0 | |
| with: | |
| enable-cache: "false" | |
| - name: Format CMake Files | |
| run: uv run --with gersemi gersemi --in-place --warnings-as-errors ${{ github.workspace }} | |
| - name: Save Changes | |
| uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11.1.1 | |
| if: github.ref_type != 'tag' | |
| env: | |
| HOME: ${{ github.workspace }} | |
| with: | |
| default_author: github_actions | |
| message: "Automatic CMake Format: Standardized formatting automatically" | |
| fetch: "false" | |
| json: | |
| needs: conditional | |
| if: ${{ needs.conditional.outputs.run_format == 'true' }} | |
| name: Json | |
| runs-on: ubuntu-slim | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Acquire Secrets | |
| uses: Gaucho-Racing/vault-pull-secrets@fa8269ea0faa78bd55f8628fd13680dae68908a2 # v1.3.0 | |
| with: | |
| secrets: firmware-monorepo-autoformat.github_pat | |
| - name: Checkout Pull Request | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| fetch-depth: 1 | |
| token: ${{ env.GITHUB_PAT }} | |
| - name: Format JSON Files | |
| run: | | |
| set -o pipefail | |
| git ls-files '*.json' | xargs -r -I{} sh -c 'jq --tab . {} > {}.tmp && mv {}.tmp {}' | |
| - name: Save Changes | |
| uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11.1.1 | |
| if: github.ref_type != 'tag' | |
| env: | |
| HOME: ${{ github.workspace }} | |
| with: | |
| default_author: github_actions | |
| message: "Automatic Json Format: Standardized formatting automatically" | |
| fetch: "false" | |
| perl: | |
| needs: conditional | |
| if: ${{ needs.conditional.outputs.run_format == 'true' }} | |
| name: Perl | |
| runs-on: ubuntu-slim | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Acquire Secrets | |
| uses: Gaucho-Racing/vault-pull-secrets@fa8269ea0faa78bd55f8628fd13680dae68908a2 # v1.3.0 | |
| with: | |
| secrets: firmware-monorepo-autoformat.github_pat | |
| - name: Checkout Pull Request | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| fetch-depth: 1 | |
| token: ${{ env.GITHUB_PAT }} | |
| - name: Setup Perl | |
| uses: shogo82148/actions-setup-perl@53e33bb27be492a926eee378e8a5f7ff6618b061 # v1.43.1 | |
| with: | |
| install-modules: "Perl::Tidy" | |
| - name: Format Perl Files | |
| run: | | |
| set -o pipefail | |
| git ls-files '*.pl' '*.pm' | xargs perltidy -b -bext='/' | |
| - name: Save Changes | |
| uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11.1.1 | |
| if: github.ref_type != 'tag' | |
| env: | |
| HOME: ${{ github.workspace }} | |
| with: | |
| default_author: github_actions | |
| message: "Automatic Perl Tidy: Standardized formatting automatically" | |
| fetch: "false" | |
| asm: | |
| needs: conditional | |
| if: ${{ needs.conditional.outputs.run_format == 'true' }} | |
| name: Assembly | |
| runs-on: ubuntu-slim | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Acquire Secrets | |
| uses: Gaucho-Racing/vault-pull-secrets@fa8269ea0faa78bd55f8628fd13680dae68908a2 # v1.3.0 | |
| with: | |
| secrets: firmware-monorepo-autoformat.github_pat | |
| - name: Checkout Pull Request | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| fetch-depth: 1 | |
| token: ${{ env.GITHUB_PAT }} | |
| - name: Setup Go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | |
| with: | |
| go-version: "stable" | |
| cache: false | |
| - name: Install asmfmt | |
| run: | | |
| set -o pipefail | |
| go install github.com/klauspost/asmfmt/cmd/asmfmt@latest | |
| - name: Format Assembly Files | |
| run: | | |
| set -o pipefail | |
| git ls-files '*.s' '*.asm' | xargs -r asmfmt -w -e | |
| - name: Save Changes | |
| uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11.1.1 | |
| if: github.ref_type != 'tag' | |
| env: | |
| HOME: ${{ github.workspace }} | |
| with: | |
| default_author: github_actions | |
| message: "Automatic Assembly Format: Standardized formatting automatically" | |
| fetch: "false" | |
| all: | |
| if: ${{ !github.event.pull_request.draft && always() }} | |
| name: Completed All Auto Formatters | |
| needs: [clang, cmake, json, perl, asm] | |
| runs-on: ubuntu-slim | |
| permissions: {} | |
| steps: | |
| - name: Fail Auto Format | |
| if: > | |
| ${{ | |
| needs.clang.result != 'success' || | |
| needs.cmake.result != 'success' || | |
| needs.json.result != 'success' || | |
| needs.perl.result != 'success' || | |
| needs.asm.result != 'success' | |
| }} | |
| run: | | |
| echo "One or more auto format jobs have failed." | |
| echo "Please check the individual job logs for details." | |
| exit 1 | |
| - name: Complete Auto Format | |
| run: | | |
| echo "Auto Format has been completed for Clang, CMake, JSON, Perl, and Assembly files." | |
| echo "Please refer to the individual job logs for detailed formatting information." |