Skip to content

Commit

Permalink
feat: Create rules_release (#601)
Browse files Browse the repository at this point in the history
* Create rules_release

* Setup release flow for bunq2ynab
  • Loading branch information
mvgijssel authored Nov 22, 2023
1 parent 65fa40b commit aca6efb
Show file tree
Hide file tree
Showing 46 changed files with 3,615 additions and 1 deletion.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ esphome_nimble/tmp
node_modules

rules/rules_task
rules/rules_release
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
5 changes: 5 additions & 0 deletions .changeset/bunq2ynab_release-five-suits-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bunq2ynab_release": patch
---

Setup release manager for bunq2ynab docker image
15 changes: 15 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "vgijssel/setup" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": [],
"privatePackages": {
"version": true,
"tag": true
}
}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ mutagen.yml.lock

local.bazelrc

node_modules
node_modules

.pdm-python
__pypackages__
keys
nixos.qcow2
40 changes: 40 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load(
"pycross_target_environment",
)
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@rules_release//release:defs.bzl", "release_manager")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -191,3 +192,42 @@ diff_test(
file1 = "pdm-setup_lock.bzl",
file2 = ":pdm-setup_lock",
)

task(
name = "git_askpass",
cmds = [
"echo $($OP read op://vgijssel-prod/github-git-push/credential)",
],
env = {
"OP": cmd.executable("//tools/onepassword:op"),
},
)

task(
name = "push_git_changes",
cmds = [
"export GIT_AUTHOR_NAME=$($OP read op://vgijssel-prod/github-git-push/username)",
"export GIT_AUTHOR_EMAIL=$($OP read op://vgijssel-prod/github-git-push/email)",
"export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME",
"export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL",
"git add .",
"git commit -m 'chore(release_manager): update release files'",
# Disable credential.helper to ensure GIT_ASKPASS is used and not cached
"git -c credential.helper= push --tags origin HEAD:master",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
env = {
"GIT_ASKPASS": cmd.executable(":git_askpass"),
"OP": cmd.executable("//tools/onepassword:op"),
},
)

release_manager(
name = "release_manager",
publish_cmds = [
":push_git_changes",
],
deps = [
"//tools/bunq2ynab:bunq2ynab_release",
],
)
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ use_repo(python, "python_versions")

# ------------------------------------ rules_oci ------------------------------------ #
bazel_dep(name = "rules_oci", version = "1.4.0")

# ------------------------------------ rules_release ------------------------------------ #
bazel_dep(name = "rules_release", version = "0.0.0")

local_path_override(
module_name = "rules_release",
path = "./rules/rules_release",
)
25 changes: 25 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,28 @@ exports_files(["image.tar.gz"])
nix_file = "//:python310_base_image.nix",
repository = "@nixpkgs//:default.nix",
)

# ------------------------------------ GitHub CLI ------------------------------------ #

# From https://github.com/cli/cli/releases/

http_archive(
name = "github_cli_linux_arm64",
build_file = "//tools/github_cli:BUILD.repositories.bazel.tpl",
sha256 = "e29e51efae58693cab394b983771bc0c73b400e429dd1d7339fc62c8b257c74a",
url = "https://github.com/cli/cli/releases/download/v2.39.1/gh_2.39.1_linux_arm64.tar.gz",
)

http_archive(
name = "github_cli_linux_amd64",
build_file = "//tools/github_cli:BUILD.repositories.bazel.tpl",
sha256 = "18a1bc97eb72305ff20e965d3c67aee7e1ac607fabc6251c7374226d8c41422b",
url = "https://github.com/cli/cli/releases/download/v2.39.1/gh_2.39.1_linux_amd64.tar.gz",
)

http_archive(
name = "github_cli_darwin_arm64",
build_file = "//tools/github_cli:BUILD.repositories.bazel.tpl",
sha256 = "f854225778b7215480c442cd2e3eeec1a56d33876bbbad19daf557c1b00d6913",
url = "https://github.com/cli/cli/releases/download/v2.39.1/gh_2.39.1_macOS_arm64.zip",
)
12 changes: 12 additions & 0 deletions buildbuddy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ actions:
bazel_commands:
- bazel run //:setup_ci
- bazel test --keep_going //... @rules_task//... --config buildbuddy --config buildbuddy_rbe

- name: "Release all targets"
user: buildbuddy
container_image: "ubuntu-20.04"
triggers:
push:
branches:
- "master"
bazel_commands:
- bazel run //:setup_ci
- bazel run //:release_manager.version
- bazel run //:release_manager.publish
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "setup",
"version": "0.0.0",
"private": true,
"dependencies": {},
"workspaces": [
"tmp/rules_release/packages/*"
]
}
1 change: 1 addition & 0 deletions rules/rules_release/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions rules/rules_release/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable_bzlmod=true
48 changes: 48 additions & 0 deletions rules/rules_release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library", "js_test")
load("@rules_java//java:defs.bzl", "java_binary")

