Skip to content

Commit

Permalink
Add makefile and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro-h committed May 1, 2021
1 parent ae1c010 commit 1cd7943
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 21 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches: ["**"]
tags-ignore: ["v*"]
pull_request:

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Install additional build tools
run: |
go get golang.org/x/lint/golint
make install-sys-packages
- name: Test
run: make test

- name: Lint
run: make lint

- name: Build Linux
run: make build-linux

- name: Build Windows
run: make build-windows

- name: Build Centos
run: make build-centos
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Release

on:
push:
tags: ["v*"]

jobs:

release:
name: Release
runs-on: ubuntu-latest

steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Install additional build tools
run: |
go get golang.org/x/lint/golint
make install-sys-packages
- name: Build
run: make build-all-optimized

- name: Compress binaries
run: make compress-binaries

- name: Get version
id: get_version
run: VERSION_NUMBER=${GITHUB_RUN_NUMBER}-${GITHUB_SHA:0:7} make print-version

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ steps.get_version.outputs.version }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: snippet
asset_name: snippet
asset_content_type: application/octet-stream

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: snippet-centos
asset_name: snippet-centos
asset_content_type: application/octet-stream

# - name: Upload Release Asset
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: snippet.exe
# asset_name: snippet.exe
# asset_content_type: application/octet-stream
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
snippet
snippet.exe
snippet-centos
snippet.exe
pkg_tok
upx
upx*.tar.xz
90 changes: 90 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
BASE_VERSION=0.0.1
REPO_OWNER=sandro-h
BUILD_CENTOS_IMAGE_VERSION=0.0.1
BUILD_CENTOS_IMAGE_TAG=ghcr.io/${REPO_OWNER}/snippet-centos-build:${BUILD_CENTOS_IMAGE_VERSION}
PUSH_IMAGE=false


.PHONY: docker-login
docker-login:
echo $$DOCKER_PWD | docker login ghcr.io -u ${REPO_OWNER} --password-stdin

.PHONY: push-centos-image
push-centos-image:
ifeq ($(PUSH_IMAGE), true)
docker push ${BUILD_CENTOS_IMAGE_TAG}
endif

.PHONY: build-centos-image
build-centos-image:
docker build \
--tag ${BUILD_CENTOS_IMAGE_TAG} \
centos/

.PHONY: ensure-centos-image
ensure-centos-image:
docker pull ${BUILD_CENTOS_IMAGE_TAG} || make build-centos-image push-centos-image

.PHONY: ensure-centos-image
build-centos: ensure-centos-image
docker run --rm \
-v $$(pwd):/src \
-e DEV_UID=$$(id -u) \
-w /src \
${BUILD_CENTOS_IMAGE_TAG} \
"/usr/local/go/bin/go build -o snippet-centos ${EXTRA_BUILD_ARGS} && chown \$$DEV_UID snippet-centos"

.PHONY: build-windows
build-windows:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build ${EXTRA_BUILD_ARGS}

.PHONY: build-linux
build-linux:
go build ${EXTRA_BUILD_ARGS}

.PHONY: test
test:
go test ./...

.PHONY: lint
lint:
golint -set_exit_status ./...

.PHONY: install-sys-packages
install-sys-packages:
sudo apt install gcc libc6-dev \
libx11-dev xorg-dev libxtst-dev libpng++-dev \
xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev \
libxkbcommon-dev xsel xclip \
libgl1-mesa-dev \
gcc-mingw-w64-x86-64 libz-mingw-w64-dev

###########################################################################################
# Releasing
###########################################################################################

.PHONY: release
release:
git tag v${BASE_VERSION}
git push origin v${BASE_VERSION}


.PHONY: print-version
print-version:
echo "::set-output name=version::${BASE_VERSION}.$${VERSION_NUMBER:-0}"

.PHONY: build-all-optimized
build-all-optimized: EXTRA_BUILD_ARGS=-ldflags='-s -w'
build-all-optimized: build-linux build-centos # build-windows

upx:
wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz
tar xf upx-3.96-amd64_linux.tar.xz
mv upx-3.96-amd64_linux/ upx

.PHONY: compress-binaries
compress-binaries: upx
chmod +x snippet snippet-centos
upx/upx -q --brute snippet
upx/upx -q --brute snippet-centos
# upx/upx -q --brute snippet.exe
18 changes: 0 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
# snippet

## Installation

### Redhat

#### Prerequisites

libpng 1.6 (RHEL7 only has 1.5 package):

```shell
wget https://sourceforge.net/projects/libpng/files/libpng16/1.6.37/libpng-1.6.37.tar.gz
tar xvf libpng-1.6.37.tar.gz
cd libpng-1.6.37/
./configure
make
sudo make install
sudo ln -s /usr/local/lib/libpng16.so.16 /usr/lib64/libpng16.so.16
```

## Development

### Windows cross-compilation
Expand Down
24 changes: 24 additions & 0 deletions centos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM centos:7

# Basic build tools
RUN yum -y install centos-release-scl
RUN yum -y install devtoolset-7-gcc-c++

# golang tools
RUN yum -y install wget
RUN wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz
RUN tar -C /usr/local -xzf go1.16.3.linux-amd64.tar.gz
RUN echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc

# dev libs for robotgo and fyne
RUN yum -y install \
libXcursor-devel \
libXrandr-devel \
libXinerama-devel \
mesa-libGL-devel \
libXtst-devel \
libpng-devel \
libxkbcommon-x11-devel

ENTRYPOINT ["scl", "enable", "devtoolset-7"]
CMD ["bash"]
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ go 1.16
require (
fyne.io/fyne v1.4.3
fyne.io/fyne/v2 v2.0.3 // indirect
github.com/go-vgo/robotgo v0.93.1 // indirect
github.com/go-vgo/robotgo v0.93.1
github.com/robotn/gohook v0.30.5
)
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"fyne.io/fyne/container"
"fyne.io/fyne/widget"
"github.com/go-vgo/robotgo"
// "github.com/go-vgo/robotgo"
hook "github.com/robotn/gohook"
)

func main() {
fmt.Println("hi!")
// robotgo.TypeStr("Hello World")
go add()
a := app.New()
w := a.NewWindow("Hello")

Expand All @@ -26,3 +27,19 @@ func main() {

w.ShowAndRun()
}

func add() {
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
robotgo.EventHook(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
fmt.Println("ctrl-shift-q")
robotgo.EventEnd()
})

fmt.Println("--- Please press w---")
robotgo.EventHook(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("omg w was pressed")
})

s := robotgo.EventStart()
<-robotgo.EventProcess(s)
}

0 comments on commit 1cd7943

Please sign in to comment.