Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Format

# Runs ktfmt over the codebase on a daily schedule and opens a PR only if the
# formatter produced changes. Mirrors the coverage-badge cron: it force-pushes a
# dedicated, bot-owned branch so re-runs reuse one PR instead of accumulating
# stale branches, and it never touches master directly.
# Runs ktfmt and rustfmt over the codebase on a daily schedule and opens a PR
# only if a formatter produced changes. Mirrors the coverage-badge cron: it
# force-pushes a dedicated, bot-owned branch so re-runs reuse one PR instead of
# accumulating stale branches, and it never touches master directly.
on:
schedule:
# 12:00 UTC daily (one hour before the coverage-badge cron).
Expand Down Expand Up @@ -42,6 +42,8 @@ jobs:
# --lockfile_mode=off so MODULE.bazel.lock is never rewritten, keeping the
# generated PR limited to formatting-only changes.
run: ~/go/bin/bazelisk run //cli/format --enable_bzlmod=true --enable_workspace=false --lockfile_mode=off
- name: Run rustfmt
run: ~/go/bin/bazelisk run //cli/format:rustfmt --enable_bzlmod=true --enable_workspace=false --lockfile_mode=off
- name: Open PR if formatting changed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -50,12 +52,12 @@ jobs:
echo "No formatting changes; nothing to do."
exit 0
fi
BRANCH="ci/ktfmt-format"
BRANCH="ci/format"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$BRANCH"
git add -A
git commit -m "ci: apply ktfmt formatting"
git commit -m "ci: apply ktfmt and rustfmt formatting"
# Force-push the dedicated, bot-owned branch so re-runs reuse one PR
# instead of accumulating stale branches. This never touches master.
git push --force origin "$BRANCH"
Expand All @@ -65,6 +67,6 @@ jobs:
gh pr create \
--base master \
--head "$BRANCH" \
--title "ci: apply ktfmt formatting" \
--body "Automated ktfmt run via \`bazel run //cli/format\`. This PR contains formatting-only changes."
--title "ci: apply ktfmt and rustfmt formatting" \
--body "Automated ktfmt and rustfmt run via \`bazel run //cli/format\` and \`bazel run //cli/format:rustfmt\`. This PR contains formatting-only changes."
fi
7 changes: 4 additions & 3 deletions cli/format/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ format_multirun(

# The fixer for the rustfmt gate. //:rust_format_check only reports (it fails
# the build, it does not rewrite files), so `bazel run //cli/format:rustfmt` is
# how you satisfy it. Kept separate from `format` for the same reason
# `buildifier` is: one language per target, so a cron on one never rewrites
# another's files.
# how you satisfy it. Kept as its own target so Makefile / CI can run one
# language without the other; the daily format cron runs it after `format`.
# buildifier stays on a separate cron so Starlark rewrites never land in the
# ktfmt/rustfmt PR.
#
# `upstream_wrapper:rustfmt` is plain rustfmt from the registered toolchain --
# not //tools/rustfmt, which is a Bazel-target-driven wrapper that does not take
Expand Down
Loading