From 331142762270ff7eafcf07ff72096badb7e5c11b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 27 Oct 2021 19:04:00 +0300 Subject: [PATCH 1/4] update workflows Signed-off-by: Vasiliy Tolstov --- .github/workflows/codeql-analysis.yml | 21 +++--- .github/workflows/dependabot-automerge.yml | 75 ++++++---------------- 2 files changed, 32 insertions(+), 64 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index fa4081e..b50aad2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -9,7 +9,7 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: "codeql" on: workflow_run: @@ -17,16 +17,16 @@ on: types: - completed push: - branches: [ master ] + branches: [ master, v3 ] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [ master, v3 ] schedule: - cron: '34 1 * * 0' jobs: analyze: - name: Analyze + name: analyze runs-on: ubuntu-latest permissions: actions: read @@ -42,11 +42,14 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - - name: Checkout repository + - name: checkout uses: actions/checkout@v2 - + - name: setup + uses: actions/setup-go@v2 + with: + go-version: 1.16 # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL + - name: init uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} @@ -57,7 +60,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild + - name: autobuild uses: github/codeql-action/autobuild@v1 # ℹ️ Command-line programs to run using the OS shell. @@ -71,5 +74,5 @@ jobs: # make bootstrap # make release - - name: Perform CodeQL Analysis + - name: analyze uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml index dd6a62e..69e4c39 100644 --- a/.github/workflows/dependabot-automerge.yml +++ b/.github/workflows/dependabot-automerge.yml @@ -1,66 +1,31 @@ name: "prautomerge" on: - workflow_run: - workflows: ["prbuild"] - types: - - completed + pull_request_target: + types: [assigned, opened, synchronize, reopened] permissions: - contents: write pull-requests: write + contents: write jobs: - Dependabot-Automerge: + dependabot: runs-on: ubuntu-latest - # Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR - # The the github.event.workflow_run.event value is 'push' and not 'pull_request' - # dont work with multiple workflows when last returns success - if: >- - github.event.workflow_run.conclusion == 'success' - && github.actor == 'dependabot[bot]' - && github.event.sender.login == 'dependabot[bot]' - && github.event.sender.type == 'Bot' - && (github.event.workflow_run.event == 'pull_request' - || (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch )) + if: ${{ github.actor == 'dependabot[bot]' }} steps: - - name: Approve Changes and Merge changes if label 'dependencies' is set - uses: actions/github-script@v5 + - name: metadata + id: metadata + uses: dependabot/fetch-metadata@v1.1.1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - console.log(context.payload.workflow_run); - - var labelNames = await github.paginate( - github.issues.listLabelsOnIssue, - { - repo: context.repo.repo, - owner: context.repo.owner, - issue_number: context.payload.workflow_run.pull_requests[0].number, - }, - (response) => response.data.map( - (label) => label.name - ) - ); - - console.log(labelNames); - - if (labelNames.includes('dependencies')) { - console.log('Found label'); - - await github.pulls.createReview({ - repo: context.repo.repo, - owner: context.repo.owner, - pull_number: context.payload.workflow_run.pull_requests[0].number, - event: 'APPROVE' - }); - console.log('Approved PR'); - - await github.pulls.merge({ - repo: context.repo.repo, - owner: context.repo.owner, - pull_number: context.payload.workflow_run.pull_requests[0].number, - }); - - console.log('Merged PR'); - } + github-token: "${{ secrets.TOKEN }}" + - name: approve + run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.TOKEN}} + - name: merge + if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.TOKEN}} -- 2.45.2 From 686c49d8d77f8447e69583ffa7d0395f6ac64540 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Oct 2021 04:23:11 +0000 Subject: [PATCH 2/4] Bump go.unistack.org/micro/v3 from 3.8.5 to 3.8.7 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.5 to 3.8.7. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.5...v3.8.7) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 10ad07a..5d804ab 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( github.com/imdario/mergo v0.3.12 - go.unistack.org/micro/v3 v3.8.5 + go.unistack.org/micro/v3 v3.8.7 ) diff --git a/go.sum b/go.sum index 28e6754..195a70b 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= go.unistack.org/micro-proto/v3 v3.1.0 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA= go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= -go.unistack.org/micro/v3 v3.8.5 h1:DIYWRsQF+NPhKZP45sCtNsUhaRw6u2+Ps7U+pKU7i3s= -go.unistack.org/micro/v3 v3.8.5/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.7 h1:k1zOpJ3uS8MxdhK8annRsa5J/LW7MpqPjwYuekW61wE= +go.unistack.org/micro/v3 v3.8.7/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -- 2.45.2 From 1defe581d3a258bd80ab53b44f6390bfecf43777 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Nov 2021 04:26:54 +0000 Subject: [PATCH 3/4] Bump go.unistack.org/micro/v3 from 3.8.7 to 3.8.10 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.7 to 3.8.10. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.7...v3.8.10) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5d804ab..2067e04 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( github.com/imdario/mergo v0.3.12 - go.unistack.org/micro/v3 v3.8.7 + go.unistack.org/micro/v3 v3.8.10 ) diff --git a/go.sum b/go.sum index 195a70b..d7b456f 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= go.unistack.org/micro-proto/v3 v3.1.0 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA= go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= -go.unistack.org/micro/v3 v3.8.7 h1:k1zOpJ3uS8MxdhK8annRsa5J/LW7MpqPjwYuekW61wE= -go.unistack.org/micro/v3 v3.8.7/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.10 h1:ZMKGGalqkZc677S5BmSPTAMZAE4q3u2FuqCrCd1TO7g= +go.unistack.org/micro/v3 v3.8.10/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -- 2.45.2 From 70a3109b31a85e14b9e1ee6520fb17042897a885 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 24 Nov 2021 01:21:55 +0300 Subject: [PATCH 4/4] add watch test Signed-off-by: Vasiliy Tolstov --- env_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/env_test.go b/env_test.go index 421adb7..8f09dff 100644 --- a/env_test.go +++ b/env_test.go @@ -4,8 +4,10 @@ import ( "context" "os" "testing" + "time" "go.unistack.org/micro/v3/config" + rutil "go.unistack.org/micro/v3/util/reflect" ) type Config struct { @@ -17,6 +19,52 @@ type Config struct { MapIntValue map[string]int `env:"MAP_INT"` } +func TestMerge(t *testing.T) { + ctx := context.Background() + type Nested struct { + Name string `env:"NAME_VALUE"` + } + type Cfg struct { + Name string `env:"NAME_VALUE"` + Nested Nested + } + + conf := &Cfg{} + + cfg := NewConfig(config.Struct(conf)) + + if err := cfg.Init(); err != nil { + t.Fatal(err) + } + + if err := cfg.Load(ctx, config.LoadOverride(true), config.LoadAppend(true)); err != nil { + t.Fatal(err) + } + + w, err := cfg.Watch(ctx, config.WatchInterval(50*time.Millisecond, 500*time.Millisecond)) + defer func() { + if err := w.Stop(); err != nil { + t.Fatal(err) + } + }() + + os.Setenv("NAME_VALUE", "after") + changes, err := w.Next() + if err != nil { + t.Fatal(err) + } + + for k, v := range changes { + if err := rutil.SetFieldByPath(conf, v, k); err != nil { + t.Fatal(err) + } + } + + if conf.Name != "after" || conf.Nested.Name != "after" { + t.Fatalf("changes %#+v not applied to %#+v", changes, conf) + } +} + func TestLoad(t *testing.T) { ctx := context.Background() conf := &Config{StringValue: "before_load"} @@ -63,8 +111,6 @@ func TestLoad(t *testing.T) { if len(conf.MapIntValue) != 2 { t.Fatalf("something wrong with env config: %#+v", conf.MapIntValue) } - - t.Logf("cfg %#+v", conf) } func TestSave(t *testing.T) { diff --git a/go.mod b/go.mod index 2067e04..ae5e8b2 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( github.com/imdario/mergo v0.3.12 - go.unistack.org/micro/v3 v3.8.10 + go.unistack.org/micro/v3 v3.8.11 ) diff --git a/go.sum b/go.sum index d7b456f..93f41b9 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= go.unistack.org/micro-proto/v3 v3.1.0 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA= go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= -go.unistack.org/micro/v3 v3.8.10 h1:ZMKGGalqkZc677S5BmSPTAMZAE4q3u2FuqCrCd1TO7g= -go.unistack.org/micro/v3 v3.8.10/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.11 h1:Wv1YopcYNcsN3bW8Mv8v6AF99s0uKBtWQ1M/Ag8QLec= +go.unistack.org/micro/v3 v3.8.11/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -- 2.45.2