Skip to content

Commit

Permalink
feat: Release rules_task and rules_release (#609)
Browse files Browse the repository at this point in the history
* Release rules_task and rules_release

* Setup release names

* Try to use multitool with github_cli

* Remove multitool

* Working publish github release rule

* Try to setup template rule for github

* Working template for github release

* Upload gitlab release with a tar.gz archive

* Wire bunq2ynab with publish_to_github rule

* Proper wiring for rules_task

* Change directory structure rules_task

* Implement all_files

* Remove global defs

* Sort imports

* Move runner files

* Setup release deps

* Created changesets

* Remove semantic release
  • Loading branch information
mvgijssel authored Nov 24, 2023
1 parent 2168bf2 commit fb47806
Show file tree
Hide file tree
Showing 58 changed files with 715 additions and 2,541 deletions.
5 changes: 5 additions & 0 deletions .changeset/rules_release-wicked-carrots-obey-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": minor
---

Add publish_github_release to make publishing GitHub releases easier.
5 changes: 5 additions & 0 deletions .changeset/rules_release-wicked-carrots-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": patch
---

Setup release flow for rules_release
5 changes: 5 additions & 0 deletions .changeset/rules_task-ninety-lobsters-fold-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_task": patch
---

Replaced semantic release with rules_release release flow.
7 changes: 7 additions & 0 deletions .changeset/rules_task-ninety-lobsters-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"rules_task": major
---

BREAKING CHANGE: Restructure the directory layout so it's the same as rules_release. This enables
using development dependencies in the root BUILD.bazel file without having to install those
when this rule is used in another repository.
49 changes: 0 additions & 49 deletions .github/workflows/release.yml

This file was deleted.

7 changes: 5 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_task//:defs.bzl", "cmd", "task")
load("@rules_task//task:defs.bzl", "cmd", "task")
load(
"@jvolkman_rules_pycross//pycross:defs.bzl",
"pycross_lock_file",
Expand Down Expand Up @@ -229,10 +229,13 @@ task(

release_manager(
name = "release_manager",
bazel_diff_args = "--fineGrainedHashExternalRepos=rules_release,rules_task",
publish_cmds = [
":push_git_changes",
],
deps = [
"//tools/bunq2ynab:bunq2ynab_release",
"//tools/bunq2ynab:release",
"@rules_release//:release",
"@rules_task//:release",
],
)
6 changes: 4 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ bazel_dep(name = "platforms", version = "0.0.8")

# ------------------------------------ rules_skylib ------------------------------------ #
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "aspect_bazel_lib", version = "2.0.0-rc1")

# ------------------------------------ aspect_bazel_lib ------------------------------------ #
bazel_dep(name = "aspect_bazel_lib", version = "2.0.1")

# ------------------------------------ rules_pkg ------------------------------------ #
bazel_dep(name = "rules_pkg", version = "0.9.1")

# ------------------------------------ rules_task ------------------------------------ #
bazel_dep(name = "rules_task", version = "0.1.0")
bazel_dep(name = "rules_task", version = "0.0.0")

local_path_override(
module_name = "rules_task",
Expand Down
25 changes: 0 additions & 25 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -326,28 +326,3 @@ 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",
)
2 changes: 1 addition & 1 deletion infrastructure/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_task//:defs.bzl", "cmd", "task")
load("@rules_task//task:defs.bzl", "cmd", "task")
load("@pdm-setup//:requirements.bzl", "requirement")

package(default_visibility = ["//visibility:public"])
Expand Down
2 changes: 1 addition & 1 deletion occupancy_component/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@pdm-setup//:requirements.bzl", "requirement")
load("//tools/pytest:pytest.bzl", "py_pytest_test")
load("@rules_task//:defs.bzl", "cmd", "task")
load("@rules_task//task:defs.bzl", "cmd", "task")

py_library(
name = "lib",
Expand Down
2 changes: 1 addition & 1 deletion provisioner/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//tools/pyinfra:defs.bzl", "pyinfra_run")
load("@rules_task//:defs.bzl", "cmd", "task", "task_test")
load("@rules_task//task:defs.bzl", "cmd", "task", "task_test")
load("//tools/docker:docker.bzl", "docker_load")
load("@pdm-setup//:requirements.bzl", "requirement")
load("//tools/onepassword:defs.bzl", "secrets")
Expand Down
141 changes: 139 additions & 2 deletions rules/rules_release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library", "js_test")
load("@aspect_rules_js//js:defs.bzl", "js_binary")
load("@rules_java//java:defs.bzl", "java_binary")
load("@rules_task//task:defs.bzl", "cmd")
load("//release:defs.bzl", "publish_github_release", "release")
load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar")

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

_darwin_arm64 = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
]

_linux_amd64 = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
]

_linux_arm64 = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
]

