From 27bf8054b5581adb0e5e0567e68fe89f846b169b Mon Sep 17 00:00:00 2001 From: phlax Date: Thu, 15 Aug 2024 13:03:34 +0100 Subject: [PATCH] bazel: Add `@envoy_repo` (#5) Signed-off-by: Ryan Northey --- .github/workflows/envoy.yml | 25 +++++++++++++++++++++++++ BUILD | 24 ++++++++++++++++++++++++ WORKSPACE | 10 +++++++--- deps.bzl | 2 ++ deps_extra.bzl | 6 ++++++ setup_extra.bzl | 6 ++++++ toolchains.bzl | 14 +++++++++----- versions.bzl | 2 ++ 8 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/envoy.yml create mode 100644 deps_extra.bzl create mode 100644 setup_extra.bzl diff --git a/.github/workflows/envoy.yml b/.github/workflows/envoy.yml new file mode 100644 index 0000000..26cb564 --- /dev/null +++ b/.github/workflows/envoy.yml @@ -0,0 +1,25 @@ +name: Envoy + +permissions: + contents: read + +on: + pull_request: + push: + branches: + - main + +concurrency: + group: >- + ${{ github.event.inputs.head_ref || github.run_id }} + + +jobs: + envoy: + runs-on: ubuntu-24.04 + if: github.repository_owner == 'envoyproxy' + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - run: | + bazel build --config=ci //:envoy_versions + cat bazel-bin/envoy_versions.json | jq '.' diff --git a/BUILD b/BUILD index 69a2983..c00c174 100644 --- a/BUILD +++ b/BUILD @@ -1,5 +1,6 @@ load("@bazel_gazelle//:def.bzl", "gazelle") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@aspect_bazel_lib//lib:jq.bzl", "jq") # gazelle:prefix github.com/aptly-dev/aptly gazelle(name = "gazelle") @@ -21,3 +22,26 @@ gazelle( command = "update-repos", data = [":go.mod"], ) + +jq( + name = "envoy_versions", + srcs = ["@envoy_repo//:project"], + out = "envoy_versions.json", + filter = """ + .releases as $releases + | { + latest_releases: [ + .stable_versions[] + | . as $minor + | { + version: $minor, + releases: ( + $releases + | map(select(startswith("v" + $minor + "."))) + ) + } + ] + } + """, + visibility = ["//visibility:public"], +) diff --git a/WORKSPACE b/WORKSPACE index c97e90d..c8c65b7 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -11,9 +11,13 @@ load("//:setup.bzl", "setup") setup() load("//:toolchains.bzl", "toolchains") -toolchains() +toolchains(VERSIONS) + +load("//:setup_extra.bzl", "setup_extra") +setup_extra() + +load("//:deps_extra.bzl", "dependencies_extra") +dependencies_extra() -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") # gazelle:repo bazel_gazelle # gazelle:repository_macro deps-go.bzl%go_dependencies -gazelle_dependencies(go_repository_default_config = "//:WORKSPACE") diff --git a/deps.bzl b/deps.bzl index 4fc1418..e3a82da 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,3 +1,4 @@ +load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") @@ -10,3 +11,4 @@ def dependencies(): aptly_dependencies() go_dependencies() go_rules_dependencies() + aspect_bazel_lib_dependencies() diff --git a/deps_extra.bzl b/deps_extra.bzl new file mode 100644 index 0000000..ad44759 --- /dev/null +++ b/deps_extra.bzl @@ -0,0 +1,6 @@ +load("@base_pip3//:requirements.bzl", pip_dependencies = "install_deps") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +def dependencies_extra(): + pip_dependencies() + gazelle_dependencies(go_repository_default_config = "//:WORKSPACE") diff --git a/setup_extra.bzl b/setup_extra.bzl new file mode 100644 index 0000000..fcbd224 --- /dev/null +++ b/setup_extra.bzl @@ -0,0 +1,6 @@ +load("@envoy//bazel:python_dependencies.bzl", "envoy_python_dependencies") +load("@envoy//bazel:repo.bzl", "envoy_repo") + +def setup_extra(): + envoy_python_dependencies() + envoy_repo() diff --git a/toolchains.bzl b/toolchains.bzl index 700c478..e8e6d50 100644 --- a/toolchains.bzl +++ b/toolchains.bzl @@ -1,13 +1,17 @@ +load("@aspect_bazel_lib//lib:repositories.bzl", "register_jq_toolchains", "register_yq_toolchains") load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains") load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains") load("@rules_python//python:repositories.bzl", "python_register_toolchains") -def toolchains(): +def _python_minor_version(python_version): + return "_".join(python_version.split(".")[:2]) + +def toolchains(versions): python_register_toolchains( - name = "python3_12", - # Available versions are listed in @rules_python//python:versions.bzl. - # We recommend using the same version your team is already standardized on. - python_version = "3.12", + name = "python%s" % _python_minor_version(versions["python"]), + python_version = versions["python"], ) rules_proto_toolchains() go_register_toolchains(version = "1.22.4") + register_jq_toolchains(version = versions["jq"]) + register_yq_toolchains(version = versions["yq"]) diff --git a/versions.bzl b/versions.bzl index c211429..b7f54a5 100644 --- a/versions.bzl +++ b/versions.bzl @@ -1,5 +1,7 @@ VERSIONS = { + "jq": "1.7", + "yq": "4.24.4", "python": "3.12", "aspect_bazel_lib": { "type": "github_archive",