Skip to content

Commit feed211

Browse files
CI
1 parent f23c98c commit feed211

File tree

13 files changed

+1215
-216
lines changed

13 files changed

+1215
-216
lines changed

.github/workflows/build.yml

Lines changed: 129 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,148 @@
1-
name: build
1+
name: Build and Release
22

33
on:
4-
pull_request:
54
push:
6-
# run only against tags
5+
branches: [ main ]
76
tags:
8-
- "*"
7+
- 'v*.*.*'
8+
pull_request:
9+
branches: [ main ]
10+
workflow_dispatch: # Allow manual trigger
911

1012
permissions:
1113
contents: write
1214

1315
jobs:
1416
build:
15-
runs-on: ubuntu-latest
17+
name: Build
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
include:
22+
# Linux builds
23+
- os: ubuntu-latest
24+
goos: linux
25+
goarch: amd64
26+
cgo: '1'
27+
target: go-pcap2socks-linux-amd64
28+
- os: ubuntu-latest
29+
goos: linux
30+
goarch: arm64
31+
cgo: '1'
32+
cc: aarch64-linux-gnu-gcc
33+
target: go-pcap2socks-linux-arm64
34+
# macOS builds
35+
- os: macos-latest
36+
goos: darwin
37+
goarch: arm64
38+
cgo: '1'
39+
target: go-pcap2socks-darwin-arm64
40+
# Windows build
41+
- os: windows-latest
42+
goos: windows
43+
goarch: amd64
44+
cgo: '0'
45+
target: go-pcap2socks-windows-amd64.exe
46+
1647
steps:
1748
- uses: actions/checkout@v4
1849
with:
1950
fetch-depth: 0
51+
2052
- uses: actions/setup-go@v5
2153
with:
22-
go-version: '1.23.1'
23-
- run: sudo apt-get install -y libpcap-dev
24-
- run: go mod tidy
25-
- run: go test -v ./...
26-
- uses: goreleaser/goreleaser-action@v6
54+
go-version: stable
55+
56+
- name: Install dependencies (Linux)
57+
if: matrix.os == 'ubuntu-latest'
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y libpcap-dev
61+
# Install cross-compiler for ARM64
62+
if [ "${{ matrix.goarch }}" = "arm64" ]; then
63+
sudo apt-get install -y gcc-aarch64-linux-gnu
64+
# Setup libpcap for ARM64 cross-compilation
65+
cd /tmp
66+
wget http://www.tcpdump.org/release/libpcap-1.10.1.tar.gz
67+
tar xzf libpcap-1.10.1.tar.gz
68+
cd libpcap-1.10.1
69+
export CC=aarch64-linux-gnu-gcc
70+
./configure --host=aarch64-linux --with-pcap=linux
71+
make
72+
sudo make install DESTDIR=/tmp/libpcap-arm64
73+
echo "CGO_LDFLAGS=-L/tmp/libpcap-arm64/usr/local/lib" >> $GITHUB_ENV
74+
echo "CGO_CFLAGS=-I/tmp/libpcap-arm64/usr/local/include" >> $GITHUB_ENV
75+
fi
76+
77+
- name: Install dependencies (macOS)
78+
if: matrix.os == 'macos-latest'
79+
run: brew install libpcap
80+
81+
- name: Install dependencies (Windows)
82+
if: matrix.os == 'windows-latest'
83+
run: |
84+
choco install openssl.light -y
85+
choco install make -y
86+
choco install 7zip -y
87+
curl -L "https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip" -o "C:\wpcap-sdk.zip"
88+
7z x -y "C:\wpcap-sdk.zip" -o"C:\winpcap"
89+
90+
- name: Test
91+
if: matrix.goarch == 'amd64' # Only test on native architecture
92+
run: go test -v ./...
93+
94+
- name: Build
95+
env:
96+
GOOS: ${{ matrix.goos }}
97+
GOARCH: ${{ matrix.goarch }}
98+
CGO_ENABLED: ${{ matrix.cgo }}
99+
CC: ${{ matrix.cc }}
100+
run: |
101+
go build -ldflags="-s -w" -o ${{ matrix.target }} .
102+
103+
- name: Create package
104+
shell: bash
105+
run: |
106+
VERSION=${GITHUB_REF#refs/tags/}
107+
case "$VERSION" in
108+
v*.*.*) ;;
109+
*) VERSION="dev-${GITHUB_SHA::8}" ;;
110+
esac
111+
112+
if [ "${{ matrix.goos }}" = "windows" ]; then
113+
7z a "go-pcap2socks_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.zip" "${{ matrix.target }}" README.md LICENSE install.md config.md
114+
else
115+
tar czf "go-pcap2socks_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz" "${{ matrix.target }}" README.md LICENSE install.md config.md
116+
fi
117+
118+
- name: Upload artifacts
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: go-pcap2socks-${{ matrix.goos }}-${{ matrix.goarch }}
122+
path: |
123+
go-pcap2socks_*.tar.gz
124+
go-pcap2socks_*.zip
125+
126+
release:
127+
name: Release
128+
needs: build
129+
runs-on: ubuntu-latest
130+
if: startsWith(github.ref, 'refs/tags/v')
131+
132+
steps:
133+
- name: Download artifacts
134+
uses: actions/download-artifact@v4
135+
with:
136+
path: artifacts
137+
pattern: go-pcap2socks-*
138+
merge-multiple: true
139+
140+
- name: Create Release
141+
uses: softprops/action-gh-release@v2
27142
with:
28-
distribution: goreleaser
29-
version: latest
30-
args: release --clean
143+
files: artifacts/*
144+
draft: false
145+
prerelease: false
146+
generate_release_notes: true
31147
env:
32148
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ go.work
2525
.vscode
2626
/build_assets
2727
*.zip
28-
*.tar.gz
28+
*.tar.gz
29+
30+
# Build artifacts
31+
go-pcap2socks
32+
go-pcap2socks-*
33+
go_build_*
34+
-h

.goreleaser.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

Makefile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
BINARY_NAME=go-pcap2socks
2+
VERSION=$(shell git describe --tags --always --dirty)
3+
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
4+
GOFLAGS=-ldflags="-s -w -X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
5+
GO?=go
6+
7+
# Default target
8+
.PHONY: all
9+
all: build
10+
11+
# Build for current platform
12+
.PHONY: build
13+
build:
14+
$(GO) build $(GOFLAGS) -o $(BINARY_NAME) .
15+
16+
# Platform-specific builds
17+
.PHONY: build-linux-amd64
18+
build-linux-amd64:
19+
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 $(GO) build $(GOFLAGS) -o $(BINARY_NAME)-linux-amd64 .
20+
21+
.PHONY: build-linux-arm64
22+
build-linux-arm64:
23+
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc $(GO) build $(GOFLAGS) -o $(BINARY_NAME)-linux-arm64 .
24+
25+
.PHONY: build-darwin-arm64
26+
build-darwin-arm64:
27+
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 $(GO) build $(GOFLAGS) -o $(BINARY_NAME)-darwin-arm64 .
28+
29+
.PHONY: build-windows-amd64
30+
build-windows-amd64:
31+
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(GOFLAGS) -o $(BINARY_NAME)-windows-amd64.exe .
32+
33+
# Build all platforms
34+
.PHONY: build-all
35+
build-all: build-linux-amd64 build-linux-arm64 build-darwin-arm64 build-windows-amd64
36+
37+
# Test
38+
.PHONY: test
39+
test:
40+
$(GO) test -v ./...
41+
42+
# Clean
43+
.PHONY: clean
44+
clean:
45+
rm -f $(BINARY_NAME) $(BINARY_NAME)-*
46+
rm -f *.tar.gz *.zip
47+
48+
# Install
49+
.PHONY: install
50+
install:
51+
$(GO) install $(GOFLAGS) .
52+
53+
# Format code
54+
.PHONY: fmt
55+
fmt:
56+
$(GO) fmt ./...
57+
58+
# Run linters
59+
.PHONY: lint
60+
lint:
61+
@which golangci-lint > /dev/null || echo "golangci-lint not installed"
62+
@which golangci-lint > /dev/null && golangci-lint run
63+
64+
# Package for release
65+
.PHONY: package
66+
package: clean build-all
67+
@echo "Creating release packages..."
68+
# Linux AMD64
69+
tar czf $(BINARY_NAME)_$(VERSION)_linux_amd64.tar.gz $(BINARY_NAME)-linux-amd64 README.md LICENSE install.md config.md
70+
# Linux ARM64
71+
tar czf $(BINARY_NAME)_$(VERSION)_linux_arm64.tar.gz $(BINARY_NAME)-linux-arm64 README.md LICENSE install.md config.md
72+
# Darwin ARM64
73+
tar czf $(BINARY_NAME)_$(VERSION)_darwin_arm64.tar.gz $(BINARY_NAME)-darwin-arm64 README.md LICENSE install.md config.md
74+
# Windows AMD64
75+
zip $(BINARY_NAME)_$(VERSION)_windows_amd64.zip $(BINARY_NAME)-windows-amd64.exe README.md LICENSE install.md config.md
76+
77+
.PHONY: help
78+
help:
79+
@echo "Available targets:"
80+
@echo " build - Build for current platform"
81+
@echo " build-linux-amd64 - Build for Linux AMD64"
82+
@echo " build-linux-arm64 - Build for Linux ARM64"
83+
@echo " build-darwin-arm64 - Build for macOS ARM64"
84+
@echo " build-windows-amd64- Build for Windows AMD64"
85+
@echo " build-all - Build for all platforms"
86+
@echo " test - Run tests"
87+
@echo " clean - Remove built binaries and packages"
88+
@echo " install - Install locally"
89+
@echo " fmt - Format code"
90+
@echo " lint - Run linters"
91+
@echo " package - Create release packages"
92+
@echo " help - Show this help"

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
# go-pcap2socks
22
go-pcap2socks is a proxy that redirects traffic from any device to a SOCKS5 proxy.
33

4-
go-pcap2socks functions like a router, allowing you to connect various devices such as an **XBOX**, **PlayStation (PS4, PS5)**, **Nintendo Switch**, mobile phones, printers and others to any SOCKS5 proxy server. Additionally, you can host a SOCKS5 proxy server on the same PC to use services like a VPN or a game booster/accelerator for reduced latency, you can also share a working VPN from your computer to your mobile phone.
4+
go-pcap2socks functions like a router, allowing you to connect various devices such as an **XBOX**, **PlayStation (PS4, PS5)**, **Nintendo Switch**, mobile phones, printers and others to any SOCKS5 proxy server. Additionally, you can just start go-pcap2socks with the default direct outbound to share your VPN connection to any devices on your network.
55

6-
## Dependencies
7-
For **Windows**, install [Npcap](http://www.npcap.org/) or WinPcap. If you choose Npcap, ensure to install it in "WinPcap API-compatible Mode". For **macOS**, **Linux**, and other operating systems, use libpcap.
6+
## Documentation
87

9-
## Config
10-
Config example is [here](https://github.com/DaniilSokolyuk/go-pcap2socks/blob/main/config.json)
8+
- [Installation Guide](install.md) - Instructions for installing go-pcap2socks on various platforms
9+
- [Configuration Guide](config.md) - Detailed configuration documentation with examples
10+
11+
## Quick Start
12+
13+
```bash
14+
# Install
15+
go install github.com/DaniilSokolyuk/go-pcap2socks@latest
16+
17+
# Configure
18+
go-pcap2socks config
19+
20+
# Run
21+
sudo go-pcap2socks
22+
```
23+
24+
## Troubleshooting
25+
26+
### Permission Denied
27+
- Run with `sudo` or as administrator
28+
- On macOS/Linux: `sudo go-pcap2socks`
29+
- On Windows: Run as Administrator
30+
31+
### Game Console Setup
32+
For **Nintendo Switch** and **PS5**, you need to manually set the MTU value in the console's network settings. The required MTU value is displayed when go-pcap2socks starts (shown in the console output).
1133

1234
## Credits
1335
- https://github.com/google/gvisor - TCP/IP stack

0 commit comments

Comments
 (0)