Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 147 additions & 62 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,147 @@
name: CI

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]

env:
SLOW_MACHINE: 1

jobs:
unit-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
id: setup-go
with:
go-version-file: "go.mod"

- name: Download Go modules
shell: bash
if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
run: go mod download

- name: Build
run: make bins

- name: Test
run: make test

integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
test-vector: [bitcoin-cln, bitcoin-lnd, liquid-cln, liquid-lnd, misc-integration, lwk-cln, lwk-lnd]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: cachix/install-nix-action@v31
- uses: cachix/cachix-action@v16
with:
name: peerswap
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
useDaemon: true
# Switch to nix-shell for integration tests instead of nix develop.
# The 'nix develop' command can be unstable in some CI environments,
# causing issues like "clightning-1: Lost connection to the RPC socket."
# While the root cause is unclear, switching to nix-shell provides a more stable alternative for CI.
# For more context, see the issue in this failed job: https://github.com/ElementsProject/peerswap/actions/runs/16064376179/job/45336040866?pr=385
- name: Run integration tests
run: |
nix-shell --run "make test-${{matrix.test-vector}}"
name: CI

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

env:
SLOW_MACHINE: 1

jobs:
unit-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
id: setup-go
with:
go-version-file: "go.mod"

- name: Download Go modules
shell: bash
if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
run: go mod download

- name: Build
run: make bins

- name: Test
run: make test

integration-tests:
runs-on: ubuntu-latest
concurrency:
group: integration-${{ github.ref }}-${{ matrix.vector }}
cancel-in-progress: true
needs: [build-test-bins]
strategy:
fail-fast: false
matrix:
vector:
[
bitcoin_clncln,
bitcoin_mixed,
bitcoin_lndlnd,
liquid_clncln,
liquid_mixed,
liquid_lndlnd,
misc_1,
misc_2,
misc_3,
lnd,
]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Cache Go modules
id: go-cache
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download Go modules
if: ${{ steps.go-cache.outputs.cache-hit != 'true' }}
run: go mod download

# Test binaries are prebuilt and downloaded as artifact
- name: Download test binaries
uses: actions/download-artifact@v4
with:
name: test-bins
path: out/test-builds

- uses: cachix/install-nix-action@v31
- uses: cachix/cachix-action@v16
with:
name: peerswap
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
useDaemon: true
# Switch to nix-shell for integration tests instead of nix develop.
# The 'nix develop' command can be unstable in some CI environments,
# causing issues like "clightning-1: Lost connection to the RPC socket."
# While the root cause is unclear, switching to nix-shell provides a more stable alternative for CI.
# For more context, see the issue in this failed job: https://github.com/ElementsProject/peerswap/actions/runs/16064376179/job/45336040866?pr=385
- name: Run integration tests
env:
INTEGRATION_TEST_PARALLEL: "6"
SKIP_BUILD_TEST_BINS: "1"
run: |
nix-shell --run "RUN_INTEGRATION_TESTS=1 PAYMENT_RETRY_TIME=10 PEERSWAP_TEST_FILTER=$PEERSWAP_TEST_FILTER INTEGRATION_TEST_PARALLEL=$INTEGRATION_TEST_PARALLEL make test-matrix-${{ matrix.vector }}"

build-test-bins:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Cache Go modules
id: go-cache
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download Go modules
if: ${{ steps.go-cache.outputs.cache-hit != 'true' }}
run: go mod download

- name: Build test binaries
run: make test-bins

- name: Upload test binaries
uses: actions/upload-artifact@v4
with:
name: test-bins
path: out/test-builds
176 changes: 176 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
version: "2"

run:
tests: true
timeout: 5m

