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

<feat> add versionRange for adaptor; support to customize adapter-mapping; support to install a few adapter #211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
37 changes: 28 additions & 9 deletions .github/workflows/koupleless_runtime_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,42 @@ jobs:
run: |
# 创建一个映射来存储模块名到 JDK 版本的映射
modules=(${{ join(fromJSON(steps.find-maven-modules.outputs.modules-list), ' ') }})
modules_in_right_jdk=""
modules_in_right_jdk_array=()
for module in "${modules[@]}"; do
# 读取模块中的 pom.xml 来确定 JDK 版本
jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
echo "${module} JDK version: ${jdk_version}"
# 如果是目标 jdk 版本,则执行 release 操作


# 如果是目标 jdk 版本,则记录
if [[ "${jdk_version}" == "1.8" ]]; then
modules_in_right_jdk="${modules_in_right_jdk}${module},"
modules_in_right_jdk_array+=(${module})
fi
done
Comment on lines +135 to +145
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance module discovery robustness

The current JDK version extraction logic could be more resilient:

  1. It assumes a specific pom.xml format
  2. Lacks error handling for malformed or missing version tags
  3. No validation of extracted version format

Consider this more robust implementation:

- jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
+ # Extract and validate JDK version
+ if ! jdk_version=$(xmllint --xpath "string(//java.version)" $module/pom.xml 2>/dev/null); then
+   echo "Warning: Could not extract JDK version from $module/pom.xml"
+   continue
+ fi
+ # Validate version format
+ if [[ ! $jdk_version =~ ^1\.[0-9]+$|^[0-9]+(\.[0-9]+)*$ ]]; then
+   echo "Warning: Invalid JDK version format in $module: $jdk_version"
+   continue
+ fi

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 140-140: trailing spaces

(trailing-spaces)


