Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add sync workflow #701

Merged
merged 3 commits into from
Jun 1, 2023
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
43 changes: 43 additions & 0 deletions .github/workflows/envoy-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Sync Envoy

on:
workflow_dispatch:

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

permissions:
contents: read

jobs:
sync:
runs-on: ubuntu-20.04
alecholmez marked this conversation as resolved.
Show resolved Hide resolved
permissions:
contents: write
if: |
${{
!contains(github.actor, '[bot]')
|| github.actor == 'sync-envoy[bot]'
}}
steps:
# Checkout the repo
- name: 'Checkout Repository'
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0

# Checkout the Envoy repo
- name: 'Checkout Repository'
uses: actions/checkout@v3
with:
repository: envoyproxy/envoy
ref: main
fetch-depth: 0
path: upstream

- run: mv upstream ../envoy
- run: ci/sync_envoy.sh
env:
ENVOY_SRC_DIR: ../envoy
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This repository contains a Go-based implementation of an API server that
implements the discovery service APIs defined in
[data-plane-api](https://github.com/envoyproxy/data-plane-api).

## Proto files

The Go proto files are synced from the upstream Envoy repository (https://github.com/envoyproxy/envoy) on every upstream commit.

Synchronization is triggered using the `envoy-sync.yaml` workflow.

## Scope

Expand Down Expand Up @@ -61,8 +66,8 @@ The Envoy xDS APIs follow a well defined [versioning scheme](https://www.envoypr

### Deprecated

`V2` control-plane code has been removed and will no longer be supported. For previous conversations on support for various xDS versions, see here:
- [here](https://docs.google.com/document/d/1ZkHpz6DwEUmAlG0kb2Mgu4iaeQC2Bbb0egMbECoNNKY/edit?ts=5e602993#heading=h.15nsmgmjaaml)
phlax marked this conversation as resolved.
Show resolved Hide resolved
`V2` control-plane code has been removed and will no longer be supported. For previous conversations on support for various xDS versions, see here:
- [here](https://docs.google.com/document/d/1ZkHpz6DwEUmAlG0kb2Mgu4iaeQC2Bbb0egMbECoNNKY/edit?ts=5e602993#heading=h.15nsmgmjaaml)
- [here](https://envoyproxy.slack.com/archives/C7LDJTM6Z/p1582925082005300)

*Note*: It is recommended to use a previous SHA if there is still a need for `V2`.
Expand Down
96 changes: 96 additions & 0 deletions ci/sync_envoy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash -eu

set -o pipefail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you add set -o errexit here, it's the same as bash -e, except (IMHO) a bit clearer to the reader.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider set -o nounset, which is also a useful check, though not always what you want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nouunset would not work here if it is checking for an unset var

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you add set -o errexit here, it's the same as bash -e, except (IMHO) a bit clearer to the reader.

thinking on this im not sure - my guess is that you if you surveyed devs more would recognize -e as its just far more common

re nounset - i guess it can probably work if i re/set it from the env


MIRROR_MSG="Mirrored from envoyproxy/envoy"
SRCS=(envoy contrib)
GO_TARGETS=(@envoy_api//...)
IMPORT_BASE="github.com/envoyproxy/go-control-plane"
COMMITTER_NAME="envoy-sync[bot]"
COMMITTER_EMAIL="envoy-sync[bot]@users.noreply.github.com"
ENVOY_SRC_DIR="${ENVOY_SRC_DIR:-}"


if [[ -z "$ENVOY_SRC_DIR" ]]; then
echo "ENVOY_SRC_DIR not set, it should point to a cloned Envoy repo" >&2
exit 1
elif [[ ! -d "$ENVOY_SRC_DIR" ]]; then
echo "ENVOY_SRC_DIR ($ENVOY_SRC_DIR) not found, did you clone it?" >&2
exit 1
fi


build_protos () {
# TODO(phlax): use envoy do_ci target once https://github.com/envoyproxy/envoy/pull/27675 lands
local go_protos go_proto go_file rule_dir proto input_dir output_dir
echo "Building go protos ..."
cd "${ENVOY_SRC_DIR}" || exit 1

# shellcheck disable=SC1091
. ci/setup_cache.sh

read -r -a go_protos <<< "$(bazel query "kind('go_proto_library', ${GO_TARGETS[*]})" | tr '\n' ' ')"
bazel build \
--experimental_proto_descriptor_sets_include_source_info \
"${go_protos[@]}"
rm -rf build_go
mkdir -p build_go
for go_proto in "${go_protos[@]}"; do
# strip @envoy_api//
rule_dir="$(echo "${go_proto:12}" | cut -d: -f1)"
proto="$(echo "${go_proto:12}" | cut -d: -f2)"
input_dir="bazel-bin/external/envoy_api/${rule_dir}/${proto}_/${IMPORT_BASE}/${rule_dir}"
output_dir="build_go/${rule_dir}"
mkdir -p "$output_dir"
while read -r go_file; do
cp -a "$go_file" "$output_dir"
done <<< "$(find "$input_dir" -name "*.go")"
done
cd - || exit 1
}

get_last_envoy_sha () {
git log \
--grep="$MIRROR_MSG" -n 1 \
| grep "$MIRROR_MSG" \
| tail -n 1 \
| sed -e "s#.*$MIRROR_MSG @ ##"
}

sync_protos () {
local src envoy_src
echo "Syncing go protos ..."
for src in "${SRCS[@]}"; do
envoy_src="${ENVOY_SRC_DIR}/build_go/${src}"
rm -rf "$src"
echo "Copying ${envoy_src} -> ${src}"
cp -a "$envoy_src" "$src"
git add "$src"
done
}

commit_changes () {
local last_envoy_sha changes changed
echo "Committing changes ..."
changed="$(git diff HEAD --name-only | grep -v envoy/COMMIT || :)"
if [[ -z "$changed" ]]; then
echo "Nothing changed, not committing"
return
fi
last_envoy_sha="$(get_last_envoy_sha)"
changes="$(git -C "${ENVOY_SRC_DIR}" rev-list "${last_envoy_sha}"..HEAD)"
echo "Changes detected: "
echo "$changes"
latest_commit="$(git -C "${ENVOY_SRC_DIR}" rev-list "${last_envoy_sha}"..HEAD | head -n1)"
echo "$latest_commit" > envoy/COMMIT
git config --global user.email "$COMMITTER_EMAIL"
git config --global user.name "$COMMITTER_NAME"
phlax marked this conversation as resolved.
Show resolved Hide resolved
git add envoy contrib
git commit --allow-empty -s -m "${MIRROR_MSG} @ ${latest_commit}"
git push origin main
}


build_protos
sync_protos
commit_changes