Compare commits

..

9 Commits

Author SHA1 Message Date
yusing
79327e98bd chore: update submodule goutils 2026-02-26 14:19:03 +08:00
yusing
206f69d249 chore(scripts): fix docker depedencies in refresh-compat.sh 2026-02-26 01:14:04 +08:00
yusing
3f6b09d05e chore(scripts): narrow git diff to only include go files in refresh-compat.sh 2026-02-26 01:11:41 +08:00
yusing
af68eb4b18 build: create placeholder JS files and tidy Go modules
- Add script logic to create empty placeholder files for minified JS files
  so go vet won't complain about missing files
- Run go mod tidy in root and agent directory to clean up dependencies
2026-02-26 01:03:02 +08:00
yusing
9927267149 chore: improve refresh-compat.sh with error handling and fix sed application
Add `set -euo pipefail` for strict error handling, check for clean working tree before running, and add trap for cleanup. Move sed replacements from patch file to actual changed Go files to correctly apply sonic-to-json transformations after checkout.
2026-02-26 00:46:12 +08:00
yusing
af8cddc1b2 chore: add AGENTS.md 2026-02-26 00:39:10 +08:00
yusing
c74da5cba9 build: make POST_BUILD always run 2026-02-26 00:35:44 +08:00
yusing
c23cf8ef06 ci: refactor compat branch refresh to use patch-based approach 2026-02-26 00:34:48 +08:00
yusing
733716ba2b build(cli): fix build path and unify build command
Use the shared build target for CLI binaries and upload
artifacts to GitHub releases on tag builds.
2026-02-25 14:40:06 +08:00
6 changed files with 123 additions and 29 deletions

View File

@@ -47,14 +47,20 @@ jobs:
- name: Build CLI
run: |
make CLI_BIN_PATH=bin/${{ matrix.binary_name }} build-cli
make cli=1 NAME=${{ matrix.binary_name }} build
- name: Check binary
run: |
file bin/${{ matrix.binary_name }}
- name: Upload artifact
- name: Upload
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.binary_name }}
path: bin/${{ matrix.binary_name }}
- name: Upload to release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: bin/${{ matrix.binary_name }}

View File