config_setting(
name = "is_linux_amd64",
constraint_values = _linux_amd64,
)

config_setting(
name = "is_linux_arm64",
constraint_values = _linux_arm64,
)

config_setting(
name = "is_darwin_arm64",
constraint_values = _darwin_arm64,
)

npm_link_all_packages()

java_binary(
Expand Down Expand Up @@ -33,7 +66,7 @@ js_binary(
],
entry_point = "cli.mjs",
env = {
"WORKSPACE_NAME": repository_name().lstrip("@"),
"WORKSPACE_NAME": repository_name().removeprefix("@"),
},
)

Expand All @@ -46,3 +79,107 @@ js_binary(
],
entry_point = "changesets_cli.mjs",
)

filegroup(
name = "all_files",
srcs = glob(["**/*"]) + [
"//release:all_files",
"//release/private:all_files",
],
)

mtree_spec(
name = "release_archive_mtree",
srcs = [
":all_files",
],
)

# Remove `../rules_release~override` from each line because otherwise
# this results in an empty archive when extracting.
genrule(
name = "release_archive_mtree_normalized",
srcs = [
":release_archive_mtree",
],
outs = [
"release_archive_mtree_normalized.spec",
],
cmd = """
sed 's|../{}/||' $< > $@
""".format(repository_name().removeprefix("@")),
)

tar(
name = "release_archive",
srcs = [
":all_files",
],
out = "rules_release.tar.gz",
compress = "gzip",
mtree = ":release_archive_mtree_normalized",
)

genrule(
name = "github_release_template",
srcs = [
":release.version_changelog",
":release.version",
":release_archive",
],
outs = [
"github_release_template.txt",
],
cmd = """
export VERSION="v$$(cat $(location :release.version))"
export SHA=$$(shasum -a 256 $(location :release_archive) | awk '{print $$1}')
export PREFIX="rules_release-$${VERSION}"
export ARCHIVE="rules_release.tar.gz"
cat <<EOF > $(OUTS)
## Using WORKSPACE:
\\`\\`\\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_release",
sha256 = "$${SHA}",
url = "https://github.com/vgijssel/setup/releases/download/$${PREFIX}/$${ARCHIVE}",
)
\\`\\`\\`
EOF
cat $(location :release.version_changelog) >> $(OUTS)
""",
)

publish_github_release(
name = "publish_github_release",
assets = [
":release_archive",
],
before_cmds = [
"export OP_SERVICE_ACCOUNT_TOKEN=${ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD:-}",
"export GH_TOKEN=$($OP read op://vgijssel-prod/github-release/credential)",
],
changelog_file = ":github_release_template",
env = {
"OP": cmd.executable("//tools/onepassword:op"),
},
release = ":release",
)

release(
name = "release",
changelog_file = "CHANGELOG.md",
publish_cmds = [
":publish_github_release",
],
release_name = "rules_release",
target = ":all_files",
version_file = "version.txt",
deps = [
"@rules_task//:release",
],
)
Empty file.
36 changes: 33 additions & 3 deletions rules/rules_release/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,44 @@ module(
version = "0.0.0",
)

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

# ------------------------------------ platforms ------------------------------------ #
bazel_dep(name = "platforms", version = "0.0.8")

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

# ------------------------------------ aspect_bazel_lib ------------------------------------ #
bazel_dep(name = "aspect_bazel_lib", version = "2.0.1")

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

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

# ------------------------------------ bazel-diff ------------------------------------ #
use_repo(non_module_dependencies, "bazel_diff")

# ------------------------------------ github_cli ------------------------------------ #
use_repo(non_module_dependencies, "github_cli_linux_arm64")

use_repo(non_module_dependencies, "github_cli_linux_amd64")

use_repo(non_module_dependencies, "github_cli_darwin_arm64")

# ------------------------------------ onepassword ------------------------------------ #
use_repo(non_module_dependencies, "onepassword_linux_arm64")

use_repo(non_module_dependencies, "onepassword_linux_amd64")

use_repo(non_module_dependencies, "onepassword_darwin_arm64")

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

####### Node.js version #########
Expand Down Expand Up @@ -51,3 +73,11 @@ npm.npm_translate_lock(
)

use_repo(npm, "npm")

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

local_path_override(
module_name = "rules_task",
path = "../rules_task",
)
6 changes: 6 additions & 0 deletions rules/rules_release/release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "all_files",
srcs = glob(["**/*"]),
)
Loading

0 comments on commit fb47806

Please sign in to comment.