merge stable #41

Merged
vtolstov merged 4 commits from master into v3 2021-11-18 16:12:50 +03:00
6 changed files with 80 additions and 76 deletions

View File

@ -9,7 +9,7 @@
# the `language` matrix defined below to confirm you have the correct set of # the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages. # supported CodeQL languages.
# #
name: "CodeQL" name: "codeql"
on: on:
workflow_run: workflow_run:
@ -17,16 +17,16 @@ on:
types: types:
- completed - completed
push: push:
branches: [ master ] branches: [ master, v3 ]
pull_request: pull_request:
# The branches below must be a subset of the branches above # The branches below must be a subset of the branches above
branches: [ master ] branches: [ master, v3 ]
schedule: schedule:
- cron: '34 1 * * 0' - cron: '34 1 * * 0'
jobs: jobs:
analyze: analyze:
name: Analyze name: analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
actions: read 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 # 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: steps:
- name: Checkout repository - name: checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: setup
uses: actions/setup-go@v2
with:
go-version: 1.16
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: init
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v1
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
@ -57,7 +60,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # 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) # 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 uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
@ -71,5 +74,5 @@ jobs:
# make bootstrap # make bootstrap
# make release # make release
- name: Perform CodeQL Analysis - name: analyze
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v1

View File

@ -1,66 +1,31 @@
name: "prautomerge" name: "prautomerge"
on: on:
workflow_run: pull_request_target:
workflows: ["prbuild"] types: [assigned, opened, synchronize, reopened]
types:
- completed
permissions: permissions:
contents: write
pull-requests: write pull-requests: write
contents: write
jobs: jobs:
Dependabot-Automerge: dependabot:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR if: ${{ github.actor == 'dependabot[bot]' }}
# 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 ))
steps: steps:
- name: Approve Changes and Merge changes if label 'dependencies' is set - name: metadata
uses: actions/github-script@v5 id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: "${{ secrets.TOKEN }}"
script: | - name: approve
console.log(context.payload.workflow_run); run: gh pr review --approve "$PR_URL"
env:
var labelNames = await github.paginate( PR_URL: ${{github.event.pull_request.html_url}}
github.issues.listLabelsOnIssue, GITHUB_TOKEN: ${{secrets.TOKEN}}
{ - name: merge
repo: context.repo.repo, if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
owner: context.repo.owner, run: gh pr merge --auto --merge "$PR_URL"
issue_number: context.payload.workflow_run.pull_requests[0].number, env:
}, PR_URL: ${{github.event.pull_request.html_url}}
(response) => response.data.map( GITHUB_TOKEN: ${{secrets.TOKEN}}
(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');
}

42
file.go
View File

@ -51,9 +51,17 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
return err return err
} }
fp, err := os.OpenFile(c.path, os.O_RDONLY, os.FileMode(0400)) path := c.path
options := config.NewLoadOptions(opts...)
if options.Context != nil {
if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" {
path = v
}
}
fp, err := os.OpenFile(path, os.O_RDONLY, os.FileMode(0400))
if err != nil { if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "file load path %s error: %v", c.path, err) c.opts.Logger.Errorf(c.opts.Context, "file load path %s error: %v", path, err)
if !c.opts.AllowFail { if !c.opts.AllowFail {
return err return err
} }
@ -64,7 +72,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
buf, err := ioutil.ReadAll(io.LimitReader(fp, int64(codec.DefaultMaxMsgSize))) buf, err := ioutil.ReadAll(io.LimitReader(fp, int64(codec.DefaultMaxMsgSize)))
if err != nil { if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "file load path %s error: %v", c.path, err) c.opts.Logger.Errorf(c.opts.Context, "file load path %s error: %v", path, err)
if !c.opts.AllowFail { if !c.opts.AllowFail {
return err return err
} }
@ -88,7 +96,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
} }
if err != nil { if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "file load path %s error: %v", c.path, err) c.opts.Logger.Errorf(c.opts.Context, "file load path %s error: %v", path, err)
if !c.opts.AllowFail { if !c.opts.AllowFail {
return err return err
} }
@ -106,18 +114,26 @@ func (c *fileConfig) Save(ctx context.Context, opts ...config.SaveOption) error
return err return err
} }
path := c.path
options := config.NewSaveOptions(opts...)
if options.Context != nil {
if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" {
path = v
}
}
buf, err := c.opts.Codec.Marshal(c.opts.Struct) buf, err := c.opts.Codec.Marshal(c.opts.Struct)
if err != nil { if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "file save path %s error: %v", c.path, err) c.opts.Logger.Errorf(c.opts.Context, "file save path %s error: %v", path, err)
if !c.opts.AllowFail { if !c.opts.AllowFail {
return err return err
} }
return config.DefaultAfterSave(ctx, c) return config.DefaultAfterSave(ctx, c)
} }
fp, err := os.OpenFile(c.path, os.O_WRONLY|os.O_CREATE, os.FileMode(0600)) fp, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, os.FileMode(0600))
if err != nil { if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "file save path %s error: %v", c.path, err) c.opts.Logger.Errorf(c.opts.Context, "file save path %s error: %v", path, err)
if !c.opts.AllowFail { if !c.opts.AllowFail {
return err return err
} }
@ -130,7 +146,7 @@ func (c *fileConfig) Save(ctx context.Context, opts ...config.SaveOption) error
} }
if err != nil { if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "file save path %s error: %v", c.path, err) c.opts.Logger.Errorf(c.opts.Context, "file save path %s error: %v", path, err)
if !c.opts.AllowFail { if !c.opts.AllowFail {
return err return err
} }
@ -152,8 +168,16 @@ func (c *fileConfig) Name() string {
} }
func (c *fileConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) { func (c *fileConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
path := c.path
options := config.NewWatchOptions(opts...)
if options.Context != nil {
if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" {
path = v
}
}
w := &fileWatcher{ w := &fileWatcher{
path: c.path, path: path,
opts: c.opts, opts: c.opts,
wopts: config.NewWatchOptions(opts...), wopts: config.NewWatchOptions(opts...),
done: make(chan struct{}), done: make(chan struct{}),

2
go.mod
View File

@ -4,5 +4,5 @@ go 1.16
require ( require (
github.com/imdario/mergo v0.3.12 github.com/imdario/mergo v0.3.12
go.unistack.org/micro/v3 v3.8.5 go.unistack.org/micro/v3 v3.8.9
) )

4
go.sum
View File

@ -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= 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 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA=
go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= 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.9 h1:F+HAQSHI86F8Xx5D6XKvvuN0TtOuVvJM+OBV8aYTg0Y=
go.unistack.org/micro/v3 v3.8.5/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= go.unistack.org/micro/v3 v3.8.9/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA=
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -9,3 +9,15 @@ type pathKey struct{}
func Path(path string) config.Option { func Path(path string) config.Option {
return config.SetOption(pathKey{}, path) return config.SetOption(pathKey{}, path)
} }
func LoadPath(path string) config.LoadOption {
return config.SetLoadOption(pathKey{}, path)
}
func SavePath(path string) config.SaveOption {
return config.SetSaveOption(pathKey{}, path)
}
func WatchPath(path string) config.WatchOption {
return config.SetWatchOption(pathKey{}, path)
}