Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions .github/workflows/envoy-dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,82 @@ on:
workflow_dispatch:
inputs:
task:
description: 'Select a task'
description: Select a task
required: true
default: build-image
enum:
default: bazel
type: choice
options:
- bazel
- bazel-api
- build-image
dependency:
description: Dependency to update (if applicable)
version:
description: Version to set (optional)
pr:
type: boolean
default: true
pr_message:
description: Additional message for PR, eg to fix an issue (optional)

concurrency:
group: ${{ github.run_id }}-${{ github.workflow }}
cancel-in-progress: true


jobs:
update_bazel:
if: startsWith(inputs.task, 'bazel')
name: >-
Update dep
(${{ inputs.pr && 'PR/' || '' }}${{ inputs.task == 'bazel' && 'bazel' || 'bazel/api' }}/${{ inputs.dependency }}/${{ inputs.version }})
runs-on: ubuntu-22.04
steps:
- id: checkout
name: Checkout Envoy repository
uses: envoyproxy/toolshed/gh-actions/github/checkout@actions-v0.0.25
with:
app_id: ${{ secrets.ENVOY_CI_DEP_APP_ID }}
app_key: ${{ secrets.ENVOY_CI_DEP_APP_KEY }}
- id: version
name: Shorten (possible) SHA
uses: envoyproxy/toolshed/gh-actions/str/sub@actions-v0.0.25
with:
string: ${{ inputs.version }}
length: 7
min: 40
- run: |
echo "Updating(${TASK}): ${DEPENDENCY} -> ${VERSION}"
bazel run --config=ci //bazel:${TARGET} $DEPENDENCY $VERSION
name: Update dependency
env:
DEPENDENCY: ${{ inputs.dependency }}
VERSION: ${{ inputs.version }}
TARGET: ${{ inputs.task == 'bazel' && 'update' || 'api-update' }}
TASK: ${{ inputs.task == 'bazel' && 'bazel' || 'api/bazel' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: envoyproxy/toolshed/gh-actions/upload/diff@actions-v0.0.25
name: Upload diff
with:
name: ${{ inputs.dependency }}-${{ steps.version.outputs.string }}
- name: Create a PR
if: ${{ inputs.pr }}
uses: envoyproxy/toolshed/gh-actions/github/pr@actions-v0.0.25
with:
base: main
body: |
Created by Envoy dependency bot for @${{ github.actor }}

${{ inputs.pr_message }}
branch: >-
dependency/${{ inputs.task }}/${{ inputs.dependency }}/${{ steps.version.outputs.string }}
committer-name: publish-envoy[bot]
committer-email: 140627008+publish-envoy[bot]@users.noreply.github.com
title: >-
${{ inputs.task == 'bazel' && 'deps' || 'deps/api' }}: Bump `${{ inputs.dependency }}`
-> ${{ steps.version.outputs.string }}
GITHUB_TOKEN: ${{ steps.checkout.outputs.token }}

update_build_image:
if: github.event.inputs.task == 'build-image'
name: Update build image (PR)
Expand Down
6 changes: 3 additions & 3 deletions api/bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "envoy_toolshed",
project_desc = "Tooling, libraries, runners and checkers for Envoy proxy's CI",
project_url = "https://github.com/envoyproxy/toolshed",
version = "0.0.10",
sha256 = "bdfcf0a23c18a99887ac25761aa56d85bedb6eda77c89f9f19e6142b812749b9",
version = "0.1.1",
sha256 = "ee759b57270a2747f3f2a3d6ecaad63b834dd9887505a9f1c919d72429dbeffd",
strip_prefix = "toolshed-bazel-v{version}/bazel",
urls = ["https://github.com/envoyproxy/toolshed/archive/bazel-v{version}.tar.gz"],
use_category = ["build"],
release_date = "2023-10-02",
release_date = "2023-10-21",
cpe = "N/A",
license = "Apache-2.0",
license_url = "https://github.com/envoyproxy/envoy/blob/bazel-v{version}/LICENSE",
Expand Down
34 changes: 30 additions & 4 deletions bazel/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
load("//bazel:envoy_build_system.bzl", "envoy_package")
load("//bazel:envoy_internal.bzl", "envoy_select_force_libcpp")
load("@envoy_toolshed//:macros.bzl", "json_data")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load(":repository_locations.bzl", "REPOSITORY_LOCATIONS_SPEC")
load("@envoy_api//bazel:repository_locations.bzl", API_REPOSITORY_LOCATIONS_SPEC = "REPOSITORY_LOCATIONS_SPEC")
load("@envoy_api//bazel:repository_locations_utils.bzl", "load_repository_locations_spec", "merge_dicts")
load("@envoy_toolshed//:macros.bzl", "json_data")
load("@envoy_toolshed//dependency:macros.bzl", "updater")
load("//bazel:envoy_build_system.bzl", "envoy_package")
load("//bazel:envoy_internal.bzl", "envoy_select_force_libcpp")
load(":repository_locations.bzl", "REPOSITORY_LOCATIONS_SPEC")

licenses(["notice"]) # Apache 2

Expand Down Expand Up @@ -887,3 +888,28 @@ cc_library(
name = "python_headers",
visibility = ["//visibility:public"],
)

# These can be run as follows:
#
# $ bazel run //bazel:update ENVOY_DEP NEW_VERSION
# $ bazel run //bazel:api-update API_DEP NEW_VERSION
updater(
name = "update",
data = ["//tools/dependency:check"],
dependencies = ":repository_locations",
post_script = ":version_update_post.sh",
pydict = True,
tags = ["skip_on_windows"],
version_file = ":repository_locations.bzl",
)

updater(
name = "api-update",
data = ["//tools/dependency:check"],
dependencies = "@envoy_api//bazel:repository_locations",
post_script = ":version_update_post.sh",
pydict = True,
tags = ["skip_on_windows"],
version_file = "@envoy_api//bazel:repository_locations.bzl",
version_path_replace = "external/envoy_api:api",
)
78 changes: 78 additions & 0 deletions bazel/version_update_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash -e

set -o pipefail


EXISTING_DATE="$("${JQ}" -r ".${DEP}.release_date" "${DEP_DATA}")"
DATE_SEARCH="release_date = \"${EXISTING_DATE}\","
DEP_CHECK="${DEP_CHECK:-tools/dependency/check}"

find_date_line () {
local match match_ln date_match_ln
# This needs to find the correct date to replace
match="$(\
grep -n "${DEP_SEARCH}" "${VERSION_FILE}" \
| cut -d: -f-2)"
match_ln="$(\
echo "${match}" \
| cut -d: -f1)"
match_ln="$((match_ln + 1))"
date_match_ln="$(\
tail -n "+${match_ln}" "${VERSION_FILE}" \
| grep -n "${DATE_SEARCH}" \
| head -n1 \
| cut -d: -f1)"
date_match_ln="$((match_ln + date_match_ln - 1))"
printf '%s' "$date_match_ln"
}

update_date () {
local match_ln search replace
match_ln="$1"
search="$2"
replace="$3"
echo "Updating date(${match_ln}): ${search} -> ${replace}"
sed -i "${match_ln}s/${search}/${replace}/" "$VERSION_FILE"
}

get_new_date () {
# create a repository_locations with just the dep and with updated version
tmpfile="$(mktemp)"
# shellcheck disable=SC2016
"$JQ" --arg new_version "$VERSION" \
--arg existing_version "$EXISTING_VERSION" \
--arg dep "$DEP" \
'if has($dep) then .[$dep].version = $new_version | .[$dep].urls |= map(gsub($existing_version; $new_version)) else . end' \
"$DEP_DATA" > "$tmpfile"
output="$(\
"$DEP_CHECK" \
--repository_locations="$tmpfile" \
--path "${BUILD_WORKSPACE_DIRECTORY}" \
-c release_dates 2>&1)"
echo "$output" \
| grep -E "^Mismatch" \
| grep "$DEP" \
| cut -d= -f2 \
| xargs || {
cat "$tmpfile" >&2
echo "$output" >&2
rm "$tmpfile"
exit 1
}
rm "$tmpfile"
}

post_version_update () {
local date_ln new_date
if [[ "$EXISTING_VERSION" == "$VERSION" ]]; then
echo "Nothing to update" >&2
exit 0
fi
date_ln="$(find_date_line)"
new_date="$(get_new_date)"
if [[ -z "$new_date" ]]; then
echo "Unable to retrieve date" >&2
exit 1
fi
update_date "$date_ln" "$EXISTING_DATE" "$new_date"
}