Skip to content

Commit

Permalink
chore: refactor CI generation to include tests outside of examples (#…
Browse files Browse the repository at this point in the history
…319)

- Introduce `//ci` package. It contains the following:
  - `bzlmod_modes`: Module for managing enable/disable bzlmod values.
- `ci_integration_test_params`: Rule to collect test parameters for an
integration test.
- `ci_test_params_suite`: Rule for aggregating one or more
`ci_integration_test_params`.
- `ci_workflow`: Macro that generates a GitHub workflow files, defines a
test to confirm the version in source matches the generated version, and
defines a runnable target to update the source tree.
- Update `generate_ci_workflow` to expect the new test params JSON.

Closes #311.
  • Loading branch information
cgrindel authored Mar 29, 2023
1 parent 8802fcb commit 0ef0d56
Show file tree
Hide file tree
Showing 28 changed files with 784 additions and 217 deletions.
24 changes: 24 additions & 0 deletions .github/actions/execute_test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Execute Test

inputs:
test_target:
description: The test target to execute.
required: true
bzlmod_enabled:
description: Boolean value that specifies whether bzlmod should be enabled.
required: true

runs:
using: composite
steps:
- name: Execute Test
shell: bash
env:
TEST_TARGET: ${{ inputs.test_target }}
BZLMOD_ENABLED: ${{ inputs.bzlmod_enabled }}
run: |
if [[ "${BZLMOD_ENABLED}" == "false" ]] && [[ "${TEST_TARGET}" =~ ^@@ ]]; then
# Strip the first @ from test target
TEST_TARGET="${TEST_TARGET#@}"
fi
bazelisk test "${TEST_TARGET}"
19 changes: 0 additions & 19 deletions .github/actions/test_example/action.yml

This file was deleted.

90 changes: 41 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# This file is processed by //tools/generate_ci_workflow. Specifically, the
# matrix strategy sections for the integration test matrix jobs are updated with
# the values from //examples:json.
# Portions of this file are generated by the build.
#
# Note:
# - Modification to values outside of the matrix strategy sections should
Expand Down Expand Up @@ -29,76 +27,70 @@ jobs:
fail-fast: false
matrix:
include:
- example: http_archive_ext_deps
bazel_version: .bazelversion
- test: '@@//bzlmod:e2e_test'
runner: ubuntu-22.04
enable_bzlmod: true
- test: '@@//bzlmod:e2e_test'
runner: macos-12
enable_bzlmod: true
- example: http_archive_ext_deps
bazel_version: .bazelversion
- test: '@@//examples:firebase_example_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- test: '@@//examples:http_archive_ext_deps_test_bazel_.bazelversion'
runner: ubuntu-22.04
enable_bzlmod: false
- example: http_archive_ext_deps
bazel_version: .bazelversion
- test: '@@//examples:http_archive_ext_deps_test_bazel_.bazelversion'
runner: ubuntu-22.04
enable_bzlmod: true
- example: http_archive_ext_deps
bazel_version: .bazelversion
runner: ubuntu-22.04
- test: '@@//examples:http_archive_ext_deps_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: false
- example: pkg_manifest_minimal
bazel_version: .bazelversion
- test: '@@//examples:http_archive_ext_deps_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: pkg_manifest_minimal
bazel_version: .bazelversion
runner: ubuntu-22.04
- test: '@@//examples:interesting_deps_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: soto_example
bazel_version: .bazelversion
- test: '@@//examples:ios_sim_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: soto_example
bazel_version: .bazelversion
runner: ubuntu-22.04
- test: '@@//examples:objc_code_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: vapor_example
bazel_version: .bazelversion
- test: '@@//examples:phone_number_kit_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: vapor_example
bazel_version: .bazelversion
- test: '@@//examples:pkg_manifest_minimal_test_bazel_.bazelversion'
runner: ubuntu-22.04
enable_bzlmod: true
- test: '@@//examples:pkg_manifest_minimal_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: false
- example: vapor_example
bazel_version: .bazelversion
enable_bzlmod: true
- test: '@@//examples:soto_example_test_bazel_.bazelversion'
runner: ubuntu-22.04
enable_bzlmod: true
- example: vapor_example
bazel_version: .bazelversion
- test: '@@//examples:soto_example_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- test: '@@//examples:vapor_example_test_bazel_.bazelversion'
runner: ubuntu-22.04
enable_bzlmod: false
- example: firebase_example
bazel_version: .bazelversion
runner: macos-12
- test: '@@//examples:vapor_example_test_bazel_.bazelversion'
runner: ubuntu-22.04
enable_bzlmod: true
- example: interesting_deps
bazel_version: .bazelversion
- test: '@@//examples:vapor_example_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: ios_sim
bazel_version: .bazelversion
enable_bzlmod: false
- test: '@@//examples:vapor_example_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: objc_code
bazel_version: .bazelversion
- test: '@@//examples:xcmetrics_example_test_bazel_.bazelversion'
runner: macos-12
enable_bzlmod: true
- example: phone_number_kit
bazel_version: .bazelversion
runner: macos-12
- test: '@@//release:archive_test'
runner: ubuntu-22.04
enable_bzlmod: true
- example: xcmetrics_example
bazel_version: .bazelversion
- test: '@@//release:archive_test'
runner: macos-12
enable_bzlmod: true
runs-on: ${{ matrix.runner }}
Expand All @@ -116,10 +108,10 @@ jobs:
with:
repo_name: swift_bazel
xcode_version: 14.0.1
- uses: ./.github/actions/test_example
- uses: ./.github/actions/execute_test
with:
bazel_version: ${{ matrix.bazel_version }}
example_name: ${{ matrix.example }}
bzlmod_enabled: ${{ matrix.bzlmod_enabled }}
test_target: ${{ matrix.test }}
tidy_and_test_matrix:
strategy:
fail-fast: false
Expand Down
36 changes: 10 additions & 26 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg")
load("@cgrindel_bazel_starlib//bzltidy:defs.bzl", "tidy")
load("@cgrindel_bazel_starlib//markdown:defs.bzl", "markdown_pkg")
load("@cgrindel_bazel_starlib//shlib/rules:execute_binary.bzl", "execute_binary")
load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_diff_and_update", "updatesrc_update_all")
load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update_all")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"integration_test_utils",
)
load("//ci:defs.bzl", "ci_workflow")

