From a609a0181e84fc66bf9070c185fba01a505ca1c5 Mon Sep 17 00:00:00 2001 From: Charalampos Mainas Date: Fri, 8 May 2026 15:19:10 +0300 Subject: [PATCH 1/3] Hopefully final check PR: https://github.com/urunc-dev/urunc_test/pull/58 Signed-off-by: Charalampos Mainas Reviewed-by: Panagiotis Mavrikos Approved-by: Panagiotis Mavrikos --- .github/workflows/add-git-trailers.yml | 43 +++++++++----------------- .github/workflows/pr-merge.yml | 21 +++++++------ .github/workflows/pr-trailers.yml | 16 ---------- 3 files changed, 26 insertions(+), 54 deletions(-) delete mode 100644 .github/workflows/pr-trailers.yml diff --git a/.github/workflows/add-git-trailers.yml b/.github/workflows/add-git-trailers.yml index 73d5f5f..59d8b51 100644 --- a/.github/workflows/add-git-trailers.yml +++ b/.github/workflows/add-git-trailers.yml @@ -1,12 +1,12 @@ name: Add Git Trailers to PR commits on: - workflow_call: - secrets: - GIT_CLONE_PAT: - required: false - URUNC_BOT_PRIVATE_KEY: - required: true + pull_request_review: + types: [submitted] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true permissions: contents: read @@ -14,16 +14,12 @@ permissions: jobs: git-trailers: name: Add Git Trailers - runs-on: ${{ matrix.runner }} - strategy: - matrix: - include: - - arch: amd64 - runner: ubuntu-22.04 - continue-on-error: true + if: >- + github.event.pull_request.base.ref == 'main' && + github.event.review.state == 'approved' + runs-on: ubuntu-22.04 permissions: contents: write - pull-requests: write steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 @@ -40,11 +36,6 @@ jobs: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} - - name: Append git trailers - uses: nubificus/git-trailers@8e08c91bb4c1fd9cb1ccbd9cc8029c31acf8da66 # feat_use_rebase - with: - user_info: .github/contributors.yaml - - name: Generate urunc-bot token id: generate-token uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 @@ -52,20 +43,16 @@ jobs: app-id: ${{ vars.URUNC_BOT_APP_ID }} private-key: ${{ secrets.URUNC_BOT_PRIVATE_KEY }} - - name: Set up Git - run: | - git config --global user.name "urunc-bot[bot]" - git config --global user.email "urunc-bot[bot]@users.noreply.github.com" - - name: Append git trailers - uses: nubificus/git-trailers@18fd322f3fbfd505b4de728974a4ac1f32f758a7 # feat_auto_merge + uses: nubificus/git-trailers@1d1595aacfd9239ae69d773cb895606daa17e538 with: - user_info: .github/contributors.yaml + token: ${{ steps.generate-token.outputs.token }} + user-info: .github/contributors.yaml - name: Merge PR env: GH_TOKEN: ${{ steps.generate-token.outputs.token }} + PR_URL: ${{ github.event.pull_request.html_url }} run: | - PR_URL=${{ github.event.pull_request.html_url }} - + sleep 5 # Wait for github to get updated with the push. Otherwise merge will fail gh pr merge "$PR_URL" --rebase --admin diff --git a/.github/workflows/pr-merge.yml b/.github/workflows/pr-merge.yml index 1b57dfd..fa66f2f 100644 --- a/.github/workflows/pr-merge.yml +++ b/.github/workflows/pr-merge.yml @@ -4,6 +4,8 @@ on: pull_request_target: types: - closed + branches: + - 'main-pr*' permissions: contents: read @@ -11,22 +13,19 @@ permissions: jobs: add-trailers-and-merge: if: | - github.event.pull_request.merged == true && - startsWith(github.event.pull_request.base.ref, 'main-pr') + github.event.pull_request.merged == true runs-on: ubuntu-latest permissions: contents: write - steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 with: egress-policy: audit - - name: Set up Git - run: | - git config --global user.name "urunc-bot[bot]" - git config --global user.email "urunc-bot[bot]@users.noreply.github.com" + - name: Exit if PR is not rebaseable + if: ${{ github.event.pull_request.rebaseable != null && github.event.pull_request.rebaseable == false }} + run: exit 1 - name: Check out repo uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -42,16 +41,18 @@ jobs: private-key: ${{ secrets.URUNC_BOT_PRIVATE_KEY }} - name: Append git trailers - uses: nubificus/git-trailers@18fd322f3fbfd505b4de728974a4ac1f32f758a7 # feat_auto_merge + uses: nubificus/git-trailers@1d1595aacfd9239ae69d773cb895606daa17e538 with: - user_info: .github/contributors.yaml + token: ${{ steps.generate-token.outputs.token }} + user-info: .github/contributors.yaml - name: Create a Pull Request from PR_BRANCH to main and merge it env: GH_TOKEN: ${{ steps.generate-token.outputs.token }} + PR_BRANCH: ${{ github.event.pull_request.base.ref }} run: | PR_BRANCH=${{ github.event.pull_request.base.ref }} - + # Create the pull request PR_URL=$(gh pr create \ --head "$PR_BRANCH" \ diff --git a/.github/workflows/pr-trailers.yml b/.github/workflows/pr-trailers.yml deleted file mode 100644 index 82fbcde..0000000 --- a/.github/workflows/pr-trailers.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Add Git Trailers to PR commits - -on: - pull_request_review: - types: [submitted] - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - git-trailers: - name: Add Git Trailers to PR commits - if: ${{ github.event.pull_request.base.ref == 'main' && github.event.review.state == 'approved' }} - uses: ./.github/workflows/add-git-trailers.yml - secrets: inherit From d85811a6ddd55aaaa175b79b131524bec7ef168a Mon Sep 17 00:00:00 2001 From: charma7 <104625181+charma7@users.noreply.github.com> Date: Fri, 8 May 2026 15:26:48 +0300 Subject: [PATCH 2/3] Update contributors.yaml PR: https://github.com/urunc-dev/urunc_test/pull/59 Signed-off-by: char ma Reviewed-by: Charalampos Mainas Approved-by: Charalampos Mainas --- .github/contributors.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/contributors.yaml b/.github/contributors.yaml index fce1b46..d5a7311 100644 --- a/.github/contributors.yaml +++ b/.github/contributors.yaml @@ -83,3 +83,6 @@ users: jim-junior: name: Beingana Jim Junior email: jimjunior854@gmail.com + charma7: + name: A test user + email: test@mail.com From dab1e3964a2239d1159c5f3b492a4be62ccd8473 Mon Sep 17 00:00:00 2001 From: Md Raiyan Date: Fri, 15 May 2026 16:27:34 +0000 Subject: [PATCH 3/3] fix(e2e): replace regex in findValOfKey with JSON parsing Signed-off-by: Md Raiyan --- tests/e2e/common.go | 57 ++++++++++++++++++++++++------- tests/e2e/common_test.go | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 tests/e2e/common_test.go diff --git a/tests/e2e/common.go b/tests/e2e/common.go index e232c63..b29802b 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -16,10 +16,11 @@ package urunce2etesting import ( "bytes" + "encoding/json" "errors" "fmt" "os/exec" - "regexp" + "strconv" "strings" ) @@ -250,21 +251,53 @@ func checkExpectedOut(expected string, output string, e error) error { } func findValOfKey(searchArea string, key string) (string, error) { - keystr := "\"" + key + "\":[^,;\\]}]*" - r, err := regexp.Compile(keystr) - if err != nil { - return "", err + var data interface{} + if err := json.Unmarshal([]byte(searchArea), &data); err != nil { + return "", fmt.Errorf("key %s not found in search area", key) } - match := r.FindString(searchArea) - if match == "" { + val, found := searchJSONKey(data, key) + if !found { return "", fmt.Errorf("key %s not found in search area", key) } + return val, nil +} - keyValMatch := strings.Split(match, ":") - if len(keyValMatch) < 2 { - return "", fmt.Errorf("invalid format for key %s: %s", key, match) +func searchJSONKey(data interface{}, key string) (string, bool) { + switch v := data.(type) { + case map[string]interface{}: + if val, ok := v[key]; ok { + return jsonValToString(val), true + } + for _, child := range v { + if result, found := searchJSONKey(child, key); found { + return result, true + } + } + case []interface{}: + for _, item := range v { + if result, found := searchJSONKey(item, key); found { + return result, true + } + } } + return "", false +} - val := strings.ReplaceAll(keyValMatch[1], "\"", "") - return strings.TrimSpace(val), nil +func jsonValToString(v interface{}) string { + switch val := v.(type) { + case string: + return val + case float64: + if val == float64(int64(val)) { + return strconv.FormatInt(int64(val), 10) + } + return strconv.FormatFloat(val, 'f', -1, 64) + case bool: + return strconv.FormatBool(val) + case nil: + return "" + default: + b, _ := json.Marshal(val) + return string(b) + } } diff --git a/tests/e2e/common_test.go b/tests/e2e/common_test.go new file mode 100644 index 0000000..be23089 --- /dev/null +++ b/tests/e2e/common_test.go @@ -0,0 +1,73 @@ +// Copyright (c) 2023-2026, Nubificus LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package urunce2etesting + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFindValOfKey(t *testing.T) { + tests := []struct { + name string + searchArea string + key string + wantVal string + wantErr bool + }{ + { + name: "scalar string value", + searchArea: `[{"IPAddress":"172.17.0.2","Name":"test"}]`, + key: "IPAddress", + wantVal: "172.17.0.2", + }, + { + name: "scalar integer value", + searchArea: `[{"Pid":12345,"Name":"test"}]`, + key: "Pid", + wantVal: "12345", + }, + { + name: "value containing comma is truncated", + searchArea: `[{"Name":"test","Label":"foo,bar"}]`, + key: "Label", + wantVal: "foo,bar", + }, + { + name: "nested object value", + searchArea: `[{"NetworkSettings":{"IPAddress":"172.17.0.2"}}]`, + key: "NetworkSettings", + wantVal: `{"IPAddress":"172.17.0.2"}`, + }, + { + name: "key not found", + searchArea: `[{"Name":"test"}]`, + key: "Missing", + wantErr: true, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + val, err := findValOfKey(tc.searchArea, tc.key) + if tc.wantErr { + assert.Error(t, err) + return + } + assert.NoError(t, err) + assert.Equal(t, tc.wantVal, val) + }) + } +}