Skip to content

Commit

Permalink
Merge pull request #37 from shipengqi/feat/release
Browse files Browse the repository at this point in the history
feat(options): add banner callback
  • Loading branch information
shipengqi authored May 9, 2024
2 parents e4b9b4e + ce5fa9f commit e8ea8e2
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ updates:
labels:
- "dependencies"
commit-message:
prefix: "feat"
prefix: "chore"
include: "scope"
- package-ecosystem: "github-actions"
assignees:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
pull_request:
branches: [ main ]
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
jobs:
analyze:
name: analyze
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/gitleaks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
permissions:
contents: read
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/grype.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
jobs:
scan-source:
name: scan-source
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ on:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- '.goreleaser.yaml'
permissions:
contents: read

jobs:
golangci:
strategy:
matrix:
go: [ '1.20', '1.21' ]
go: [ '1.20', '1.21', '1.22' ]
os: [ ubuntu-latest, windows-latest ]
permissions:
contents: read # for actions/checkout to fetch code
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "release a version"
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # it is required fot the changelog to work correctly
- uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
distribution: goreleaser
version: latest
args: release --debug --clean

35 changes: 35 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
builds:
- # If true, skip the build.
# Useful for library projects.
skip: true
changelog:
sort: asc
use: github
filters:
exclude:
- '^Merge'
groups:
- title: 'New Features'
regexp: "^.*feat.*:+.*$"
order: 100
- title: 'Bug Fixes'
regexp: "^.*fix.*:+.*$"
order: 200
- title: 'Dependency Updates'
regexp: "^.*(feat|fix)\\(deps\\)*:+.*$"
order: 300
- title: 'Documentation Updates'
regexp: "^.*docs.*:+.*$"
order: 400
- title: Other work
order: 9999
release:
footer: |
**Full Changelog**: https://github.com/shipengqi/gosh/compare/{{ .PreviousTag }}...{{ .Tag }}
# modelines, feel free to remove those if you don't want/use them:
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8 changes: 8 additions & 0 deletions gosh.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Client struct {
opts *Options
auth ssh.AuthMethod
callback ssh.HostKeyCallback
bannercb ssh.BannerCallback
}

// NewDefault creates a Client with DefaultHostKeyCallback, the host public key must be in known hosts.
Expand Down Expand Up @@ -112,6 +113,12 @@ func (c *Client) WithHostKeyCallback(callback ssh.HostKeyCallback) *Client {
return c
}

// WithBannerCallback sets ssh.BannerCallback of Client.
func (c *Client) WithBannerCallback(callback ssh.BannerCallback) *Client {
c.bannercb = callback
return c
}

// Dial starts a client connection to the given SSH server.
func (c *Client) Dial() error {
cli, err := c.dial()
Expand Down Expand Up @@ -280,6 +287,7 @@ func (c *Client) dial() (*ssh.Client, error) {
Auth: []ssh.AuthMethod{c.auth},
Timeout: c.opts.Timeout,
HostKeyCallback: c.callback,
BannerCallback: c.bannercb,
},
)
}
Expand Down
4 changes: 2 additions & 2 deletions knownhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

func AutoFixedHostKeyCallback(host string, remote net.Addr, key ssh.PublicKey) error {
found, err := VerifyKnownHost("", host, remote, key)
if found && err != nil {
if err != nil {
return err
}
if found && err == nil {
if found {
return nil
}
// Add the new host to known hosts file.
Expand Down

0 comments on commit e8ea8e2

Please sign in to comment.