DevJourney · code I wrote while learning
format-check.yml
2.3 KBname: Format Check
# Verifies the whole tree against the repository's declared styles:
# .prettierrc.json, .clang-format, pyproject.toml (black), gofmt and
# google-java-format. The entire tree is checked because it is fully
# formatted, so any drift - new or pre-existing - fails here.
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
permissions:
contents: read
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Java for google-java-format
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "21"
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
- name: Set up pnpm
uses: pnpm/action-setup@v6 # reads packageManager from the root package.json
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: "stable"
cache: false
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.x"
- name: Install formatters
run: |
# prettier comes from the repository's pinned devDependency so the
# check matches developer machines exactly.
pnpm install --frozen-lockfile
python -m pip install --quiet black clang-format==23.1.5
# google-java-format is not packaged for apt; use the all-deps jar
# pinned to the same version developers run locally.
version=$(cat .google-java-format-version)
sudo curl --fail --show-error --location -o /opt/google-java-format.jar \
"https://repo.maven.apache.org/maven2/com/google/googlejavaformat/google-java-format/$version/google-java-format-$version-all-deps.jar"
sudo tee /usr/local/bin/google-java-format >/dev/null <<'WRAPPER'
#!/bin/sh
exec java -jar /opt/google-java-format.jar "$@"
WRAPPER
sudo chmod +x /usr/local/bin/google-java-format
google-java-format --version
black --version
clang-format --version
./node_modules/.bin/prettier --version
- name: Check Java formatting
run: ./format --java --all --check
- name: Check repository formatting
run: ./format --all --check