Merge pull request #113 from wxbty/master

add workflow conf for  benchmark
diff --git a/.github/workflows/trigger-sample-benchmark.yml b/.github/workflows/trigger-sample-benchmark.yml
new file mode 100644
index 0000000..180322a
--- /dev/null
+++ b/.github/workflows/trigger-sample-benchmark.yml
@@ -0,0 +1,230 @@
+name: Manually Triggered benchmark for Dubbo Samples
+
+on:
+  repository_dispatch:
+    types: [ manual-trigger ]
+
+permissions:
+  contents: read
+
+env:
+  FORK_COUNT: 0
+  FAIL_FAST: 1
+  SHOW_ERROR_DETAIL: 1
+  #multi-version size limit
+  VERSIONS_LIMIT: 1
+  CANDIDATE_VERSIONS: '
+    spring.version:5.3.24;
+    spring-boot.version:2.7.6;
+    '
+
+jobs:
+  check-benchmark-path:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          repository: 'apache/dubbo-samples'
+          ref: master
+      - name: Check if directory exists
+        run: |
+          #!/bin/bash
+          cd test
+          PATH_TO_CHECK="../10-task/dubbo-samples-benchmark/"
+          if [ ! -d "$PATH_TO_CHECK" ]; then
+            exit 1
+          fi
+
+  build-source:
+    name: "Build Dubbo"
+    needs: check-benchmark-path
+    runs-on: ubuntu-latest
+    outputs:
+      version: ${{ steps.dubbo-version.outputs.version }}
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          repository: 'apache/dubbo'
+          ref: 3.3
+      - name: "Dubbo cache"
+        id: dubbo-cache
+        uses: actions/cache@v4
+        with:
+          path: ~/.m2/repository/org/apache/dubbo
+          key: ${{ runner.os }}-dubbo-snapshot-${{ github.sha }}
+      - name: "Cache local Maven repository"
+        if: steps.dubbo-cache.outputs.cache-hit != 'true'
+        uses: actions/cache@v4
+        with:
+          path: ~/.m2/repository
+          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+          restore-keys: |
+            ${{ runner.os }}-maven-
+      - name: "Set up JDK 17"
+        if: steps.dubbo-cache.outputs.cache-hit != 'true'
+        uses: actions/setup-java@v4
+        with:
+          distribution: 'zulu'
+          java-version: 17
+      - name: "Build Dubbo with Maven"
+        if: steps.dubbo-cache.outputs.cache-hit != 'true'
+        run: |
+          ./mvnw --batch-mode --no-snapshot-updates --no-transfer-progress  clean install -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
+      - name: "Calculate Dubbo Version"
+        id: dubbo-version
+        run: |
+          REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' pom.xml`
+          echo "version=$REVISION" >> $GITHUB_OUTPUT
+          echo "dubbo version: $REVISION"
+          echo "commit_id: ${{ github.sha }}"
+
+  samples-test-job:
+    needs: [ build-source ]
+    name: "Samples benchmark test on ubuntu-latest"
+    runs-on: ubuntu-latest
+    timeout-minutes: 90
+    env:
+      JAVA_VER: 8
+    strategy:
+      matrix:
+        job_id: [ 1 ]
+      fail-fast: false
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          repository: 'apache/dubbo-samples'
+          ref: master
+      - name: "Cache local Maven repository"
+        uses: actions/cache@v4
+        with:
+          path: ~/.m2/repository
+          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+          restore-keys: |
+            ${{ runner.os }}-maven-
+      - name: "Restore Dubbo cache"
+        uses: actions/cache@v4
+        with:
+          path: ~/.m2/repository/org/apache/dubbo
+          key: ${{ runner.os }}-dubbo-snapshot-${{ github.sha }}
+      - name: "Cache Skywalking Agent"
+        id: cache-skywalking-agent
+        uses: actions/cache@v4
+        with:
+          path: /tmp/skywalking-agent
+          key: ${{ runner.os }}-skywalking-agent-9.0.0
+      - name: "Cache MySQL Driver"
+        id: cache-mysql-driver
+        uses: actions/cache@v4
+        with:
+          path: /tmp/mysql-connector-java-8.0.23.jar
+          key: ${{ runner.os }}-mysql-driver-8.0.23
+      - name: "Download Skywalking Agent and MySQL Driver"
+        if: steps.cache-skywalking-agent.outputs.cache-hit != 'true' || steps.cache-mysql-driver.outputs.cache-hit != 'true'
+        run: |
+          wget -c https://archive.apache.org/dist/skywalking/java-agent/9.0.0/apache-skywalking-java-agent-9.0.0.tgz --no-check-certificate
+          tar -zxvf apache-skywalking-java-agent-9.0.0.tgz -C /tmp
+          wget -c https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.23/mysql-connector-java-8.0.23.jar
+          mv mysql-connector-java-8.0.23.jar /tmp/
+      - name: "Mvn Benchmark Skywalking Plugin"
+        run: |
+          rm /tmp/skywalking-agent/plugins/*
+          cd 10-task/dubbo-samples-benchmark/dubbo-samples-benchmark-agent && mvn --batch-mode --no-snapshot-updates -e --no-transfer-progress clean package -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
+          cp -f ./target/dubbo-samples-benchmark-agent.jar /tmp/skywalking-agent/plugins/
+      - name: "Set up JDK 8"
+        uses: actions/setup-java@v4
+        with:
+          distribution: 'zulu'
+          java-version: 8
+      - name: "Init Candidate Versions"
+        run: |
+          DUBBO_VERSION="${{needs.build-source.outputs.version}}"
+          CANDIDATE_VERSIONS="dubbo.version:$DUBBO_VERSION;compiler.version:$DUBBO_VERSION;$CANDIDATE_VERSIONS;dubbo.benchmark:1.0.0;dubbo.compiler.version:$DUBBO_VERSION"
+          echo "CANDIDATE_VERSIONS=$CANDIDATE_VERSIONS" >> $GITHUB_ENV
+      - name: "Replace runtime parameter"
+        run: |
+          RUNTIME_CONFIG_PATH=./10-task/dubbo-samples-benchmark/case-runtime-parameter.conf
+          rm -rf $RUNTIME_CONFIG_PATH
+          runtime_para_pairs="${{ github.event.client_payload.prop}}"
+          IFS='@' read -ra groups <<< "$runtime_para_pairs"
+          for group in "${groups[@]}"; do
+            IFS='|' read -ra prop_array <<< "$group"
+            config_line=""
+            for ((i=0; i<${#prop_array[@]}; i+=2)); do
+              config_line+="-D${prop_array[i]}=${prop_array[i+1]} "
+            done
+            echo "${config_line% }" >> "$RUNTIME_CONFIG_PATH"
+          done
+      - name: "Build test image"
+        run: |
+          cd test && bash ./build-test-image.sh
+      - name: "Run tests"
+        run: cd test && bash ./run-tests.sh ../10-task/dubbo-samples-benchmark/
+      - name: "Upload docker log"
+        uses: actions/upload-artifact@v4
+        with:
+          name: samples-docker-log
+          path: |
+            ./10-task/dubbo-samples-benchmark/target/logs/*.log
+            /tmp/skywalking-agent/logs/*.log
+      - name: "Upload jmh output result"
+        uses: actions/upload-artifact@v4
+        with:
+          name: samples-jmh-result
+          path: /tmp/jmh*.json
+      - name: "Push results to results repository"
+        run: |
+          RESULTS_REPO_OWNER="${{ github.event.client_payload.PUSH_NAME}}"
+          RESULTS_REPO_BRANCH="${{ github.event.client_payload.RESULTS_REPO_BRANCH}}"
+          RESULTS_REPO_NAME="${{ github.event.client_payload.REPO_NAME}}"
+          GITHUB_TOKEN="${{ github.event.client_payload.PUSH_TOKEN}}"
+          
+          if ! ls /tmp/jmh_result_prop*.json -1q &> /dev/null; then
+            echo "No file matching /tmp/jmh_result_prop*.json exists. Exiting..."
+            exit 0
+          fi
+
+          git clone --depth 1 --branch ${RESULTS_REPO_BRANCH} https://github.com/${RESULTS_REPO_OWNER}/${RESULTS_REPO_NAME}.git jmh_result
+          cd jmh_result
+          git config user.name 'github-actions[bot]'
+          git config user.email 'github-actions[bot]@users.noreply.github.com'
+
+          WORK_DIR="$(pwd)"
+          echo "WorkDir: $WORK_DIR"
+
+          DIRECTORY_PATH="$WORK_DIR/test-results/scenario"
+          if [ ! -d ${DIRECTORY_PATH} ];then
+            mkdir -p $DIRECTORY_PATH;else
+            rm $DIRECTORY_PATH/*
+          fi
+
+          cp /tmp/jmh_result*.json "$DIRECTORY_PATH"
+          cp /tmp/jmh_trace*.json "$DIRECTORY_PATH"
+
+          merged_file="merged_prop_results.json"
+          merged_trace_file="merged_prop_traces.json"
+
+          json_array=()
+          for file in $(ls -t1 "$DIRECTORY_PATH"/jmh_result*.json); do
+           if [ -f "$file" ]; then
+              echo "fileName=$file"
+              json_array+=( "$(cat "$file")" )
+           fi
+          done
+
+          merged_json=$(echo "${json_array[@]}" | jq -s add)
+          echo "$merged_json" > "$DIRECTORY_PATH/$merged_file"
+
+          json_array=()
+          for file in $(ls -t1 "$DIRECTORY_PATH"/jmh_trace*.json); do
+           if [ -f "$file" ]; then
+              json_array+=( "$(cat "$file")" )
+           fi
+          done
+
+          merged_json=$(echo "${json_array[@]}" | jq -s add)
+          echo "$merged_json" > "$DIRECTORY_PATH/$merged_trace_file"
+
+          git add $DIRECTORY_PATH
+          git commit -m "Compare prop in $(date +'%Y-%m-%d %H:%M:%S')"
+          git pull --rebase
+          git push https://${GITHUB_TOKEN}@github.com/${RESULTS_REPO_OWNER}/${RESULTS_REPO_NAME}.git ${RESULTS_REPO_BRANCH}