Skip to content

Commit

Permalink
introduce proper postupgrade script for renovate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemnmez committed Sep 29, 2024
1 parent c7b73f6 commit 45777de
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ py_venv(
"//bzl/versioning",
"//ini/git/merge_drivers/bazel_lockfile",
"//project/cultist/gen/testing",
"//py/ci/postUpgrade:postUpgrade_bin",
"//py/hello_world:hello_world_bin",
"//py/ibazel:ibazel_bin",
"//py/ipynb:ipynb_bin",
Expand Down
5 changes: 5 additions & 0 deletions ci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ ts_project(
],
)

alias(
name = "postupgrade",
actual = "@@//py/ci/postUpgrade:postUpgrade_bin",
)

jest_test(
name = "tests",
srcs = ["bazel_test.js"],
Expand Down
14 changes: 14 additions & 0 deletions py/ci/postUpgrade/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("//bzl:rules.bzl", "bazel_lint")
load("//py:rules.bzl", "py_binary")

py_binary(
name = "postUpgrade_bin",
srcs = ["__main__.py"],
main = "__main__.py",
visibility = ["//:__subpackages__"],
)

bazel_lint(
name = "bazel_lint",
srcs = ["BUILD.bazel"],
)
65 changes: 65 additions & 0 deletions py/ci/postUpgrade/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"Runs after Renovate updates some dep"
from subprocess import run as _run
from os import getenv

if __name__ != "__main__":
raise Exception("don’t import this!")

wd = getenv("BUILD_WORKSPACE_DIRECTORY")

if wd is None:
raise Exception("Please run from bazel.")


def run(*args, **kwargs):
return _run(*args, cwd=wd, **kwargs)

def bazel(args: list[str] = [], **kwargs):
return run(
["npx", "--yes", "@bazel/bazelisk"] + args,
check=True, **kwargs,
)

def bazel_run(args: list[str] = [], env: dict[str, str] = {}, **kwargs):
return bazel(
["run"] + args,
**kwargs,
)

def cargo_repin():
return bazel(["sync", "--only=cargo"])

def go_mod_tidy():
return bazel_run(["@@/sh/bin:go", "--", "mod", "tidy"])

def bazel_update_lockfile():
return bazel(["mod", "deps", "--lockfile_mode=update"])

def autofix_tags(tags: list[str]):
return bazel_run(["@@//:fix"] + tags)

def autofix_all():
return autofix_tags(["//..."])

def bazel_update_modfile():
return bazel(["mod", "tidy"])

def modify_non_bazel_lockfiles():
go_mod_tidy()
autofix_all()

def modify_bazel_lockfiles():
bazel_update_modfile()
cargo_repin()
bazel_update_lockfile()
# and one for luck
autofix_all()

modify_non_bazel_lockfiles()
modify_bazel_lockfiles()
run(["rm", "-rf", "dist/"])





13 changes: 2 additions & 11 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
"zemn-me/monorepo"
],
"allowedPostUpgradeCommands": [
"CARGO_BAZEL_REPIN=1 npx --yes @bazel/bazelisk sync --only=cargo",
"npx --yes @bazel/bazelisk run @@//sh/bin:go -- mod tidy",
"npx --yes @bazel/bazelisk run //bzl/fix_api:fix_all //...",
"rm -rf dist",
"npx --yes @bazel/bazelisk mod deps --lockfile_mode=update"
"npx --yes @bazel/bazelisk run //ci:postupgrade"
],
"packageRules": [
{
Expand All @@ -55,12 +51,7 @@
],
"postUpgradeTasks": {
"commands": [
"CARGO_BAZEL_REPIN=1 npx --yes @bazel/bazelisk sync --only=cargo",
"npx --yes @bazel/bazelisk run @@//sh/bin:go -- mod tidy",
"npx --yes @bazel/bazelisk mod deps --lockfile_mode=update",
"npx --yes @bazel/bazelisk run //bzl/fix_api:fix_all //...",
"npx --yes @bazel/bazelisk run //bzl/fix_api:fix_all //...",
"rm -rf dist"
"npx --yes @bazel/bazelisk run //ci:postupgrade"
],
"executionMode": "branch",
"fileFilters": [
Expand Down

0 comments on commit 45777de

Please sign in to comment.