diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca94840..3cc1211 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,152 +1,110 @@ name: CI +on: + push: + branches: [main] + pull_request: + branches: [main] + permissions: contents: read -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +env: + GO_VERSION: "1.25.0" + GOLANGCI_VERSION: v2.12.2 + GOVULN_VERSION: v1.1.4 + GORELEASER_VERSION: v2.5.0 + TASK_VERSION: v3.40.0 jobs: - check: - name: Lint, fmt-check, and tests + lint: + name: Lint & format runs-on: ubuntu-latest steps: - - name: Check out code - uses: actions/checkout@v6 + - uses: actions/checkout@v4.2.2 - - name: Set up Go - uses: actions/setup-go@v6 + - uses: actions/setup-go@v5.1.0 with: - go-version: 'stable' + go-version: ${{ env.GO_VERSION }} + cache: true - - name: Cache Go modules - uses: actions/cache@v5 + - uses: arduino/setup-task@v2.0.0 with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + version: ${{ env.TASK_VERSION }} + repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run gofmt (check) - run: | - echo "Checking formatting with gofmt..." - fmt_output=$(gofmt -l . || true) - if [ -n "$fmt_output" ]; then - echo "The following files need formatting:" - echo "$fmt_output" - echo "Run 'gofmt -w .' to fix." - exit 1 - fi + - name: Format check + run: task fmt:check - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v9 + - name: Vet + run: task vet + + - uses: golangci/golangci-lint-action@v9.2.1 with: - version: latest + version: ${{ env.GOLANGCI_VERSION }} args: --timeout=5m ./... - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + test: + name: Test (race) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.2.2 + + - uses: actions/setup-go@v5.1.0 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - uses: arduino/setup-task@v2.0.0 + with: + version: ${{ env.TASK_VERSION }} + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: | - go test -race ./... -v - - build: - name: Build binaries + run: task test + + vuln: + name: govulncheck runs-on: ubuntu-latest - strategy: - matrix: - include: - - goos: linux - goarch: amd64 - cgo: 0 - - goos: darwin - goarch: arm64 - cgo: 0 - - goos: android - goarch: arm64 - cgo: 1 - api: 21 - - goos: android - goarch: arm - cgo: 1 - api: 21 - # you can add more (android/arm, windows, etc.) later - steps: - - name: Check out code - uses: actions/checkout@v6 + - uses: actions/checkout@v4.2.2 + + - uses: actions/setup-go@v5.1.0 with: - fetch-tags: true + go-version: ${{ env.GO_VERSION }} + cache: true - - name: Set up Go - uses: actions/setup-go@v6 + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@${{ env.GOVULN_VERSION }} + + - run: govulncheck ./... + + build-snapshot: + name: Snapshot build (all targets) + runs-on: ubuntu-latest + needs: [lint, test] + steps: + - uses: actions/checkout@v4.2.2 with: - go-version: 'stable' + fetch-depth: 0 - # Install Android NDK for android rows and expose ndk-path output - - name: Setup Android NDK - if: matrix.goos == 'android' - id: setup-ndk - uses: nttld/setup-ndk@v1 + - uses: actions/setup-go@v5.1.0 with: - ndk-version: r26d - add-to-path: false + go-version: ${{ env.GO_VERSION }} + cache: true - - name: Build - env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - CGO_ENABLED: ${{ matrix.cgo }} - ANDROID_API: ${{ matrix.api }} - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} - run: | - echo "Building for $GOOS/$GOARCH (CGO_ENABLED=$CGO_ENABLED)" - - # If this is an Android build, point CC at the NDK toolchain clang - if [ "$GOOS" = "android" ]; then - if [ -z "$ANDROID_NDK_HOME" ]; then - echo "ANDROID_NDK_HOME is not set – did setup-ndk run?" - exit 1 - fi - - TOOLCHAIN_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" - - if [ "$GOARCH" = "arm64" ]; then - export CC="$TOOLCHAIN_BIN/aarch64-linux-android${ANDROID_API}-clang" - elif [ "$GOARCH" = "arm" ]; then - export CC="$TOOLCHAIN_BIN/armv7a-linux-androideabi${ANDROID_API}-clang" - else - echo "Unsupported ANDROID GOARCH=$GOARCH" - exit 1 - fi - - echo "Using Android NDK CC=$CC" - fi - - mkdir -p dist - - ext="" - if [ "$GOOS" = "windows" ]; then - ext=".exe" - fi - - GOOS=$GOOS GOARCH=$GOARCH \ - go build -ldflags "-s -w -checklinkname=0" -trimpath \ - -o "dist/client-${GOOS}-${GOARCH}${ext}" \ - ./cmd/client - - GOOS=$GOOS GOARCH=$GOARCH \ - go build -ldflags "-s -w -checklinkname=0" -trimpath \ - -o "dist/server-${GOOS}-${GOARCH}${ext}" \ - ./cmd/server - - - name: Upload artifact - uses: actions/upload-artifact@v6 + - uses: goreleaser/goreleaser-action@v6.1.0 with: - name: good-turn-${{ matrix.goos }}-${{ matrix.goarch }} - path: dist/** + distribution: goreleaser + version: ${{ env.GORELEASER_VERSION }} + args: release --snapshot --clean --skip=publish,sign,docker,announce + + - uses: actions/upload-artifact@v4.4.3 + with: + name: snapshot-dist + path: dist/ + retention-days: 7 diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml deleted file mode 100644 index 2eee1c7..0000000 --- a/.github/workflows/issues.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: "Close Stale Issues" -on: - schedule: - - cron: "0 0 * * 3" - workflow_dispatch: - -jobs: - stale: - permissions: - issues: write - runs-on: ubuntu-latest - steps: - - uses: actions/stale@997185467fa4f803885201cee163a9f38240193d # v10 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: > - Привет! 👋 -

