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

chore(CI): add pipeline to check sidecar version against OpenAPI spec and client code versions #1062

Merged
merged 24 commits into from
Feb 21, 2025
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
4 changes: 4 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@ promotions:
pipeline_file: third-party-notices.yml
auto_promote:
when: "branch =~ '.*' and change_in(['/package.json', '/NOTICE.txt', '/scripts/notices/NOTICE-vsix_PREAMBLE.txt'], {default_branch: 'main', branch_range: '$SEMAPHORE_GIT_COMMIT_RANGE', pipeline_file: 'ignore'})"
- name: Validate Sidecar Version
pipeline_file: validate-sidecar-version.yml
auto_promote:
when: "result = 'passed' and change_in(['.versions/ide-sidecar.txt', 'src/clients/sidecar-openapi-specs/sidecar.openapi.yaml'])"
Copy link
Preview

Copilot AI Feb 21, 2025

Choose a reason for hiding this comment

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

The auto_promote condition references 'src/clients/sidecar-openapi-specs/sidecar.openapi.yaml' for the OpenAPI spec version check, but the PR description mentions validating the client code version in 'src/clients/sidecar/runtime.ts'. Please verify that the correct file is monitored for changes.

Suggested change
when: "result = 'passed' and change_in(['.versions/ide-sidecar.txt', 'src/clients/sidecar-openapi-specs/sidecar.openapi.yaml'])"
when: "result = 'passed' and change_in(['.versions/ide-sidecar.txt', 'src/clients/sidecar/runtime.ts'])"

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor Author

@shouples shouples Feb 21, 2025

Choose a reason for hiding this comment

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

We care more about changes to sidecar.openapi.yaml, which should be followed up by gulp apigen (which then changes clients/**/runtime.ts files). No need to explicitly check for any changes to runtime.ts here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good bot, try again next time.

25 changes: 25 additions & 0 deletions .semaphore/validate-sidecar-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: v1.0
name: validate-sidecar-version
agent:
machine:
type: s1-prod-ubuntu24-04-amd64-1

auto_cancel:
running:
when: "branch != 'main'"

execution_time_limit:
hours: 1

queue:
- when: "branch != 'main'"
processing: parallel

blocks:
- name: "Validate Versions"
task:
jobs:
- name: "Compare ide-sidecar.txt version against OpenAPI spec version"
commands:
- checkout
- make check-sidecar-versions
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ validate-bump:
.PHONY: bump-microversion
bump-microversion:
export VERSION_OVERRIDE=$(shell cat ./.versions/next.txt) ;\
export VERSION_POST=$(MICROVERSION_POST) ;\
export BUMP=none ;\
export SKIP_TAG_RELEASE=true ;\
$(MAKE) release-ci
export VERSION_POST=$(MICROVERSION_POST) ;\
export BUMP=none ;\
export SKIP_TAG_RELEASE=true ;\
$(MAKE) release-ci

.PHONY: release-current-version
release-current-version:
Expand Down Expand Up @@ -112,3 +112,9 @@ update-third-party-notices-pr:
.PHONY: collect-notices-vsix
collect-notices-vsix:
@./scripts/notices/collect-notices-vsix.sh

# Captures the output of the version check, strips away any ANSI escape codes, and posts a comment
# to the PR if the version check fails.
.PHONY: check-sidecar-versions
check-sidecar-versions:
@./scripts/check-sidecar-versions.sh
91 changes: 91 additions & 0 deletions scripts/check-sidecar-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
set -e

# Extract version from ide-sidecar.txt (removing 'v' prefix and whitespace)
SIDECAR_VERSION_PATH=.versions/ide-sidecar.txt
SIDECAR_VERSION=$(cat "${SIDECAR_VERSION_PATH}" | sed 's/^v//' | tr -d '[:space:]')

# Extract version from OpenAPI spec
OPENAPI_SPEC_PATH=src/clients/sidecar-openapi-specs/sidecar.openapi.yaml
OPENAPI_SPEC_VERSION=$(yq '.info.version' "${OPENAPI_SPEC_PATH}")

# Extract version from client code
CLIENT_CODE_PATH=src/clients/sidecar/runtime.ts
CLIENT_VERSION=$(grep -o "version of the OpenAPI document: [0-9.]*" "${CLIENT_CODE_PATH}" | cut -d' ' -f6)

# ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
GRAY='\033[0;90m'
NC='\033[0m'

# Enable color output
export TERM=xterm-color