@@ -1,4 +1,4 @@
name: Cherry-pick into Compat
name: Refresh Compat from Main Patch
on:
push:
@@ -8,7 +8,7 @@ on:
- ".github/workflows/merge-main-into-compat.yml"
jobs:
cherry-pick:
refresh-compat:
runs-on: ubuntu-latest
permissions:
contents: write
@@ -20,20 +20,9 @@ jobs:
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Cherry-pick commits from last tag
- name: Refresh compat with single patch commit
run: |
git fetch origin compat
git checkout compat
CURRENT_TAG=${{ github.ref_name }}
PREV_TAG=$(git describe --tags --abbrev=0 $CURRENT_TAG^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found. Cherry-picking all commits up to $CURRENT_TAG"
git rev-list --reverse --no-merges $CURRENT_TAG | xargs -r git cherry-pick
else
echo "Cherry-picking commits from $PREV_TAG to $CURRENT_TAG"
git rev-list --reverse --no-merges $PREV_TAG..$CURRENT_TAG | xargs -r git cherry-pick
fi
./scripts/refresh-compat.sh
- name: Push compat
run: |
git push origin compat
git push origin compat --force

32
AGENTS.md Normal file
View File

@@ -0,0 +1,32 @@
# AGENTS.md
## Development Commands
- Build: You should not run build command.
- Test: `go test -ldflags="-checklinkname=0" ...`
## Documentation
Update package level `README.md` if exists after making significant changes.
## Go Guidelines
1. Use builtin `min` and `max` functions instead of creating custom ones
2. Prefer `for i := range 10` over `for i := 0; i < 10; i++`
3. Beware of variable shadowing when making edits
4. Use `internal/task/task.go` for lifetime management:
- `task.RootTask()` for background operations
- `parent.Subtask()` for nested tasks
- `OnFinished()` and `OnCancel()` callbacks for cleanup
5. Use `gperr "goutils/errs"` to build pretty nested errors:
- `gperr.Multiline()` for multiple operation attempts
- `gperr.NewBuilder()` to collect errors
- `gperr.NewGroup() + group.Go()` to collect errors of multiple concurrent operations
- `gperr.PrependSubject()` to prepend subject to errors
6. Use `github.com/puzpuzpuz/xsync/v4` for lock-free thread safe maps
7. Use `goutils/synk` to retrieve and put byte buffer
## Testing
- Run scoped tests instead of `./...`
- Use `testify`, no manual assertions.

View File

@@ -17,15 +17,22 @@ endif
LDFLAGS = -X github.com/yusing/goutils/version.version=${VERSION} -checklinkname=0
PACKAGE ?= ./cmd
ifeq ($(agent), 1)
NAME = godoxy-agent
PWD = ${shell pwd}/agent
else ifeq ($(socket-proxy), 1)
NAME = godoxy-socket-proxy
PWD = ${shell pwd}/socket-proxy
else ifeq ($(cli), 1)
NAME = godoxy-cli
PWD = ${shell pwd}/cmd/cli
PACKAGE = .
else
NAME = godoxy
PWD = ${shell pwd}
godoxy = 1
endif
ifeq ($(trace), 1)
@@ -58,7 +65,6 @@ endif
BUILD_FLAGS += -tags '$(GO_TAGS)' -ldflags='$(LDFLAGS)'
BIN_PATH := $(shell pwd)/bin/${NAME}
CLI_BIN_PATH ?= $(shell pwd)/bin/godoxy-cli
export NAME
export CGO_ENABLED
@@ -76,7 +82,11 @@ endif
# CAP_NET_BIND_SERVICE: permission for binding to :80 and :443
POST_BUILD = $(SETCAP_CMD) CAP_NET_BIND_SERVICE=+ep ${BIN_PATH};
POST_BUILD = echo;
ifeq ($(godoxy), 1)
POST_BUILD += $(SETCAP_CMD) CAP_NET_BIND_SERVICE=+ep ${BIN_PATH};
endif
ifeq ($(docker), 1)
POST_BUILD += mkdir -p /app && mv ${BIN_PATH} /app/run;
endif
@@ -133,13 +143,18 @@ minify-js:
done \
fi
build: minify-js
build:
@if [ "${godoxy}" = "1" ]; then \
make minify-js; \
elif [ "${cli}" = "1" ]; then \
make gen-cli; \
fi
mkdir -p $(shell dirname ${BIN_PATH})
go build -C ${PWD} ${BUILD_FLAGS} -o ${BIN_PATH} ./cmd
go build -C ${PWD} ${BUILD_FLAGS} -o ${BIN_PATH} ${PACKAGE}
${POST_BUILD}
run: minify-js
cd ${PWD} && [ -f .env ] && godotenv -f .env go run ${BUILD_FLAGS} ./cmd
cd ${PWD} && [ -f .env ] && godotenv -f .env go run ${BUILD_FLAGS} ${PACKAGE}
dev:
docker compose -f dev.compose.yml $(args)
@@ -186,13 +201,10 @@ gen-api-types: gen-swagger
bunx --bun swagger-typescript-api generate --sort-types --generate-union-enums --axios --add-readonly --route-types \
--responses -o ${WEBUI_DIR}/src/lib -n api.ts -p internal/api/v1/docs/swagger.json
.PHONY: gen-cli build-cli update-wiki
gen-cli:
cd cmd/cli && go run ./gen
build-cli: gen-cli
mkdir -p $(shell dirname ${CLI_BIN_PATH})
go build -C cmd/cli -o ${CLI_BIN_PATH} .
.PHONY: gen-cli build-cli update-wiki
update-wiki:
DOCS_DIR=${DOCS_DIR} REPO_URL=${REPO_URL} bun --bun scripts/update-wiki/main.ts

Submodule goutils updated: 246c8e9ba1...4f468fdce8

55
scripts/refresh-compat.sh Executable file
View File

@@ -0,0 +1,55 @@
#!/bin/bash
set -euo pipefail
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Working tree is not clean. Commit or stash changes before running refresh-compat.sh." >&2
exit 1
fi
git fetch origin main compat
git checkout -B compat origin/compat
patch_file="$(mktemp)"
trap 'rm -f "$patch_file"' EXIT
git diff origin/main -- ':(glob)**/*.go' >"$patch_file"
git checkout -B main origin/main
git branch -D compat
git checkout -b compat
git apply "$patch_file"
mapfile -t changed_go_files < <(git diff --name-only -- '*.go')
fmt_go_files=()
for file in "${changed_go_files[@]}"; do
[ -f "$file" ] || continue
sed -i 's/sonic\./json\./g' "$file"
sed -i 's/"github.com\/bytedance\/sonic"/"encoding\/json"/g' "$file"
sed -E -i 's/\bsonic[[:space:]]+"encoding\/json"/json "encoding\/json"/g' "$file"
fmt_go_files+=("$file")
done
if [ "${#fmt_go_files[@]}" -gt 0 ]; then
gofmt -w "${fmt_go_files[@]}"
fi
# create placeholder files for minified JS files so go vet won't complain
while IFS= read -r file; do
ext="${file##*.}"
base="${file%.*}"
min_file="${base}-min.${ext}"
[ -f "$min_file" ] || : >"$min_file"
done < <(find internal/ -name '*.js' ! -name '*-min.js')
docker_version="$(
git show origin/compat:go.mod |
sed -n 's/^[[:space:]]*github.com\/docker\/docker[[:space:]]\+\(v[^[:space:]]\+\).*/\1/p' |
head -n 1
)"
if [ -n "$docker_version" ]; then
go mod edit -droprequire=github.com/docker/docker/api || true
go mod edit -droprequire=github.com/docker/docker/client || true
go mod edit -require="github.com/docker/docker@${docker_version}"
fi
go mod tidy
go mod -C agent tidy
git add -A
git commit -m "Apply compat patch"
go vet ./...
go vet -C agent ./...