- Данный issue давно не обновлялся. Если в течение недели здесь не будет больше активности, issue будет закрыт. -

- Спасибо! - close-issue-message: "Issue был закрыт из-за отсутствия активности." - days-before-stale: 120 - days-before-close: 7 - operations-per-run: 1000 - ascending: true - enable-statistics: true - stale-issue-label: "Stale" diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..58a7472 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,23 @@ +name: Release Please + +on: + push: + branches: [main] + +permissions: + contents: write + pull-requests: write + +concurrency: + group: release-please-${{ github.ref }} + cancel-in-progress: false + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4.1.3 + with: + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d4c0e2..7a00c81 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,345 +1,50 @@ name: Release -permissions: - contents: read - on: push: - branches: - - main - workflow_dispatch: + tags: + - 'v*.*.*' + +permissions: + contents: write + packages: write + +env: + GO_VERSION: "1.25.0" + GORELEASER_VERSION: v2.5.0 jobs: - build: - name: Build binaries + goreleaser: + name: GoReleaser runs-on: ubuntu-latest - strategy: - matrix: - include: - - goos: linux - goarch: amd64 - cgo: 0 - - goos: linux - goarch: arm64 - cgo: 0 - - goos: linux - goarch: 386 - cgo: 0 - - goos: linux - goarch: arm - goarm: "7" - cgo: 0 - - goos: linux - goarch: mipsle - gomips: softfloat - cgo: 0 - - goos: linux - goarch: mips - gomips: softfloat - cgo: 0 - - goos: linux - goarch: mips64le - gomips: softfloat - cgo: 0 - - goos: linux - goarch: riscv64 - cgo: 0 - - goos: darwin - goarch: amd64 - cgo: 0 - - goos: darwin - goarch: arm64 - cgo: 0 - - goos: windows - goarch: amd64 - cgo: 0 - - goos: windows - goarch: arm64 - cgo: 0 - - goos: windows - goarch: 386 - cgo: 0 - - goos: android - goarch: arm64 - cgo: 1 - api: 21 - - goos: android - goarch: arm - cgo: 1 - api: 21 - - goos: freebsd - goarch: amd64 - cgo: 0 - steps: - - name: Check out code - uses: actions/checkout@v6 - - - name: Set up Go - uses: actions/setup-go@v6 - with: - go-version: "stable" - - # Install Android NDK only for android rows - - name: Setup Android NDK - if: matrix.goos == 'android' - id: setup-ndk - uses: nttld/setup-ndk@v1 - with: - ndk-version: r26d - add-to-path: false - - - name: Build - env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - GOMIPS: ${{ matrix.gomips }} - GOARM: ${{ matrix.goarm }} - CGO_ENABLED: ${{ matrix.cgo }} - ANDROID_API: ${{ matrix.api }} - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} - VERSION: ${{ github.ref_name }} - run: | - echo "Building for $GOOS/$GOARCH${GOARM:+/arm$GOARM} (CGO_ENABLED=$CGO_ENABLED)" - - if [ "$GOOS" = "android" ]; then - if [ -z "$ANDROID_NDK_HOME" ]; then - echo "ANDROID_NDK_HOME is not set – did setup-ndk run?" - exit 1 - fi - - TOOLCHAIN_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" - - if [ "$GOARCH" = "arm64" ]; then - export CC="$TOOLCHAIN_BIN/aarch64-linux-android${ANDROID_API}-clang" - elif [ "$GOARCH" = "arm" ]; then - export CC="$TOOLCHAIN_BIN/armv7a-linux-androideabi${ANDROID_API}-clang" - else - echo "Unsupported ANDROID GOARCH=$GOARCH" - exit 1 - fi - - echo "Using Android NDK CC=$CC" - fi - - mkdir -p dist - - # Set extension for windows - if [ "${GOOS}" = "windows" ]; then - EXT=.exe - else - EXT= - fi - - GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM GOMIPS=$GOMIPS \ - go build -ldflags "-s -w -checklinkname=0" -trimpath \ - -o "dist/client-${GOOS}-${GOARCH}${EXT}" \ - ./cmd/client - - GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM GOMIPS=$GOMIPS \ - go build -ldflags "-s -w -checklinkname=0" -trimpath \ - -o "dist/server-${GOOS}-${GOARCH}${EXT}" \ - ./cmd/server - - - name: Upload artifact - uses: actions/upload-artifact@v6 - with: - name: good-turn-${{ matrix.goos }}-${{ matrix.goarch }} - path: dist/** - - release: - name: Create GitHub Release - needs: build - runs-on: ubuntu-latest - outputs: - should_release: ${{ steps.meta.outputs.should_release }} - tag_name: ${{ steps.meta.outputs.tag_name }} - permissions: - contents: write - steps: - - name: Check out code - uses: actions/checkout@v6 + - uses: actions/checkout@v4.2.2 with: fetch-depth: 0 - fetch-tags: true - - name: Download build artifacts - uses: actions/download-artifact@v7 + - uses: actions/setup-go@v5.1.0 with: - path: dist + go-version: ${{ env.GO_VERSION }} + cache: true - - name: Prepare release metadata - id: meta - run: | - LATEST_TAG="$(git tag -l | grep -E '^(v)?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1 || true)" - PREFIX="" - BASE_VERSION="$LATEST_TAG" + - uses: docker/setup-qemu-action@v3.2.0 - if [ -z "$LATEST_TAG" ]; then - BASE_VERSION="0.0.0" - elif [ "${LATEST_TAG#v}" != "$LATEST_TAG" ]; then - PREFIX="v" - BASE_VERSION="${LATEST_TAG#v}" - fi + - uses: docker/setup-buildx-action@v3.7.1 - IFS=. read -r MAJOR MINOR PATCH <<< "$BASE_VERSION" - - if [ -n "$LATEST_TAG" ]; then - RANGE="$LATEST_TAG..HEAD" - else - RANGE="HEAD" - fi - - COMMITS="$(git log --no-merges --format='%s' "$RANGE")" - BUMP="" - - if printf '%s\n' "$COMMITS" | grep -Eiq '^break([(:! ]|$)'; then - BUMP="major" - MAJOR=$((MAJOR + 1)) - MINOR=0 - PATCH=0 - elif printf '%s\n' "$COMMITS" | grep -Eiq '^(feat|refactor)([(:! ]|$)'; then - BUMP="minor" - MINOR=$((MINOR + 1)) - PATCH=0 - elif printf '%s\n' "$COMMITS" | grep -Eiq '^fix([(:! ]|$)'; then - BUMP="patch" - PATCH=$((PATCH + 1)) - fi - - NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}" - NEXT_TAG="${PREFIX}${NEXT_VERSION}" - - { - echo "previous_tag=$LATEST_TAG" - echo "range=$RANGE" - echo "bump=$BUMP" - echo "should_release=$([ -n "$BUMP" ] && echo true || echo false)" - echo "tag_name=$NEXT_TAG" - echo "release_name=$NEXT_TAG" - echo "body_path=release-notes.md" - } >> "$GITHUB_OUTPUT" - - - name: Generate release notes from commit messages - id: notes - if: steps.meta.outputs.should_release == 'true' - env: - PREVIOUS_TAG: ${{ steps.meta.outputs.previous_tag }} - NEXT_TAG: ${{ steps.meta.outputs.tag_name }} - BUMP: ${{ steps.meta.outputs.bump }} - RANGE: ${{ steps.meta.outputs.range }} - run: | - strip_prefix() { - sed -E 's/^(feat|fix|break|refactor)([(!:]|[[:space:]])+[[:space:]]*//I' - } - - FEATURES="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^feat([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)" - REFACTORS="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^refactor([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)" - FIXES="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^fix([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)" - BREAKING="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^break([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)" - - { - echo "body_path=release-notes.md" - } >> "$GITHUB_OUTPUT" - - { - if [ -n "$BREAKING" ]; then - echo "### Breaking Changes" - echo - printf '%s\n' "$BREAKING" | sed 's/^/- /' - echo - fi - - if [ -n "$FEATURES" ]; then - echo "### Features" - echo - printf '%s\n' "$FEATURES" | sed 's/^/- /' - echo - fi - - if [ -n "$REFACTORS" ]; then - echo "### Refactoring" - echo - printf '%s\n' "$REFACTORS" | sed 's/^/- /' - echo - fi - - if [ -n "$FIXES" ]; then - echo "### Bug Fixes" - echo - printf '%s\n' "$FIXES" | sed 's/^/- /' - echo - fi - } > release-notes.md - - - name: Create Release - if: steps.meta.outputs.should_release == 'true' - uses: softprops/action-gh-release@v2 - with: - # upload every file in dist/ including nested files - files: | - dist/** - tag_name: ${{ steps.meta.outputs.tag_name }} - target_commitish: ${{ github.sha }} - name: ${{ steps.meta.outputs.release_name }} - body_path: ${{ steps.meta.outputs.body_path }} - overwrite_files: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Skip release when no semantic commit is found - if: steps.meta.outputs.should_release != 'true' - run: | - echo "No new semantic release created." - echo "Add a commit starting with break, feat, fix, or refactor after the latest tag." - - docker: - name: Publish Docker image - needs: release - if: needs.release.outputs.should_release == 'true' - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Check out code - uses: actions/checkout@v6 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Prepare image name - id: image - env: - REPOSITORY: ${{ github.repository }} - run: | - echo "name=ghcr.io/$(echo "$REPOSITORY" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" - - - name: Log in to GitHub Container Registry - uses: docker/login-action@v4 + - name: Log in to GHCR + uses: docker/login-action@v3.3.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v6 - with: - images: ${{ steps.image.outputs.name }} - tags: | - type=raw,value=latest - type=raw,value=${{ needs.release.outputs.tag_name }} + - name: Install syft (SBOM) + uses: anchore/sbom-action/download-syft@v0.17.7 - - name: Build and push Docker image - uses: docker/build-push-action@v7 + - uses: goreleaser/goreleaser-action@v6.1.0 with: - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + distribution: goreleaser + version: ${{ env.GORELEASER_VERSION }} + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..eb2ecab --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,199 @@ +# GoReleaser config: https://goreleaser.com +version: 2 + +project_name: btp + +before: + hooks: + - go mod download + +builds: + # Standard client/server builds — pure Go, no CGO. + - id: client + main: ./cmd/client + binary: client + flags: + - -trimpath + ldflags: + - -s -w -checklinkname=0 -X main.version={{.Version}} + env: + - CGO_ENABLED=0 + targets: + - linux_amd64 + - linux_arm64 + - linux_386 + - linux_arm_7 + - linux_mipsle_softfloat + - linux_mips_softfloat + - linux_mips64le_softfloat + - linux_riscv64 + - darwin_amd64 + - darwin_arm64 + - windows_amd64 + - windows_arm64 + - windows_386 + - freebsd_amd64 + + - id: server + main: ./cmd/server + binary: server + flags: + - -trimpath + ldflags: + - -s -w -checklinkname=0 -X main.version={{.Version}} + env: + - CGO_ENABLED=0 + targets: + - linux_amd64 + - linux_arm64 + - linux_386 + - linux_arm_7 + - linux_mipsle_softfloat + - linux_mips_softfloat + - linux_mips64le_softfloat + - linux_riscv64 + - darwin_amd64 + - darwin_arm64 + - windows_amd64 + - windows_arm64 + - windows_386 + - freebsd_amd64 + + # Android client only. Pure Go (CGO=0), packaged as native .so name + # for use as Android native library (JNI / standalone shipment). + - id: client-android + main: ./cmd/client + binary: libvkturn2.so + no_unique_dist_dir: false + flags: + - -trimpath + ldflags: + - -s -w -checklinkname=0 -X main.version={{.Version}} + env: + - CGO_ENABLED=0 + targets: + - android_arm64 + - android_arm + +archives: + # Default archives for non-Android platforms: tar.gz / zip with bundled binary. + - id: default + ids: + - client + - server + name_template: >- + {{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }} + {{- with .Arm }}v{{ . }}{{ end }} + {{- with .Mips }}-{{ . }}{{ end }} + format_overrides: + - goos: windows + formats: [zip] + files: + - LICENSE* + - README* + + # Android: ship the .so binary directly (no archive wrapper), with + # arch suffix so arm64 and arm coexist on the release page. + - id: android + ids: + - client-android + formats: [binary] + name_template: "libvkturn2-{{ .Version }}-android-{{ .Arch }}" + +checksum: + name_template: checksums.txt + +sboms: + - artifacts: archive + +snapshot: + version_template: "{{ incpatch .Version }}-snapshot-{{ .ShortCommit }}" + +changelog: + use: github + sort: asc + groups: + - title: "Breaking Changes" + regexp: '^.*?break(\(.+?\))??!?:.+$' + order: 0 + - title: "Features" + regexp: '^.*?feat(\(.+?\))??!?:.+$' + order: 10 + - title: "Bug Fixes" + regexp: '^.*?fix(\(.+?\))??!?:.+$' + order: 20 + - title: "Performance" + regexp: '^.*?perf(\(.+?\))??!?:.+$' + order: 30 + - title: "Refactoring" + regexp: '^.*?refactor(\(.+?\))??!?:.+$' + order: 40 + - title: "Other" + order: 999 + filters: + exclude: + - '^docs:' + - '^test:' + - '^chore:' + - '^ci:' + - '^style:' + - 'Merge pull request' + - 'Merge branch' + +release: + github: + owner: samosvalishe + name: btp + prerelease: auto + mode: replace + draft: false + name_template: "{{ .ProjectName }} {{ .Version }}" + +dockers: + - id: server-amd64 + ids: + - server + image_templates: + - "ghcr.io/samosvalishe/btp:{{ .Version }}-amd64" + dockerfile: Dockerfile.goreleaser + use: buildx + goos: linux + goarch: amd64 + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.source=https://github.com/samosvalishe/btp" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.created={{ .Date }}" + extra_files: + - docker/entrypoint.sh + + - id: server-arm64 + ids: + - server + image_templates: + - "ghcr.io/samosvalishe/btp:{{ .Version }}-arm64" + dockerfile: Dockerfile.goreleaser + use: buildx + goos: linux + goarch: arm64 + build_flag_templates: + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.source=https://github.com/samosvalishe/btp" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.created={{ .Date }}" + extra_files: + - docker/entrypoint.sh + +docker_manifests: + - name_template: "ghcr.io/samosvalishe/btp:{{ .Version }}" + image_templates: + - "ghcr.io/samosvalishe/btp:{{ .Version }}-amd64" + - "ghcr.io/samosvalishe/btp:{{ .Version }}-arm64" + + - name_template: "ghcr.io/samosvalishe/btp:latest" + skip_push: "{{ .Prerelease }}" + image_templates: + - "ghcr.io/samosvalishe/btp:{{ .Version }}-amd64" + - "ghcr.io/samosvalishe/btp:{{ .Version }}-arm64" diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..e18ee07 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..41ccc72 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to this project are documented here. + +This file is maintained automatically by +[Release Please](https://github.com/googleapis/release-please) based on +[Conventional Commits](https://www.conventionalcommits.org/). diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 9b945c9..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM golang:1.25-alpine AS builder - -WORKDIR /build - -COPY . . -RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o server ./cmd/server - -FROM alpine:3.23 - -RUN apk add --no-cache ca-certificates tzdata - -WORKDIR /app - -COPY docker/entrypoint.sh . -COPY --from=builder /build/server . -RUN sed -i 's/\r$//' entrypoint.sh && chmod +x entrypoint.sh - -EXPOSE 56000/udp -EXPOSE 56000/tcp - -ENTRYPOINT ["./entrypoint.sh"] diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..ab9a3b6 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,20 @@ +# Thin runtime image. Built by GoReleaser using a pre-compiled server binary. +# See .goreleaser.yaml (dockers section) for the build context. +FROM alpine:3.23 + +RUN apk add --no-cache ca-certificates tzdata + +WORKDIR /app + +# GoReleaser places the server binary at the build root, and any files +# listed in `extra_files` (entrypoint.sh) are also placed in the context root. +COPY server /app/server +COPY docker/entrypoint.sh /app/entrypoint.sh + +RUN sed -i 's/\r$//' /app/entrypoint.sh \ + && chmod +x /app/entrypoint.sh /app/server + +EXPOSE 56000/udp +EXPOSE 56000/tcp + +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/README.md b/README.md index d840141..29b6ff1 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,62 @@ ## О проекте -**btp** - туннель UDP/TCP через TURN-реле VK Calls. Клиент берёт временные TURN-учётки из ссылки на звонок и гонит ваш -трафик (WireGuard, Xray/VLESS) до сервера на VPS поверх DTLS. +**btp** — туннель UDP/TCP через TURN-реле VK Calls. Клиент берёт временные TURN-учётки из ссылки на звонок и гонит ваш трафик (WireGuard, Xray/VLESS) до сервера на VPS поверх DTLS. ## Быстрый старт +См. [docs/quickstart.md](docs/quickstart.md). Полная документация — в [docs/](docs/README.md). +## Разработка -
+### Зависимости + +- **Go** ≥ 1.25 — `https://go.dev/dl/` +- **Task** (runner) — `go install github.com/go-task/task/v3/cmd/task@v3.40.0` или `winget install Task.Task` / `brew install go-task` + +Остальные dev-инструменты (`golangci-lint`, `govulncheck`, `goimports`, `goreleaser`) ставит сам Task: + +```bash +task tools:install +``` + +### Команды + +```bash +task # список доступных задач +task build # собрать client + server в dist/ для текущего хоста +task build:all # кросс-сборка всех target через goreleaser snapshot +task test # go test -race +task test:cover # тесты + покрытие → cover.html +task lint # golangci-lint +task fmt # gofmt + goimports (форматирование) +task fmt:check # проверить форматирование (используется в CI) +task vet # go vet +task vuln # govulncheck +task ci # полный набор: fmt:check + vet + lint + test + vuln +task tidy # go mod tidy +task clean # удалить dist/, cover.out, cover.html +``` + +### Релизы + +Авто-релизы через [Release Please](https://github.com/googleapis/release-please) + [GoReleaser](https://goreleaser.com). + +[Conventional Commits](https://www.conventionalcommits.org/): + +- `feat: ...` — minor bump +- `fix: ...` / `perf: ...` — patch bump +- `break: ...` (или `feat!:`) — major bump +- `refactor:`, `docs:`, `test:`, `chore:`, `ci:`, `style:` — в CHANGELOG не попадают (либо группа Refactoring) + +Поток: push в `main` → Release Please откроет PR `chore(main): release X.Y.Z` с обновлённым `CHANGELOG.md` → merge PR → тег `vX.Y.Z` → GoReleaser выпускает релиз (бинари + Docker image на GHCR). + +Pre-release: создать тег вручную `git tag v0.X.Y-rc.1 && git push --tags`. GoReleaser детектит автоматически (`latest` Docker тег не обновляется). --- +
+ Telegram канал: [Free Turn](https://t.me/+5BdkU4q_CGQyNTdi) -
\ No newline at end of file +
diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..86fe491 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,95 @@ +version: '3' + +vars: + BINARIES: client server + VERSION: + sh: git describe --tags --always --dirty 2>/dev/null || echo dev + LDFLAGS: -s -w -checklinkname=0 -X main.version={{.VERSION}} + GOLANGCI_VERSION: v2.12.2 + GOVULN_VERSION: v1.1.4 + GORELEASER_VERSION: v2.5.0 + +tasks: + default: + cmds: + - task --list + silent: true + + build: + desc: Build host binaries (client + server) to dist/ + cmds: + - for: { var: BINARIES } + cmd: go build -ldflags "{{.LDFLAGS}}" -trimpath -o dist/{{.ITEM}} ./cmd/{{.ITEM}} + + build:all: + desc: Cross-compile all targets via goreleaser snapshot + cmds: + - goreleaser release --snapshot --clean --skip=publish,sign + + test: + desc: Run unit tests with race detector + cmds: + - go test -race -count=1 ./... + + test:cover: + desc: Run tests with coverage report (cover.html) + cmds: + - go test -race -count=1 -coverprofile=cover.out ./... + - go tool cover -html=cover.out -o cover.html + + lint: + desc: Run golangci-lint + cmds: + - golangci-lint run --timeout=5m ./... + + fmt: + desc: Format code (gofmt + goimports) + cmds: + - gofmt -w . + - goimports -w . + + fmt:check: + desc: Verify formatting (fails on diff) + cmds: + - cmd: | + out=$(gofmt -l .) + if [ -n "$out" ]; then + echo "Files need formatting:" + echo "$out" + exit 1 + fi + + vet: + desc: Run go vet + cmds: + - go vet ./... + + vuln: + desc: Run govulncheck + cmds: + - govulncheck ./... + + tidy: + desc: Tidy go.mod / go.sum + cmds: + - go mod tidy + + ci: + desc: Run full CI suite locally (fmt-check, vet, lint, test, vuln) + deps: [fmt:check, vet, lint, test, vuln] + + tools:install: + desc: Install dev tools (golangci-lint, govulncheck, goreleaser, goimports) + cmds: + - go install golang.org/x/tools/cmd/goimports@latest + - go install golang.org/x/vuln/cmd/govulncheck@{{.GOVULN_VERSION}} + - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{{.GOLANGCI_VERSION}} + - go install github.com/goreleaser/goreleaser/v2@{{.GORELEASER_VERSION}} + + clean: + desc: Remove build artifacts + cmds: + - cmd: rm -rf dist/ cover.out cover.html + platforms: [linux, darwin] + - cmd: powershell -Command "Remove-Item -Recurse -Force dist,cover.out,cover.html -ErrorAction SilentlyContinue" + platforms: [windows] diff --git a/cmd/client/main.go b/cmd/client/main.go index 49f95df..21558be 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -25,6 +25,9 @@ import ( "github.com/samosvalishe/btp/internal/wire/srtpmimicry" ) +// version is populated at build time via -ldflags "-X main.version=...". +var version = "dev" + const dtlsHandshakeConcurrency = 3 // manualCaptchaSolver связывает контракт vkauth.ManualSolveFunc @@ -49,6 +52,7 @@ func main() { } logger := logx.New(cfg.Log.Debug) + logger.Infof("btp client version=%s", version) captcha.SetLogger(logger) manualcaptcha.SetLogger(logger) dnsdial.SetLogger(logger) diff --git a/cmd/server/main.go b/cmd/server/main.go index ff02b9a..9ee9900 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -21,6 +21,9 @@ import ( "github.com/pion/dtls/v3" ) +// version is populated at build time via -ldflags "-X main.version=...". +var version = "dev" + func main() { cfg, err := config.ParseServer(os.Args[1:], os.Stderr) if err != nil { @@ -28,6 +31,7 @@ func main() { log.Fatalf("%v", err) } logger := logx.New(cfg.Log.Debug) + logger.Infof("btp server version=%s", version) if cfg.Obf.GenKey { key, gerr := srtpmimicry.GenKeyHex() diff --git a/docs/README.md b/docs/README.md index 6135861..f7b4981 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,6 +5,5 @@ - [Флаги клиента и сервера](flags.md) - [Развёртывание: systemd, Docker](deploy.md) - [Мобильные: Android (Termux), iOS (iSH)](mobile.md) -- [Сборка из исходников](build.md) - [Решение проблем](troubleshooting.md) - [Глоссарий](glossary.md) diff --git a/docs/build.md b/docs/build.md deleted file mode 100644 index 47387cd..0000000 --- a/docs/build.md +++ /dev/null @@ -1,76 +0,0 @@ -# Сборка - -Нужен Go 1.24.x. - -```bash -go build -o client ./cmd/client -go build -o server ./cmd/server -go test ./... -``` - -## Кросс-Сборка - -**Linux amd64:** - -```bash -GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o server-linux-amd64 ./cmd/server -GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o client-linux-amd64 ./cmd/client -``` - -**Android arm64 как `.so`** (упаковка в приложение, PowerShell): - -```powershell -$env:GOOS="android"; $env:GOARCH="arm64"; $env:CGO_ENABLED="0" -go build -ldflags="-s -w -checklinkname=0" -trimpath -o libvkturn.so .\cmd\client -``` - -Bash: - -```bash -GOOS=android GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-s -w -checklinkname=0" -trimpath -o libvkturn.so ./cmd/client -``` - -**Linux arm64 как `.so`** (в обход NDK, ABI совпадает): - -```bash -GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-s -w -checklinkname=0" -trimpath -o libvkturn.so ./cmd/client -``` - -**Linux amd64 как `.so`:** - -```bash -GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w -checklinkname=0" -trimpath -o libvkturn-client.so ./cmd/client -GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w -checklinkname=0" -trimpath -o libvkturn-server.so ./cmd/server -``` - -> Все `.so` выше — обычные ELF под `.so`-именем (`CGO_ENABLED=0`, не настоящий shared library). Настоящий `c-shared` — `CGO_ENABLED=1` + NDK toolchain (см. `.github/workflows/release.yml`). - -**Windows amd64:** - -```powershell -$env:GOOS="windows"; $env:GOARCH="amd64"; $env:CGO_ENABLED="0" -go build -ldflags="-s -w -checklinkname=0" -trimpath -o client-windows-amd64.exe ./cmd/client -go build -ldflags="-s -w -checklinkname=0" -trimpath -o server-windows-amd64.exe ./cmd/server -``` - -**Windows arm64:** - -```powershell -$env:GOOS="windows"; $env:GOARCH="arm64"; $env:CGO_ENABLED="0" -go build -ldflags="-s -w -checklinkname=0" -trimpath -o client-windows-arm64.exe ./cmd/client -go build -ldflags="-s -w -checklinkname=0" -trimpath -o server-windows-arm64.exe ./cmd/server -``` - -**macOS amd64 (Intel):** - -```bash -GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o client-darwin-amd64 ./cmd/client -GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o server-darwin-amd64 ./cmd/server -``` - -**macOS arm64 (Apple Silicon):** - -```bash -GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o client-darwin-arm64 ./cmd/client -GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o server-darwin-arm64 ./cmd/server -``` diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..2f1cc29 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "packages": { + ".": { + "release-type": "go", + "package-name": "btp", + "include-component-in-tag": false, + "include-v-in-tag": true, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "draft": false, + "prerelease": false, + "changelog-path": "CHANGELOG.md", + "changelog-sections": [ + { "type": "feat", "section": "Features" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "perf", "section": "Performance" }, + { "type": "refactor", "section": "Refactoring" }, + { "type": "break", "section": "Breaking Changes" }, + { "type": "docs", "section": "Documentation", "hidden": true }, + { "type": "chore", "section": "Chores", "hidden": true }, + { "type": "test", "section": "Tests", "hidden": true }, + { "type": "ci", "section": "CI", "hidden": true }, + { "type": "style", "section": "Style", "hidden": true } + ] + } + }, + "release-search-depth": 50, + "commit-search-depth": 500, + "separate-pull-requests": false, + "plugins": [] +}