Skip to content

Commit

Permalink
Optimize binary size
Browse files Browse the repository at this point in the history
  • Loading branch information
slytomcat committed Jul 2, 2023
1 parent 03290e5 commit 1ab8b6e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Go
on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.5
- name: Cache
uses: actions/cache@v3
with:
path: |
/home/runner/.cache/go-build/
/home/runner/go/pkg/mod/
key: GO_MOD_CACHE
- name: Requirements
run: sudo apt-get install upx-ucl
- name: Build
run: ./build.sh
- name: Upload a Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build_artifacts
path: |
ws
push:
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: build_artifacts
- name: Draft new release and upload assets
env:
GH_TOKEN: ${{ secrets.ACTION_TOKEN }}
run: |
gh release create "$(git branch --show-current)-$(git rev-parse --short HEAD)" ./ws
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
CGO_ENABLED=0 go build -buildvcs=false -trimpath -ldflags="-s -w -X main.version=$(git branch --show-current)-$(git rev-parse --short HEAD)" .
upx -qqq --best ws
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// Version is app version
const Version = "0.2.3"
var version = ""

var options struct {
origin string
Expand All @@ -31,7 +31,7 @@ var options struct {
func main() {
rootCmd := &cobra.Command{
Use: "ws URL",
Short: fmt.Sprintf("ws is a websocket client v.%s", Version),
Short: fmt.Sprintf("ws is a websocket client v.%s", version),
Run: root,
}
rootCmd.Flags().StringVarP(&options.origin, "origin", "o", "", "websocket origin")
Expand All @@ -48,7 +48,7 @@ func main() {

func root(cmd *cobra.Command, args []string) {
if options.printVersion {
fmt.Printf("ws v.%s\n", Version)
fmt.Printf("ws v.%s\n", version)
os.Exit(0)
}

Expand Down

0 comments on commit 1ab8b6e

Please sign in to comment.