# Markdown links for GH PR comment
GH_PR_PATH_PREFIX=https://github.com/confluentinc/vscode/blob/${SEMAPHORE_GIT_PR_SHA}
IDE_SIDECAR_LINK="[ide-sidecar.txt](${GH_PR_PATH_PREFIX}/${SIDECAR_VERSION_PATH})"
OPENAPI_SPEC_LINK="[sidecar.openapi.yaml](${GH_PR_PATH_PREFIX}/${OPENAPI_SPEC_PATH})"
CLIENT_CODE_LINK="[runtime.ts](${GH_PR_PATH_PREFIX}/${CLIENT_CODE_PATH})"

# Message templates
PR_COMMENT_HEADER="### Sidecar Version Check Failed (https://github.com/confluentinc/vscode/commit/${SEMAPHORE_GIT_PR_SHA})"
OPENAPI_MISMATCH_MSG="Make sure to copy https://github.com/confluentinc/ide-sidecar/blob/v${SIDECAR_VERSION}/src/generated/resources/openapi.yaml to ${OPENAPI_SPEC_LINK}"
CLIENT_MISMATCH_MSG="Make sure to run \`gulp apigen\` to regenerate sidecar client code"

# Compare versions: sidecar vs OpenAPI spec vs client code
if [ "$SIDECAR_VERSION" != "$OPENAPI_SPEC_VERSION" ]; then
# Show colored output in terminal
printf "❌ ${RED}OpenAPI spec version mismatch!${NC}\n\n"
printf "Make sure to copy ${GRAY}%s${NC} to ${BLUE}%s${NC}.\n\n" \
"https://github.com/confluentinc/ide-sidecar/blob/v${SIDECAR_VERSION}/src/generated/resources/openapi.yaml" \
"$OPENAPI_SPEC_PATH"
printf "${GRAY}%s${NC}: ${GREEN}%s${NC}\n" "$SIDECAR_VERSION_PATH" "$SIDECAR_VERSION"
printf "${GRAY}%s${NC}: ${RED}%s${NC}\n" "$OPENAPI_SPEC_PATH" "$OPENAPI_SPEC_VERSION"

# Post GitHub comment if in CI
if [ "$CI" = "true" ] && [ -n "$SEMAPHORE_GIT_PR_NUMBER" ]; then
echo "Version check failed. Posting comment to PR #$SEMAPHORE_GIT_PR_NUMBER"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/confluentinc/vscode/issues/$SEMAPHORE_GIT_PR_NUMBER/comments" \
-f body="${PR_COMMENT_HEADER}

OpenAPI spec version mismatch:
- ${IDE_SIDECAR_LINK}: \`${SIDECAR_VERSION}\` :white_check_mark:
- ${OPENAPI_SPEC_LINK}: \`${OPENAPI_SPEC_VERSION}\` :x:

${OPENAPI_MISMATCH_MSG}"
fi
exit 1

elif [ "$OPENAPI_SPEC_VERSION" != "$CLIENT_VERSION" ]; then
# Show colored output in terminal
printf "❌ ${RED}Client code version mismatch!${NC}\n\n"
printf "Make sure to run '${BLUE}gulp apigen${NC}' to regenerate sidecar client code.\n\n"
printf "${GRAY}%s${NC}: ${GREEN}%s${NC}\n" "$SIDECAR_VERSION_PATH" "$SIDECAR_VERSION"
printf "${GRAY}%s${NC}: ${GREEN}%s${NC}\n" "$OPENAPI_SPEC_PATH" "$OPENAPI_SPEC_VERSION"
printf "${GRAY}%s${NC}: ${RED}%s${NC}\n" "$CLIENT_CODE_PATH" "$CLIENT_VERSION"

# Post GitHub comment if in CI
if [ "$CI" = "true" ] && [ -n "$SEMAPHORE_GIT_PR_NUMBER" ]; then
echo "Version check failed. Posting comment to PR #$SEMAPHORE_GIT_PR_NUMBER"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/confluentinc/vscode/issues/$SEMAPHORE_GIT_PR_NUMBER/comments" \
-f body="${PR_COMMENT_HEADER}

Client code version mismatch:
- ${IDE_SIDECAR_LINK}: \`${SIDECAR_VERSION}\` :white_check_mark:
- ${OPENAPI_SPEC_LINK}: \`${OPENAPI_SPEC_VERSION}\` :white_check_mark:
- ${CLIENT_CODE_LINK}: \`${CLIENT_VERSION}\` :x:

${CLIENT_MISMATCH_MSG}"
fi
exit 1
fi

printf "✅ All versions match: ${GREEN}%s${NC}\n" "$SIDECAR_VERSION"