From b47b0d057242a450687ddf9745322e4b25582f7f Mon Sep 17 00:00:00 2001 From: jvoravong Date: Fri, 22 Sep 2023 17:26:12 -0600 Subject: [PATCH] patch --- .../workflows/update_chart_dependencies.yaml | 1 - .../update_instrumentation_dependencies.yaml | 22 ++++++++++-- ci_scripts/chloggen-new.sh | 2 +- ci_scripts/chloggen-pr-validate.sh | 2 +- ci_scripts/chloggen-release.sh | 2 +- ci_scripts/{base_util.sh => common.sh} | 16 +++++++++ ci_scripts/install-tools.sh | 2 +- ci_scripts/update-images-operator-otel.sh | 12 ++++--- ci_scripts/update-images-operator-splunk.sh | 34 ++++++++++++++----- 9 files changed, 73 insertions(+), 20 deletions(-) rename ci_scripts/{base_util.sh => common.sh} (86%) diff --git a/.github/workflows/update_chart_dependencies.yaml b/.github/workflows/update_chart_dependencies.yaml index 7ad854d3fc..4dc9e07b4f 100644 --- a/.github/workflows/update_chart_dependencies.yaml +++ b/.github/workflows/update_chart_dependencies.yaml @@ -81,4 +81,3 @@ jobs: branch: "update-${{ matrix.repo }}-${{ steps.update_chart.outputs.LATEST_VER }}" base: main delete-branch: true - modify-outputs: false diff --git a/.github/workflows/update_instrumentation_dependencies.yaml b/.github/workflows/update_instrumentation_dependencies.yaml index b2f2680529..1223461b58 100644 --- a/.github/workflows/update_instrumentation_dependencies.yaml +++ b/.github/workflows/update_instrumentation_dependencies.yaml @@ -56,7 +56,25 @@ jobs: commit-message: Update ${{ matrix.language }} instrumentation version title: Update ${{ matrix.language }} instrumentation version to ${{ steps.swizzle_version.outputs.TAG_UPSTREAM }} body: Use the new version of the ${{ matrix.language }} instrumentation - branch: "update-${{ matrix.language }}-${{ steps.swizzle_version.outputs.TAG_UPSTREAM }}" + branch: "update-${{ matrix.language }}" base: main delete-branch: true - modify-outputs: false + - name: Add CHANGELOG entry + if: ${{ steps.swizzle_version.outputs.NEED_UPDATE == 1 }} + run: | + git fetch origin + git checkout "update-${{ matrix.language }}" + RESPONSE=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository }}:update-${{ matrix.language }}) + echo "$RESPONSE" + PR_ID=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository }}:update-${{ matrix.language }} \ + | jq '.[0].number') + make chlog-new CHANGE_TYPE=enhancement COMPONENT=operator \ + NOTE="Update ${{ matrix.language }} instrumentation version to ${{ steps.swizzle_version.outputs.TAG_UPSTREAM }}" \ + ISSUES="[$PR_ID]" + git add . + git commit -m "Add .chloggen entry" + git push origin "update-${{ matrix.language }}" diff --git a/ci_scripts/chloggen-new.sh b/ci_scripts/chloggen-new.sh index bf0be1bd3e..769920df85 100755 --- a/ci_scripts/chloggen-new.sh +++ b/ci_scripts/chloggen-new.sh @@ -16,7 +16,7 @@ # Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$SCRIPT_DIR/base_util.sh" +source "$SCRIPT_DIR/common.sh" # ---- Initialize Variables ---- if [[ -z "$FILENAME" ]]; then diff --git a/ci_scripts/chloggen-pr-validate.sh b/ci_scripts/chloggen-pr-validate.sh index 654e5bc5d1..d8980b30d9 100755 --- a/ci_scripts/chloggen-pr-validate.sh +++ b/ci_scripts/chloggen-pr-validate.sh @@ -12,7 +12,7 @@ # Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$SCRIPT_DIR/base_util.sh" +source "$SCRIPT_DIR/common.sh" # ---- Initialize Variables ---- # Get the current branch name diff --git a/ci_scripts/chloggen-release.sh b/ci_scripts/chloggen-release.sh index 7d6af7bde2..4430ad79af 100755 --- a/ci_scripts/chloggen-release.sh +++ b/ci_scripts/chloggen-release.sh @@ -7,7 +7,7 @@ # Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$SCRIPT_DIR/base_util.sh" +source "$SCRIPT_DIR/common.sh" # ---- Initialize Variables ---- # Create a temporary file to hold the updated CHANGELOG.md content diff --git a/ci_scripts/base_util.sh b/ci_scripts/common.sh similarity index 86% rename from ci_scripts/base_util.sh rename to ci_scripts/common.sh index bdc13643a7..14e41350fb 100755 --- a/ci_scripts/base_util.sh +++ b/ci_scripts/common.sh @@ -97,3 +97,19 @@ emit_output() { echo "${var_name}=${var_value}" fi } + +# ---- CI/CD Methods ---- +# Function: setup_git +# Description: Configures git with predefined user name and email. +# Designed to be used in a GitHub workflow environment. +# Usage: setup_git +setup_git() { + # Check if the function is being run in a GitHub workflow environment + if [[ -z "$GITHUB_ACTIONS" ]]; then + debug "Skipping setup git config" + else + git config --global user.name "release-bot" + git config --global user.email "ssg-srv-gh-o11y-gdi@splunk.com" + echo "Successfully setup git config for release-bot" + fi +} diff --git a/ci_scripts/install-tools.sh b/ci_scripts/install-tools.sh index a6150c2649..0f307a8b68 100755 --- a/ci_scripts/install-tools.sh +++ b/ci_scripts/install-tools.sh @@ -10,7 +10,7 @@ # Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$SCRIPT_DIR/base_util.sh" +source "$SCRIPT_DIR/common.sh" # ---- Initialize Variables and Functions ---- # Default to true if running in a GitHub workflow, false otherwise diff --git a/ci_scripts/update-images-operator-otel.sh b/ci_scripts/update-images-operator-otel.sh index 00cc08afc7..770d402f2f 100755 --- a/ci_scripts/update-images-operator-otel.sh +++ b/ci_scripts/update-images-operator-otel.sh @@ -10,7 +10,7 @@ # Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$SCRIPT_DIR/base_util.sh" +source "$SCRIPT_DIR/common.sh" # ---- Initialize Temporary Files ---- # Create a temporary file to hold a subsection of the values.yaml file @@ -76,9 +76,6 @@ while IFS='=' read -r IMAGE_KEY VERSION; do fi done < "${TEMP_VERSIONS}" -# Emit the NEED_UPDATE variable to either GitHub output or stdout -emit_output "NEED_UPDATE" - # Merge the updated subsection back into values.yaml # This approach specifically updates only the subsection between the start and end tokens. # By doing so, we avoid reformatting the entire file, thus preserving the original structure and comments. @@ -87,12 +84,17 @@ awk ' /# Auto-instrumentation Libraries \(Start\)/ {p=1; print $0; next} /# Auto-instrumentation Libraries \(End\)/ {p=0; while((getline line < "'$TEMP_VALUES_FILE'") > 0) printf " %s\n", line; print $0; next} ' "$VALUES_FILE_PATH" > "${VALUES_FILE_PATH}.updated" - # Replace the original values.yaml with the updated version mv "${VALUES_FILE_PATH}.updated" "$VALUES_FILE_PATH" # Cleanup temporary files rm "$TEMP_VALUES_FILE" rm "$TEMP_VERSIONS" + +# Emit the NEED_UPDATE variable to either GitHub output or stdout +emit_output "NEED_UPDATE" +# If in a CI/CD pipeline, setup git config for the bot user +setup_git + echo "Image update process completed successfully!" exit 0 diff --git a/ci_scripts/update-images-operator-splunk.sh b/ci_scripts/update-images-operator-splunk.sh index 6456315cb8..791700c140 100755 --- a/ci_scripts/update-images-operator-splunk.sh +++ b/ci_scripts/update-images-operator-splunk.sh @@ -14,7 +14,7 @@ # Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$SCRIPT_DIR/base_util.sh" +source "$SCRIPT_DIR/common.sh" # ---- Validate Input Arguments ---- # Check for command-line arguments @@ -27,6 +27,8 @@ fi # ---- Initialize Variables ---- # Set the instrumentation library name setd "INST_LIB_NAME" "$1" +# Create a temporary file to hold a subsection of the values.yaml file +setd "TEMP_VALUES_FILE" "$SCRIPT_DIR/temp_values_subsection.yaml" # Set repository-related variables setd "REPO" "ghcr.io/${OWNER}/splunk-otel-${INST_LIB_NAME}/splunk-otel-${INST_LIB_NAME}" @@ -47,19 +49,35 @@ echo "${REPOSITORY_LOCAL} -> Local tag: ${TAG_LOCAL}, Latest tag: $TAG_UPSTREAM" # ---- Update Version Information ---- # If needed, update the tag version in values.yaml -setd "NEED_UPDATE" "${NEED_UPDATE:-0}" # Sets NEED_UPDATE to its current value or 0 if not set if [ "$TAG_UPSTREAM" == "$TAG_LOCAL" ]; then echo "We are already up to date. Nothing else to do." -elif [[ -z "$TAG_LOCAL" || "$TAG_LOCAL" == "null" || "$TAG_LOCAL" != "$TAG_UPSTREAM" ]]; then - echo "We are not up to date. Updating now." - setd "NEED_UPDATE" 1 # Setting NEED_UPDATE to 1 as an update is required - emit_output "TAG_LOCAL" - emit_output "TAG_UPSTREAM" - yq eval -i ".${TAG_LOCAL_PATH} = \"$TAG_UPSTREAM\"" "${VALUES_FILE_PATH}" + exit 0 fi +echo "We are not up to date. Updating now." +setd "NEED_UPDATE" 1 +emit_output "TAG_LOCAL" +emit_output "TAG_UPSTREAM" + +# ---- Extract Subsection for Update ---- +# Extract the content between "# Auto-instrumentation Libraries (Start)" and "# Auto-instrumentation Libraries (End)" +awk '/# Auto-instrumentation Libraries \(Start\)/,/# Auto-instrumentation Libraries \(End\)/' "$VALUES_FILE_PATH" | grep -v "# Auto-instrumentation Libraries " > "$TEMP_VALUES_FILE" + +# ---- Update Image Information ---- +yq eval -i ".${TAG_LOCAL_PATH} = \"$TAG_UPSTREAM\"" "${VALUES_FILE_PATH}" +awk ' + !p && !/# Auto-instrumentation Libraries \(Start\)/ && !/# Auto-instrumentation Libraries \(End\)/ { print $0; next } + /# Auto-instrumentation Libraries \(Start\)/ {p=1; print $0; next} + /# Auto-instrumentation Libraries \(End\)/ {p=0; while((getline line < "'$TEMP_VALUES_FILE'") > 0) printf " %s\n", line; print $0; next} +' "$VALUES_FILE_PATH" > "${VALUES_FILE_PATH}.updated" +# Replace the original values.yaml with the updated version +mv "${VALUES_FILE_PATH}.updated" "$VALUES_FILE_PATH" +# Cleanup temporary files +rm "$TEMP_VALUES_FILE" # Emit the NEED_UPDATE variable to either GitHub output or stdout emit_output "NEED_UPDATE" +# If in a CI/CD pipeline, setup git config for the bot user +setup_git echo "Image update process completed successfully!" exit 0