# 过滤出需要发布的 adapter,过滤条件:adapter 版本与 pom.xml 中的版本一致
adapter_release_version=$(grep '<revision>' pom.xml | sed -e 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
modules_in_release_version=""
for module in "${modules_in_right_jdk_array[@]}"; do
# 如果没有 adapter-mapping.yaml,则跳过( koupleless-adapter-configs 没有 adapter-mapping.yaml)
if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
continue
fi

# 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
echo "${module} adapter version: ${adapter_version}"

# 如果是目标 adapter 版本,则记录
if [[ "${adapter_version}" == "${adapter_release_version}" ]]; then
modules_in_release_version="${modules_in_release_version}${module},"
fi
done

if [[ -n ${modules_in_right_jdk} ]]; then
modules_in_right_jdk="${modules_in_right_jdk:0:-1}"
echo "release for module ${modules_in_right_jdk}"
mvn --batch-mode deploy -Prelease -pl ${modules_in_right_jdk} -am -amd -B -U
echo "release completed for module ${modules_in_right_jdk}"
if [[ -n ${modules_in_release_version} ]]; then
modules_in_release_version="${modules_in_release_version:0:-1}"
echo "release for module ${modules_in_release_version}"
mvn --batch-mode deploy -Prelease -pl ${modules_in_release_version} -am -amd -B -U
echo "release completed for module ${modules_in_release_version}"
fi
working-directory: adapter/
env:
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/koupleless_runtime_release_2.1.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
# 创建一个映射来存储模块名到 JDK 版本的映射
modules=(${{ join(fromJSON(steps.find-maven-modules.outputs.modules-list), ' ') }})
modules_in_right_jdk=""
modules_in_right_jdk_array=()
for module in "${modules[@]}"; do
# 读取模块中的 pom.xml 来确定 JDK 版本
jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
Expand All @@ -139,14 +140,34 @@ jobs:

if [[ "${jdk_version}" == "17" ]]; then
modules_in_right_jdk="${modules_in_right_jdk}${module},"
modules_in_right_jdk_array+=(${module})
fi
done

if [[ -n ${modules_in_right_jdk} ]]; then
modules_in_right_jdk="${modules_in_right_jdk:0:-1}"
echo "release for module ${modules_in_right_jdk}"
mvn --batch-mode deploy -Prelease -pl ${modules_in_right_jdk} -am -amd -B -U
echo "release completed for module ${modules_in_right_jdk}"
# 过滤出需要发布的 adapter,过滤条件:adapter 版本与 pom.xml 中的版本一致
adapter_release_version=$(grep '<revision>' pom.xml | sed -e 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
modules_in_release_version=""
for module in "${modules_in_right_jdk_array[@]}"; do
# 如果没有 adapter-mapping.yaml,则跳过(koupleless-adapter-configs 没有 adapter-mapping.yaml)
if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
continue
fi

# 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
echo "${module} adapter version: ${adapter_version}"

# 如果是目标 adapter 版本,则记录
if [[ "${adapter_version}" == "${adapter_release_version}" ]]; then
modules_in_release_version="${modules_in_release_version}${module},"
fi
done
Comment on lines +147 to +164
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve YAML parsing robustness

The current implementation uses grep/sed to parse YAML files, which is fragile and prone to errors. Consider:

  1. Using a proper YAML parser (yq/python-yaml)
  2. Adding error handling for malformed YAML files
  3. Validating the version format before comparison

Example improvement:

# Install yq for proper YAML parsing
if ! command -v yq &> /dev/null; then
    wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
    chmod +x /usr/local/bin/yq
fi

# Parse version using yq
adapter_version=$(yq eval '.version' "$module/conf/adapter-mapping.yaml" || echo "")
if [[ -z "$adapter_version" ]]; then
    echo "Warning: Failed to parse version from $module/conf/adapter-mapping.yaml"
    continue
fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 155-155: trailing spaces

(trailing-spaces)


[error] 159-159: trailing spaces

(trailing-spaces)


if [[ -n ${modules_in_release_version} ]]; then
modules_in_release_version="${modules_in_release_version:0:-1}"
echo "release for module ${modules_in_release_version}"
mvn --batch-mode deploy -Prelease -pl ${modules_in_release_version} -am -amd -B -U
echo "release completed for module ${modules_in_release_version}"
fi
working-directory: adapter/
env:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/koupleless_runtime_release_adaptor_configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Koupleless Runtime Release

## https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
## trigger manually
on:
workflow_dispatch:

jobs:
release_for_jdk8:
# needs: build_and_test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: checkout adapter repo
uses: actions/checkout@v3
with:
repository: 'koupleless/adapter'
path: 'adapter'

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update checkout action version for adapter repository.

Update the checkout action to the latest version:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uses: actions/checkout@v3
with:
repository: 'koupleless/adapter'
path: 'adapter'
uses: actions/checkout@v4
with:
repository: 'koupleless/adapter'
path: 'adapter'
🧰 Tools
🪛 actionlint (1.7.4)

29-29: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

- name: release adapter for jdk8
run: |
# 请在发布 koupleless-adapter-configs 之前,发布 jdk8 和 jdk17 所有的 koupleless-adapters
mvn --batch-mode deploy -Prelease -pl koupleless-adapter-configs -am -amd -B -U
working-directory: adapter/
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
37 changes: 28 additions & 9 deletions .github/workflows/koupleless_runtime_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,42 @@ jobs:
run: |
# 创建一个映射来存储模块名到 JDK 版本的映射
modules=(${{ join(fromJSON(steps.find-maven-modules.outputs.modules-list), ' ') }})
modules_in_right_jdk=""
modules_in_right_jdk_array=()
for module in "${modules[@]}"; do
# 读取模块中的 pom.xml 来确定 JDK 版本
jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
echo "${module} JDK version: ${jdk_version}"
# 如果是目标 jdk 版本,则执行 release 操作


# 如果是目标 jdk 版本,则记录
if [[ "${jdk_version}" == "1.8" ]]; then
modules_in_right_jdk="${modules_in_right_jdk}${module},"
modules_in_right_jdk_array+=(${module})
fi
done
Comment on lines +134 to +144
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for module version detection

The current implementation might fail silently if:

  • The java.version tag is missing in pom.xml
  • The version format is unexpected
  • The pom.xml file is malformed

Consider adding these improvements:

 modules_in_right_jdk_array=()
 for module in "${modules[@]}"; do
-  jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
+  if [[ ! -f "$module/pom.xml" ]]; then
+    echo "Warning: pom.xml not found in $module"
+    continue
+  fi
+  
+  jdk_version=$(grep -m 1 '<java.version>' "$module/pom.xml" | sed 's/<[^>]*>//g' | xargs)
+  if [[ -z "$jdk_version" ]]; then
+    echo "Warning: java.version not found in $module/pom.xml"
+    continue
+  fi
+
+  # Validate version format
+  if [[ ! "$jdk_version" =~ ^[0-9]+\.[0-9]+$ ]]; then
+    echo "Warning: Invalid java.version format in $module/pom.xml: $jdk_version"
+    continue
+  fi
   
   echo "${module} JDK version: ${jdk_version}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
modules_in_right_jdk_array=()
for module in "${modules[@]}"; do
# 读取模块中的 pom.xml 来确定 JDK 版本
jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
echo "${module} JDK version: ${jdk_version}"
# 如果是目标 jdk 版本,则执行 release 操作
# 如果是目标 jdk 版本,则记录
if [[ "${jdk_version}" == "1.8" ]]; then
modules_in_right_jdk="${modules_in_right_jdk}${module},"
modules_in_right_jdk_array+=(${module})
fi
done
modules_in_right_jdk_array=()
for module in "${modules[@]}"; do
if [[ ! -f "$module/pom.xml" ]]; then
echo "Warning: pom.xml not found in $module"
continue
fi
jdk_version=$(grep -m 1 '<java.version>' "$module/pom.xml" | sed 's/<[^>]*>//g' | xargs)
if [[ -z "$jdk_version" ]]; then
echo "Warning: java.version not found in $module/pom.xml"
continue
fi
# Validate version format
if [[ ! "$jdk_version" =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "Warning: Invalid java.version format in $module/pom.xml: $jdk_version"
continue
fi
echo "${module} JDK version: ${jdk_version}"
# 如果是目标 jdk 版本,则记录
if [[ "${jdk_version}" == "1.8" ]]; then
modules_in_right_jdk_array+=(${module})
fi
done


# 过滤出需要发布的 adapter,过滤条件:adapter 版本与 pom.xml 中的版本一致
adapter_snapshot_version=$(grep '<revision>' pom.xml | sed -e 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
modules_in_snapshot_version=""
for module in "${modules_in_right_jdk_array[@]}"; do
# 如果没有 adapter-mapping.yaml,则跳过( koupleless-adapter-configs 没有 adapter-mapping.yaml)
if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
continue
fi

# 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
echo "${module} adapter version: ${adapter_version}"

# 如果是目标 adapter 版本,则记录
if [[ "${adapter_version}" == "${adapter_snapshot_version}" ]]; then
modules_in_snapshot_version="${modules_in_snapshot_version}${module},"
fi
done

Comment on lines +146 to 164
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve version extraction and validation logic

The current version extraction logic has several potential issues:

  1. The grep commands for version extraction are fragile
  2. No validation of extracted versions
  3. Trailing spaces in the code

Consider these improvements:

-adapter_snapshot_version=$(grep '<revision>' pom.xml | sed -e 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
+adapter_snapshot_version=$(xmllint --xpath "string(//revision)" pom.xml 2>/dev/null)
+if [[ -z "$adapter_snapshot_version" ]]; then
+  echo "Error: Failed to extract snapshot version from pom.xml"
+  exit 1
+fi

 modules_in_snapshot_version=""
 for module in "${modules_in_right_jdk_array[@]}"; do
   if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
     continue
   fi
 
-  adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
+  # Use yq for YAML parsing if available
+  if command -v yq >/dev/null 2>&1; then
+    adapter_version=$(yq eval '.version' "$module/conf/adapter-mapping.yaml")
+  else
+    adapter_version=$(grep 'version:' "$module/conf/adapter-mapping.yaml" | sed -e 's/.*version:\s*\(.*\)/\1/' | tr -d ' ')
+  fi
+
+  if [[ -z "$adapter_version" ]]; then
+    echo "Warning: Failed to extract adapter version from $module/conf/adapter-mapping.yaml"
+    continue
+  fi

Remove trailing spaces from lines 154, 158, and 164.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# 过滤出需要发布的 adapter,过滤条件:adapter 版本与 pom.xml 中的版本一致
adapter_snapshot_version=$(grep '<revision>' pom.xml | sed -e 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
modules_in_snapshot_version=""
for module in "${modules_in_right_jdk_array[@]}"; do
# 如果没有 adapter-mapping.yaml,则跳过( koupleless-adapter-configs 没有 adapter-mapping.yaml)
if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
continue
fi
# 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
echo "${module} adapter version: ${adapter_version}"
# 如果是目标 adapter 版本,则记录
if [[ "${adapter_version}" == "${adapter_snapshot_version}" ]]; then
modules_in_snapshot_version="${modules_in_snapshot_version}${module},"
fi
done
# 过滤出需要发布的 adapter,过滤条件:adapter 版本与 pom.xml 中的版本一致
adapter_snapshot_version=$(xmllint --xpath "string(//revision)" pom.xml 2>/dev/null)
if [[ -z "$adapter_snapshot_version" ]]; then
echo "Error: Failed to extract snapshot version from pom.xml"
exit 1
fi
modules_in_snapshot_version=""
for module in "${modules_in_right_jdk_array[@]}"; do
# 如果没有 adapter-mapping.yaml,则跳过( koupleless-adapter-configs 没有 adapter-mapping.yaml)
if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
continue
fi
# 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
# Use yq for YAML parsing if available
if command -v yq >/dev/null 2>&1; then
adapter_version=$(yq eval '.version' "$module/conf/adapter-mapping.yaml")
else
adapter_version=$(grep 'version:' "$module/conf/adapter-mapping.yaml" | sed -e 's/.*version:\s*\(.*\)/\1/' | tr -d ' ')
fi
if [[ -z "$adapter_version" ]]; then
echo "Warning: Failed to extract adapter version from $module/conf/adapter-mapping.yaml"
continue
fi
echo "${module} adapter version: ${adapter_version}"
# 如果是目标 adapter 版本,则记录
if [[ "${adapter_version}" == "${adapter_snapshot_version}" ]]; then
modules_in_snapshot_version="${modules_in_snapshot_version}${module},"
fi
done
🧰 Tools
🪛 yamllint (1.35.1)

[error] 154-154: trailing spaces

(trailing-spaces)


[error] 158-158: trailing spaces

(trailing-spaces)


[error] 164-164: trailing spaces

(trailing-spaces)

if [[ -n ${modules_in_right_jdk} ]]; then
modules_in_right_jdk="${modules_in_right_jdk:0:-1}"
echo "release for module ${modules_in_right_jdk}"
mvn --batch-mode deploy -Psnapshot -pl ${modules_in_right_jdk} -am -amd -B -U
echo "release completed for module ${modules_in_right_jdk}"
if [[ -n ${modules_in_snapshot_version} ]]; then
modules_in_snapshot_version="${modules_in_snapshot_version:0:-1}"
echo "release for module ${modules_in_snapshot_version}"
mvn --batch-mode deploy -Psnapshot -pl ${modules_in_snapshot_version} -am -amd -B -U
echo "release completed for module ${modules_in_snapshot_version}"
fi
working-directory: adapter/
env:
Expand Down
35 changes: 27 additions & 8 deletions .github/workflows/koupleless_runtime_snapshot_2.1.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,42 @@ jobs:
run: |
# 创建一个映射来存储模块名到 JDK 版本的映射
modules=(${{ join(fromJSON(steps.find-maven-modules.outputs.modules-list), ' ') }})
modules_in_right_jdk=""
modules_in_right_jdk_array=()
for module in "${modules[@]}"; do
# 读取模块中的 pom.xml 来确定 JDK 版本
jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
echo "${module} JDK version: ${jdk_version}"
# 如果是目标 jdk 版本,则执行 release 操作

# 如果是目标 jdk 版本,则记录
if [[ "${jdk_version}" == "17" ]]; then
modules_in_right_jdk="${modules_in_right_jdk}${module},"
modules_in_right_jdk_array+=(${module})
fi
done

Comment on lines +130 to 141
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve JDK version extraction robustness

The current JDK version extraction using grep could match partial versions or commented-out configurations. Consider using a more precise XML parsing approach.

Here's a more robust implementation:

-jdk_version=$(grep -m 1 '<java.version>' $module/pom.xml | sed 's/<[^>]*>//g' | xargs)
+jdk_version=$(xmllint --xpath "string(//*[local-name()='java.version']/text())" $module/pom.xml 2>/dev/null || echo "")

Also, consider adding error handling for missing or malformed pom.xml files.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 141-141: trailing spaces

(trailing-spaces)

if [[ -n ${modules_in_right_jdk} ]]; then
modules_in_right_jdk="${modules_in_right_jdk:0:-1}"
echo "release for module ${modules_in_right_jdk}"
mvn --batch-mode deploy -Psnapshot -pl ${modules_in_right_jdk} -am -amd -B -U
echo "release completed for module ${modules_in_right_jdk}"
# 过滤出需要发布的 adapter,过滤条件:adapter 版本与 pom.xml 中的版本一致
adapter_snapshot_version=$(grep '<revision>' pom.xml | sed -e 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
modules_in_snapshot_version=""
for module in "${modules_in_right_jdk_array[@]}"; do
# 如果没有 adapter-mapping.yaml,则跳过( koupleless-adapter-configs 没有 adapter-mapping.yaml)
if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
continue
fi

# 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
echo "${module} adapter version: ${adapter_version}"

# 如果是目标 adapter 版本,则记录
if [[ "${adapter_version}" == "${adapter_snapshot_version}" ]]; then
modules_in_snapshot_version="${modules_in_snapshot_version}${module},"
fi
done

if [[ -n ${modules_in_snapshot_version} ]]; then
modules_in_snapshot_version="${modules_in_snapshot_version:0:-1}"
echo "release for module ${modules_in_snapshot_version}"
mvn --batch-mode deploy -Psnapshot -pl ${modules_in_snapshot_version} -am -amd -B -U
echo "release completed for module ${modules_in_snapshot_version}"
Comment on lines +142 to +165
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve version matching and module selection logic

Several improvements are needed in this section:

  1. The string concatenation approach for modules_in_snapshot_version is error-prone
  2. Missing validation for adapter version format
  3. No error handling for missing or invalid YAML files
  4. Contains unnecessary trailing spaces

Here's a suggested improvement:

-modules_in_snapshot_version=""
+declare -a modules_to_release
 
 for module in "${modules_in_right_jdk_array[@]}"; do
-  # 如果没有 adapter-mapping.yaml,则跳过( koupleless-adapter-configs 没有 adapter-mapping.yaml)
-  if [[ ! -f $module/conf/adapter-mapping.yaml ]]; then
+  yaml_file="$module/conf/adapter-mapping.yaml"
+  if [[ ! -f "$yaml_file" ]]; then
+    echo "Warning: $yaml_file not found, skipping module"
     continue
   fi
 
-  # 读取模块中的 adapter-mapping.yaml 来确定 adapter 版本
-  adapter_version=$(grep 'version:' $module/conf/adapter-mapping.yaml | sed -e 's/.*version:\(.*\)/\1/' | tr -d ' ')
+  # Use yq for proper YAML parsing
+  if ! adapter_version=$(yq e '.version' "$yaml_file" 2>/dev/null); then
+    echo "Error: Failed to parse version from $yaml_file"
+    continue
+  fi
+
+  # Validate version format
+  if [[ ! $adapter_version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?$ ]]; then
+    echo "Error: Invalid version format in $yaml_file: $adapter_version"
+    continue
+  fi
 
   if [[ "${adapter_version}" == "${adapter_snapshot_version}" ]]; then
-    modules_in_snapshot_version="${modules_in_snapshot_version}${module},"
+    modules_to_release+=("$module")
   fi
 done
 
-if [[ -n ${modules_in_snapshot_version} ]]; then
-  modules_in_snapshot_version="${modules_in_snapshot_version:0:-1}"
-  echo "release for module ${modules_in_snapshot_version}"
-  mvn --batch-mode deploy -Psnapshot -pl ${modules_in_snapshot_version} -am -amd -B -U
+if (( ${#modules_to_release[@]} > 0 )); then
+  modules_list=$(IFS=,; echo "${modules_to_release[*]}")
+  echo "Releasing modules: ${modules_list}"
+  mvn --batch-mode deploy -Psnapshot -pl "${modules_list}" -am -amd -B -U

This improvement:

  • Uses an array instead of string concatenation
  • Adds proper YAML parsing with yq
  • Validates version format
  • Improves error handling and logging
  • Fixes trailing spaces

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 150-150: trailing spaces

(trailing-spaces)


[error] 154-154: trailing spaces

(trailing-spaces)


[error] 160-160: trailing spaces

(trailing-spaces)

fi
working-directory: adapter/
env:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/koupleless_runtime_snapshot_adaptor_configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Koupleless Runtime Release

## https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
## trigger manually
on:
workflow_dispatch:

jobs:
release_for_jdk8:
# needs: build_and_test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: checkout adapter repo
uses: actions/checkout@v3
with:
repository: 'koupleless/adapter'
path: 'adapter'

- name: release adapter for jdk8
run: |
# 请在发布 koupleless-adapter-configs 之前,发布 jdk8 和 jdk17 所有的 koupleless-adapters
mvn --batch-mode deploy -Psnapshot -pl koupleless-adapter-configs -am -amd -B -U
working-directory: adapter/
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@


<dependencies>

<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>1.9.18</version>
</dependency>
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update maven-resolver-util to latest version 2.0.4

The current version 1.9.18 is outdated. Maven Central shows version 2.0.4 is available. Since this project uses modern Maven dependencies (maven-core 3.9.6), it's recommended to use the latest version for better compatibility and security.

  • Update maven-resolver-util version from 1.9.18 to 2.0.4 in koupleless-base-build-plugin/pom.xml
🔗 Analysis chain

Verify maven-resolver-util version selection

The addition of this dependency aligns well with the PR objective of adding version range support. Let's verify the version choice.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check latest version and compatibility of maven-resolver-util

# Check latest version on Maven Central
curl -s "https://search.maven.org/solrsearch/select?q=g:org.apache.maven.resolver+AND+a:maven-resolver-util&rows=1&wt=json" | jq -r '.response.docs[0].latestVersion'

# Check compatibility with existing Maven dependencies
rg -A 1 "maven-core|maven-aether-provider" pom.xml

Length of output: 426


<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down Expand Up @@ -60,10 +67,12 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand Down
Loading