# MARK: - Bazel Starlark Lint and Formatting

Expand Down Expand Up @@ -155,6 +155,8 @@ filegroup(
# Include every package that is required by the child workspaces.
srcs = [
":all_files",
"//ci:all_files",
"//ci/internal:all_files",
"//config_settings/bazel/apple_platform_type:all_files",
"//config_settings/bazel/compilation_mode:all_files",
"//config_settings/spm/configuration:all_files",
Expand Down Expand Up @@ -204,32 +206,14 @@ test_suite(

# MARK: - CI Workflow

run_binary(
ci_workflow(
name = "ci_workflow",
srcs = [
".github/workflows/ci.yml",
"//examples:json",
],
outs = ["ci.yml"],
args = [
"-template",
"$(location .github/workflows/ci.yml)",
"-example_json",
"$(location //examples:json)",
"-output",
"$(location ci.yml)",
],
tool = "//tools/generate_ci_workflow",
)

updatesrc_diff_and_update(
name = "update",
srcs = [
".github/workflows/ci.yml",
],
outs = [
":ci_workflow",
test_params = [
"//bzlmod:e2e_test_params",
"//release:archive_test_params",
"//examples:all_example_test_params",
],
workflow_yml = ".github/workflows/ci.yml",
)

bzl_library(
Expand Down
13 changes: 13 additions & 0 deletions bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load(
"bazel_integration_test",
"integration_test_utils",
)
load("//ci:defs.bzl", "ci_integration_test_params")

bzlformat_pkg(name = "bzlformat")

Expand Down Expand Up @@ -34,8 +35,20 @@ bazel_integration_test(
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
test_runner = ":e2e_test_runner",
visibility = ["//:__subpackages__"],
workspace_files = integration_test_utils.glob_workspace_files("workspace") + [
"//:runtime_files",
],
workspace_path = "workspace",
)

ci_integration_test_params(
name = "e2e_test_params",
bzlmod_modes = ["enabled"],
oss = [
"macos",
"linux",
],
test_names = ["e2e_test"],
visibility = ["//:__subpackages__"],
)
22 changes: 22 additions & 0 deletions ci/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")

bzlformat_pkg(name = "bzlformat")

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [
"//ci/internal:bzlmod_modes",
"//ci/internal:ci_integration_test_params",
"//ci/internal:ci_workflow",
"//ci/internal:providers",
],
)

filegroup(
name = "all_files",
srcs = glob(["*"]),
visibility = ["//:__subpackages__"],
)
27 changes: 27 additions & 0 deletions ci/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Public API for CI workflow generation."""

load("//ci/internal:bzlmod_modes.bzl", _bzlmod_modes = "bzlmod_modes")
load(
"//ci/internal:ci_integration_test_params.bzl",
_ci_integration_test_params = "ci_integration_test_params",
)
load(
"//ci/internal:ci_test_params_suite.bzl",
_ci_test_params_suite = "ci_test_params_suite",
)
load("//ci/internal:ci_workflow.bzl", _ci_workflow = "ci_workflow")
load(
"//ci/internal:providers.bzl",
_CITestParamsInfo = "CITestParamsInfo",
)

# Modules
bzlmod_modes = _bzlmod_modes

# Rules
ci_integration_test_params = _ci_integration_test_params
ci_workflow = _ci_workflow
ci_test_params_suite = _ci_test_params_suite

# Providers
CITestParamsInfo = _CITestParamsInfo
56 changes: 56 additions & 0 deletions ci/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")

bzlformat_pkg(name = "bzlformat")

bzl_library(
name = "ci_integration_test_params",
srcs = ["ci_integration_test_params.bzl"],
visibility = ["//visibility:public"],
deps = [":providers"],
)

bzl_library(
name = "ci_workflow",
srcs = ["ci_workflow.bzl"],
visibility = ["//visibility:public"],
deps = [
":providers",
"@cgrindel_bazel_starlib//updatesrc:defs",
],
)

bzl_library(
name = "ci_test_params",
srcs = ["ci_test_params.bzl"],
visibility = ["//ci:__subpackages__"],
deps = [":providers"],
)

bzl_library(
name = "ci_test_params_suite",
srcs = ["ci_test_params_suite.bzl"],
visibility = ["//ci:__subpackages__"],
deps = [
":ci_test_params",
":providers",
],
)

filegroup(
name = "all_files",
srcs = glob(["*"]),
visibility = ["//:__subpackages__"],
)

bzl_library(
name = "bzlmod_modes",
srcs = ["bzlmod_modes.bzl"],
visibility = ["//ci:__subpackages__"],
)

bzl_library(
name = "providers",
srcs = ["providers.bzl"],
visibility = ["//ci:__subpackages__"],
)
Loading

0 comments on commit 0ef0d56

Please sign in to comment.