Skip to content

Commit

Permalink
chore: add bzlmod_e2e in preparation for publishing to BCR (#234)
Browse files Browse the repository at this point in the history
- Add `examples/bzlmod_e2e` child workspace as test for publish_to_bcr
presubmit.
- Add `.bcr` files for public_to_bcr.

Related to #195.
  • Loading branch information
cgrindel authored Mar 9, 2023
1 parent 5962eab commit fe93c39
Show file tree
Hide file tree
Showing 30 changed files with 408 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This lets us glob() up all the files inside the examples to make them inputs to tests
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, run `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`.
build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters
query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters
build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters
query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters

# Import Shared settings
import %workspace%/shared.bazelrc
Expand Down
3 changes: 3 additions & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixedReleaser:
login: cgrindel
email: chuck.grindel@gmail.com
15 changes: 15 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"homepage": "https://github.com/cgrindel/bazel-starlib",
"maintainers": [
{
"email": "chuck.grindel@gmail.com",
"github": "cgrindel",
"name": "Chuck Grindel"
}
],
"repository": [
"github:OWNER/REPO"
],
"versions": [],
"yanked_versions": {}
}
10 changes: 10 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bcr_test_module:
module_path: "examples/bzlmod_e2e"
matrix:
platform: ["macos", "ubuntu2004"]
tasks:
run_tests:
name: "Run test module"
platform: ${{ platform }}
test_targets:
- "//..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz"
}
12 changes: 11 additions & 1 deletion .github/actions/test_example/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ inputs:
runs:
using: composite
steps:
- name: Execute Integration Test
- name: Execute Integration Test in Examples Subdirectory
if: inputs.example_dir != ''
shell: bash
env:
# The integration tests make use of Github-specific functionality
# (e.g. gh).
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
bazelisk test //examples/${{ inputs.example_dir }}:${{ inputs.example_name }}_test_bazel_${{ inputs.bazel_version }}
- name: Execute Integration Test in Examples Directory
if: inputs.example_dir == ''
shell: bash
env:
# The integration tests make use of Github-specific functionality
# (e.g. gh).
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
bazelisk test //examples:${{ inputs.example_name }}_test_bazel_${{ inputs.bazel_version }}
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
example_name: simple
- example_dir: updatesrc
example_name: simple
- example_dir: ""
example_name: bzlmod_e2e
enable_bzlmod: true
bazel_version: .bazelversion
runs-on: macos-12
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -74,6 +78,10 @@ jobs:
example_name: simple
- example_dir: updatesrc
example_name: simple
- example_dir: ""
example_name: bzlmod_e2e
enable_bzlmod: true
bazel_version: .bazelversion
runs-on: ubuntu-22.04
env:
CC: clang
Expand Down
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ test_suite(
name = "all_smoke_integration_tests",
tags = INTEGRATION_TEST_TAGS,
tests = [
"//examples:smoke_integration_tests",
"//examples/bzlformat:smoke_integration_tests",
"//examples/markdown:smoke_integration_tests",
"//examples/updatesrc:smoke_integration_tests",
Expand All @@ -193,6 +194,7 @@ test_suite(
name = "all_integration_tests",
tags = INTEGRATION_TEST_TAGS,
tests = [
"//examples:integration_tests",
"//examples/bzlformat:integration_tests",
"//examples/markdown:integration_tests",
"//examples/updatesrc:integration_tests",
Expand Down
57 changes: 57 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
load(
"@contrib_rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"bazel_integration_tests",
"default_test_runner",
"integration_test_utils",
)
load("//:bazel_versions.bzl", "CURRENT_BAZEL_VERSION", "SUPPORTED_BAZEL_VERSIONS")
load("//bzlformat:defs.bzl", "bzlformat_pkg")
load("//bzllib:defs.bzl", "lists")

bzlformat_pkg(name = "bzlformat")

# MARK: - Integration Tests

_EXAMPLE_DIRS = ["bzlmod_e2e"]

default_test_runner(name = "default_test_runner")

[
bazel_integration_tests(
name = "{}_test".format(dirname),
timeout = "eternal",
bazel_versions = SUPPORTED_BAZEL_VERSIONS,
test_runner = ":default_test_runner",
workspace_files = integration_test_utils.glob_workspace_files(dirname) + [
"//:workspace_integration_test_files",
],
workspace_path = dirname,
)
for dirname in _EXAMPLE_DIRS
]

test_suite(
name = "smoke_integration_tests",
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = [
integration_test_utils.bazel_integration_test_name(
":{}_test".format(dirname),
CURRENT_BAZEL_VERSION,
)
for dirname in _EXAMPLE_DIRS
],
visibility = ["//:__subpackages__"],
)

test_suite(
name = "integration_tests",
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = lists.flatten([
integration_test_utils.bazel_integration_test_names(
":{}_test".format(dirname),
SUPPORTED_BAZEL_VERSIONS,
)
for dirname in _EXAMPLE_DIRS
]),
visibility = ["//:__subpackages__"],
)
11 changes: 11 additions & 0 deletions examples/bzlmod_e2e/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Import Shared settings
import %workspace%/../../shared.bazelrc

# Import CI settings.
import %workspace%/../../ci.bazelrc

# Try to import a local.rc file; typically, written by CI
try-import %workspace%/../../local.bazelrc

# Explicitly enable bzlmod
common --enable_bzlmod
37 changes: 37 additions & 0 deletions examples/bzlmod_e2e/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load(
"@cgrindel_bazel_starlib//bzlformat:defs.bzl",
"bzlformat_missing_pkgs",
"bzlformat_pkg",
)
load("@cgrindel_bazel_starlib//markdown:defs.bzl", "markdown_pkg")
load(
"@cgrindel_bazel_starlib//updatesrc:defs.bzl",
"updatesrc_update_all",
)

# Ensures that the Starlark files in this package are formatted properly.
bzlformat_pkg(name = "bzlformat")

# Provides targets to find, test, and fix any Bazel packages that are missing bzlformat_pkg
# declarations.
#
# bzlformat_missing_pkgs_find: Find and report any Bazel packages that missing the bzlformat_pkg
# declaration.
# bzlformat_missing_pkgs_test: Like find except it fails if any missing packages are found. This is
# useful to run in CI tests to ensure that all is well.
# bzlformat_missing_pkgs_fix: Adds bzlformat_pkg declarations to any packages that are missing
# the declaration.
bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs")

# Define a runnable target to execute all of the updatesrc_update targets
# that are defined in your workspace.
updatesrc_update_all(
name = "update_all",
targets_to_run = [
# Fix the Bazel packages when we update our source files from build outputs.
":bzlformat_missing_pkgs_fix",
],
)

# Ensure that the markdown files are formatted properly
markdown_pkg(name = "markdown")
13 changes: 13 additions & 0 deletions examples/bzlmod_e2e/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module(
name = "bzlmod_e2e",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "cgrindel_bazel_starlib", version = "0.0.0")
local_path_override(
module_name = "cgrindel_bazel_starlib",
path = "../..",
)

bazel_dep(name = "bazel_skylib", version = "1.4.1")
27 changes: 27 additions & 0 deletions examples/bzlmod_e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# E2E Test Workspace for bzlmod

This workspace demonstrates a number of `bazel-starlib` capabilities in a bzlmod-enabled repository.

## Table of Contents

The following TOC is maintained by a
[`markdown_generate_toc`](https://github.com/cgrindel/bazel-starlib/blob/main/doc/markdown/rules_and_macros_overview.md#markdown_generate_toc)
rule that is defined by a
[`markdown_pkg`](https://github.com/cgrindel/bazel-starlib/blob/main/doc/markdown/rules_and_macros_overview.md#markdown_pkg).

<!-- MARKDOWN TOC: BEGIN -->
* [Foo](#foo)
* [Foo Subtitle](#foo-subtitle)
* [Bar](#bar)
<!-- MARKDOWN TOC: END -->

## Foo

This section talks about foo.

### Foo Subtitle

This section talks about something specific to foo.

## Bar

2 changes: 2 additions & 0 deletions examples/bzlmod_e2e/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Intentionally blank
# This repository uses bzlmod. Please see MODULE.bazel for configuration.
16 changes: 16 additions & 0 deletions examples/bzlmod_e2e/header/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

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

exports_files(["header.sh"])

sh_binary(
name = "add_header",
srcs = ["header.sh"],
)

bzl_library(
name = "header",
srcs = ["header.bzl"],
deps = ["@cgrindel_bazel_starlib//updatesrc:defs"],
)
44 changes: 44 additions & 0 deletions examples/bzlmod_e2e/header/header.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load(
"@cgrindel_bazel_starlib//updatesrc:defs.bzl",
"UpdateSrcsInfo",
"update_srcs",
)

def _header_impl(ctx):
outs = []
updsrcs = []
for src in ctx.files.srcs:
out = ctx.actions.declare_file(src.basename + "_with_header")
outs.append(out)
updsrcs.append(update_srcs.create(src = src, out = out))
ctx.actions.run(
outputs = [out],
inputs = [src],
executable = ctx.executable._header_tool,
arguments = [src.path, out.path, ctx.attr.header],
)

return [
DefaultInfo(files = depset(outs)),
UpdateSrcsInfo(update_srcs = depset(updsrcs)),
]

header = rule(
implementation = _header_impl,
attrs = {
"header": attr.string(
mandatory = True,
),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
),
"_header_tool": attr.label(
default = "//header:header.sh",
executable = True,
cfg = "exec",
allow_files = True,
),
},
doc = "Copies the output files to the workspace directory.",
)
13 changes: 13 additions & 0 deletions examples/bzlmod_e2e/header/header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

src="$1"
out="$2"
header="$3"

first_line=$(head -n 1 "${src}")
if [[ "${first_line}" != "${header}" ]]; then
echo "${header}" > "${out}"
fi
cat "${src}" >> "${out}"
24 changes: 24 additions & 0 deletions examples/bzlmod_e2e/mockascript/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")

bzl_library(
name = "mockascript",
srcs = ["mockascript.bzl"],
visibility = ["//visibility:public"],
deps = [
"//mockascript/internal:mockascript_library",
"@cgrindel_bazel_starlib//bzlformat:defs",
],
)

bzlformat_pkg()

bzl_library(
name = "deps",
srcs = ["deps.bzl"],
visibility = ["//visibility:public"],
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)
15 changes: 15 additions & 0 deletions examples/bzlmod_e2e/mockascript/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Dependencies for mockascript rules."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def mockascript_rules_dependencies():
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
)
16 changes: 16 additions & 0 deletions examples/bzlmod_e2e/mockascript/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")

package(default_visibility = ["//mockascript:__subpackages__"])

bzlformat_pkg(name = "bzlformat")

bzl_library(
name = "foo",
srcs = ["foo.bzl"],
)

bzl_library(
name = "mockascript_library",
srcs = ["mockascript_library.bzl"],
)
Loading

0 comments on commit fe93c39

Please sign in to comment.