linters:
# Default v2 linter set options (standard/all/none/fast)
default: standard
enable:
# Critical / foundational
- staticcheck
- govet
- errcheck
- ineffassign
- unused
- errorlint
- revive
- gocritic
- makezero
- durationcheck
- nilerr
- bodyclose
- rowserrcheck
- sqlclosecheck
- noctx
- perfsprint
- sloglint
- nolintlint
- tparallel
- gosec
# Policy / helper
- depguard
- forbidigo
- copyloopvar
# Complexity / duplication (enabled for main code)
- goconst
- cyclop
- gocognit
- dupl
- unparam
- unconvert
disable:
# Linters with preference-dependent behavior; keep disabled for now
- exhaustruct
- varnamelen
- wsl
- nlreturn
- nonamedreturns
- funlen
- nakedret
- err113
- gochecknoglobals

# Test-only relaxations (disable specific linters for _test.go files)
exclusions:
rules:
- path: '(^|.*/)test/.*\.go'
linters:
- forbidigo # Allow fmt.Print / time.Sleep in tests
- revive # Ignore minor style issues inside tests
- gosec # Reduce false positives for simple test I/O
- dupl # Accept similar duplicated test cases
- gocognit # Relax complexity requirements for readability
- cyclop
- goconst # Loosen constant enforcement within tests
- funlen # Allow longer test functions
- nlreturn
- varnamelen
- wsl
- nolintlint # Allow simpler usage of //nolint in tests
- perfsprint # Relax performance-focused checks for tests
- unparam # Avoid false positives for unused parameters
- unconvert

settings:
# Detect loop variable capture issues
govet:
enable:
- loopclosure
# Block testify usage in tests (applies only to $test)
depguard:
rules:
main:
files:
- $all
- "!$test"
deny:
- pkg: syscall
desc: |
Deprecated: This package is locked down.
Callers should use the corresponding package in the golang.org/x/sys repository instead.
That is also where updates required by new systems or versions should be applied.
See https://golang.org/s/go1.4-syscall for more information.
- pkg: github.com/satori/go.uuid
desc: |
This package have vulnerability. Please use alternative uuid package such as "github.com/google/uuid".
- pkg: github.com/golang/protobuf/proto
desc: |
Deprecated: Use the "google.golang.org/protobuf/proto" package instead.
- pkg: github.com/golang/protobuf/ptypes
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/anypb" package instead.
- pkg: github.com/golang/protobuf/ptypes/any
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/anypb" package instead.
- pkg: github.com/golang/protobuf/ptypes/duration
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/durationpb" package instead.
- pkg: github.com/golang/protobuf/ptypes/empty
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/emptypb" package instead.
- pkg: github.com/golang/protobuf/ptypes/struct
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/structpb" package instead.
- pkg: github.com/golang/protobuf/ptypes/timestamp
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/timestamppb" package instead.
- pkg: github.com/golang/protobuf/ptypes/wrappers
desc: |
Deprecated: Use the "google.golang.org/protobuf/types/known/wrapperspb" package instead.
- pkg: github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap
desc: |
DO NOT USE ctxzap. Please check grpcserver/internal#LogWithFields.
- pkg: github.com/pkg/errors
desc: Should be replaced by standard lib errors package
- pkg: golang.org/x/sync/errgroup
desc: |
Use panic recoverable version github.com/kouzoh-mercoin/mercoin-core-kit/sync/recoverable or github.com/sourcegraph/conc instead.
test:
files:
- $test
deny:
- pkg: github.com/stretchr/testify
desc: |
DO NOT USE testing framework.

gocognit:
min-complexity: 20
goconst:
min-len: 3
min-occurrences: 3
dupl:
threshold: 200

revive:
rules:
- name: error-strings
- name: indent-error-flow
- name: exported
- name: package-comments
- name: redefines-builtin-id
- name: if-return
- name: superfluous-else
- name: var-naming

nolintlint:
require-explanation: true
require-specific: true

# v2 formatters (used by `golangci-lint fmt`)
formatters:
enable:
- gofmt
- goimports
- gofumpt
- gci
- golines
settings:
golines:
max-len: 120
gci:
sections:
- standard
- default
- prefix(github.com/your/module) # Replace with your module path
Loading
Loading