Skip to content

Commit

Permalink
add gorelease for releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Sep 5, 2023
1 parent 32dd1b5 commit 1c3eb84
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 11 deletions.
58 changes: 58 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter
name-template: 'v$NEXT_PATCH_VERSION 🌈'
tag-template: 'v$NEXT_PATCH_VERSION'
version-template: $MAJOR.$MINOR.$PATCH
# Emoji reference: https://gitmoji.carloscuesta.me/
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- 'kind/feature'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- 'regression'
- 'kind/bug'
- title: 📝 Documentation updates
labels:
- documentation
- 'kind/doc'
- title: 👻 Maintenance
labels:
- chore
- dependencies
- 'kind/chore'
- 'kind/dep'
- title: 🚦 Tests
labels:
- test
- tests
exclude-labels:
- reverted
- no-changelog
- skip-changelog
- invalid
autolabeler:
- label: 'documentation'
title:
- '/docs:/i'
- label: 'chore'
title:
- '/chore:/i'
- label: 'bug'
title:
- '/fix:/i'
- label: 'enhancement'
title:
- '/feat:/i'
change-template: '* $TITLE (#$NUMBER) @$AUTHOR'
template: |
## What’s Changed
$CHANGES
## Thanks to
$CONTRIBUTORS
18 changes: 18 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build

on:
- pull_request

jobs:
Test:
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- uses: actions/checkout@v3.0.0
- name: Unit Test
run: |
go build .
go test ./...
14 changes: 14 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Drafter

on:
push:
branches:
- master

jobs:
UpdateReleaseDraft:
runs-on: ubuntu-20.04
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_SECRETS }}
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

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3.0.0
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2.9.1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_SECRETS }}
37 changes: 37 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
id: gows
binary: gows
goos:
- linux
- windows
- darwin
ldflags:
- -w
- -s
archives:
- name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}"
builds:
- gows
format_overrides:
- goos: windows
format: zip
files:
- README.md
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
28 changes: 17 additions & 11 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"net/http"
"net/url"
"os"
"os/signal"

Expand All @@ -15,31 +14,38 @@ import (
func NewRootCmd() (cmd *cobra.Command) {
opt := &rootOption{}
cmd = &cobra.Command{
Use: "gows",
Short: "Echo the message from a websoket server",
Args: cobra.MinimumNArgs(1),
RunE: opt.runE,
Use: "gows",
Example: "gwws ws://your-server.com",
Short: "Echo the message from a websoket server",
Args: cobra.MinimumNArgs(1),
PreRunE: opt.preRunE,
RunE: opt.runE,
}
flags := cmd.Flags()
flags.StringVarP(&opt.server, "server", "s", "", "The server address")
cmd.MarkFlagRequired("server")
flags.StringVarP(&opt.cookie, "cookie", "", "", "The cookie to connect to the server")
return
}

type rootOption struct {
server string
cookie string
}

func (o *rootOption) preRunE(cmd *cobra.Command, args []string) (err error) {
o.cookie = os.ExpandEnv(o.cookie)
return
}

func (o *rootOption) runE(cmd *cobra.Command, args []string) (err error) {
service := args[0]
server := url.URL{Scheme: "ws", Host: o.server, Path: service}

header := http.Header{}
header.Set("Cookie", "oAuthLoginInfo=; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODA2MTE1OTYsImlhdCI6MTY4MDYwNDM5NiwiaXNzIjoia3ViZXNwaGVyZSIsInN1YiI6ImFkbWluIiwidG9rZW5fdHlwZSI6ImFjY2Vzc190b2tlbiIsInVzZXJuYW1lIjoiYWRtaW4ifQ.kY7jpe4If37_9Kz_U9R5s6q2jIwzZ7tTaYI6KbXee_Y; expire=1680611597080; refreshToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODA2MTg3OTYsImlhdCI6MTY4MDYwNDM5NiwiaXNzIjoia3ViZXNwaGVyZSIsInN1YiI6ImFkbWluIiwidG9rZW5fdHlwZSI6InJlZnJlc2hfdG9rZW4iLCJ1c2VybmFtZSI6ImFkbWluIn0.8niwD-WQK7LMDb-T9B177v0rVpWWP21F7qc8ve2qNrc; lang=zh")
if o.cookie != "" {
header.Set("Cookie", o.cookie)
}

var conn *websocket.Conn
var resp *http.Response
if conn, resp, err = websocket.DefaultDialer.Dial(server.String(), header); err != nil {
if conn, resp, err = websocket.DefaultDialer.Dial(service, header); err != nil {
cmd.Println("failed to dial, response is", resp)
return
}
Expand Down

0 comments on commit 1c3eb84

Please sign in to comment.