package(default_visibility = ["//visibility:public"])

npm_link_all_packages()

java_binary(
name = "bazel-diff",
main_class = "com.bazel_diff.Main",
runtime_deps = ["@bazel_diff//jar"],
)

js_binary(
name = "cli",
data = [
"lib/actions/GenerateAction.mjs",
"lib/actions/PublishAction.mjs",
"lib/actions/VersionAction.mjs",
"lib/repositories/ChangelogRepository.mjs",
"lib/repositories/ChangesetRepository.mjs",
"lib/repositories/ConfigRepository.mjs",
"lib/repositories/PackageRepository.mjs",
"lib/repositories/PublishRepository.mjs",
"lib/repositories/ReleaseRepository.mjs",
"lib/repositories/TargetRepository.mjs",
"lib/repositories/VersionRepository.mjs",
"lib/utils.mjs",
"//:node_modules/@changesets/write",
"//:node_modules/commander",
"//:node_modules/zx",
],
entry_point = "cli.mjs",
env = {
"WORKSPACE_NAME": repository_name().lstrip("@"),
},
)

js_binary(
name = "changesets_cli",
data = [
"//:node_modules/@changesets/changelog-github",
"//:node_modules/@changesets/cli",
"//:node_modules/zx",
],
entry_point = "changesets_cli.mjs",
)
53 changes: 53 additions & 0 deletions rules/rules_release/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
All the dependencies for rules_release
"""

module(
name = "rules_release",
repo_name = "rules_release",
version = "0.0.0",
)

bazel_dep(
name = "bazel_skylib",
version = "1.4.2",
)

# ------------------------------------ rules_java ------------------------------------ #
bazel_dep(name = "rules_java", version = "7.0.6")

non_module_dependencies = use_extension(":extensions.bzl", "non_module_dependencies")

use_repo(non_module_dependencies, "bazel_diff")

# ------------------------------------ rules_js ------------------------------------ #
bazel_dep(
name = "aspect_rules_js",
version = "1.33.1",
)

####### Node.js version #########
# By default you get the node version from DEFAULT_NODE_VERSION in @rules_nodejs//nodejs:repositories.bzl
# Optionally you can pin a different node version:
bazel_dep(
name = "rules_nodejs",
version = "5.8.2",
)

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")

node.toolchain(node_version = "16.14.2")
#################################

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
)

npm.npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

use_repo(npm, "npm")
Empty file added rules/rules_release/WORKSPACE
Empty file.
7 changes: 7 additions & 0 deletions rules/rules_release/changesets_cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { cd } from "zx";

const workspaceDir = process.env.WORKSPACE_DIR;

cd(workspaceDir);

import("@changesets/cli").then(() => {});
70 changes: 70 additions & 0 deletions rules/rules_release/cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Command } from "commander";
const program = new Command();

function collect(val, memo) {
memo.push(val);
return memo;
}

import GenerateAction from "./lib/actions/GenerateAction.mjs";
import VersionAction from "./lib/actions/VersionAction.mjs";
import PublishAction from "./lib/actions/PublishAction.mjs";

program
.name("release-manager")
.description("CLI to manage releases using changesets and Bazel")
.option("-c, --config <items>", "Config items", collect, [])
.version("0.0.0");

program
.command("generate")
.description(
"Generate changesets based on changed targets with latest master"
)
.requiredOption("--bazel-diff-path <string>")
.option(
"--bazel-diff-args <string>",
"Additional args generate hashes command for bazel-diff",
""
)
.action(async (options) => {
const action = new GenerateAction({
configPaths: program.opts().config,
bazelDiffPath: options.bazelDiffPath,
bazelDiffArgs: options.bazelDiffArgs,
});
await action.execute();
});

program
.command("version")
.description("Update version files based on changesets")
.requiredOption("--changesets-path <string>")
.action(async (options) => {
const action = new VersionAction({
configPaths: program.opts().config,
changesetsPath: options.changesetsPath,
});
await action.execute();
});

program
.command("publish")
.description(
"Run the publish scripts for each release and for the release manager"
)
.option(
"--publish-cmd <items>",
"Publish commands of the release manager",
collect,
[]
)
.action(async (options) => {
const action = new PublishAction({
configPaths: program.opts().config,
publishCmds: options.publishCmd,
});
await action.execute();
});

program.parse();
8 changes: 8 additions & 0 deletions rules/rules_release/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("//:repositories.bzl", "dependencies")

def _non_module_dependencies_impl(_ctx):
dependencies()

non_module_dependencies = module_extension(
implementation = _non_module_dependencies_impl,
)
Loading

0 comments on commit aca6efb

Please sign in to comment.