Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import %workspace%/tools/preset.bazelrc
common --@protobuf//bazel/toolchains:prefer_prebuilt_protoc

# Cause a build failure when files in the source tree don't match their generated counterparts.
common --@diff.bzl//diff:validate_diffs

# Don’t want to push a rules author to update their deps if not needed.
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ concurrency:
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}}
cancel-in-progress: ${{ github.ref_name != 'main' }}

permissions:
contents: write
Comment on lines +17 to +18
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this can't push to main ⚠️ . Is it necessary in addition to pull-requests: write?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, because it needs to create a branch to hold the commits

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really hesitant about including this. There are going to be lots of test cases in this repo that produce patches but we don't necessarily want the build to fail and a patch to be auto applied.

I'm also concerned about the security implications of contents: write and I don't fully understand what capabilities it would give to someone submitting a PR from their fork. Do you know?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be best kept as a documented example of how you can use the diff output groups for automatic patching and not part of ci.

pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -29,8 +34,27 @@ jobs:
USE_BAZEL_VERSION: ${{ matrix.bazel }}
steps:
- uses: actions/checkout@v5
with:
# Important: checkout the PR HEAD ref so we can push commits to it.
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- uses: bazel-contrib/setup-bazel@0.18.0
with:
# just needed for Bazel 8 performance
bazelrc: common --incompatible_enable_proto_toolchain_resolution
- run: bazel test //...
# Simulate what Aspect Workflows could do
# Run the build with patches requested, then apply them and run the tests again
- if: failure()
run: |
./examples/test.sh //examples/...
git config --global user.email "marvin@aspect.build"
git config --global user.name "Marvin [bot]"
git commit -a -m "fix: apply patches"
git push origin "HEAD:${{ github.event.pull_request.head.ref }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Comment thread
alexeagle marked this conversation as resolved.

pre-commit:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ bazel_dep(name = "bazel_lib", version = "3.0.0")
bazel_dep(name = "diffutils", version = "3.12", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1", dev_dependency = True)
bazel_dep(name = "bazelrc-preset.bzl", version = "1.6.0", dev_dependency = True)
bazel_dep(name = "protobuf", version = "33.4", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True)

register_toolchains(
"//tools/toolchains:all",
Expand Down
187 changes: 185 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions diff/private/diff.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ def _diff_rule_impl(ctx):

# If both inputs are generated, there's no writable file to patch.
is_copy_to_source = ctx.file.file1.is_source or ctx.file.file2.is_source
outputs = [ctx.outputs.patch, ctx.outputs.exit_code]
ctx.actions.run_shell(
inputs = [ctx.file.file1, ctx.file.file2] + diffinfo.tool_files,
outputs = outputs,
outputs = [ctx.outputs.patch, ctx.outputs.exit_code],
command = command,
mnemonic = "DiffutilsDiff",
mnemonic = "Diff",
Comment thread
alexeagle marked this conversation as resolved.
Outdated
progress_message = "Diffing %{input} to %{output}",
)

Expand All @@ -82,11 +81,11 @@ def _diff_rule_impl(ctx):
ERROR: diff command exited with non-zero status.

To accept the diff, run:
patch -d \\$(bazel info workspace) -p0 < {patch}
""".format(patch = ctx.outputs.patch.path)))
patch -d \\$(bazel info workspace) -p0 < \\$(bazel info bazel-bin)/{patch}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for my understanding) what case does this fix?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's when your current working directory is not the repository root.
perhaps it should be $(bazel info workspace) still, since there are multiple bin dirs under transitions

""".format(patch = ctx.outputs.patch.short_path)))

return [
DefaultInfo(files = depset(outputs)),
DefaultInfo(files = depset([ctx.file.file1])),
Comment thread
alexeagle marked this conversation as resolved.
OutputGroupInfo(
_validation = depset(validation_outputs),
# By reading the Build Events, a Bazel wrapper can identify this diff output group and apply the patch.
Expand Down
Empty file added examples/.bazelrc
Empty file.
Loading
Loading