From 3c7833c65bf11965abee5116566a17dab5f70033 Mon Sep 17 00:00:00 2001 From: cryptocifer <4777457+cryptocifer@users.noreply.github.com> Date: Thu, 15 Jun 2023 07:03:10 +0300 Subject: [PATCH] add unit test pipeline and fix release artifact's semver (#4) --- .github/workflows/lint.yaml | 33 +++++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 5 +++-- relay/wsconn_test.go | 15 ++++++++++----- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..0524212 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,33 @@ +name: "Test and Lint" + +on: + pull_request: + branches: [ main ] + + workflow_dispatch: + +jobs: + gotest-and-golint: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.50 + only-new-issues: true + skip-pkg-cache: true + skip-build-cache: true + + - name: Go-Test + run: | + timeout 300s go test --tags unittest ./... \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 91b1c59..f2c7652 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -31,7 +31,7 @@ jobs: with: app_id: ${{ secrets.RELEASE_APP_ID }} private_key: ${{ secrets.RELEASE_APP_SECRECT }} - + - name: Make binaries run: | go build @@ -41,7 +41,7 @@ jobs: echo "REVISION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV - echo "ARCHIVE_FILE_NAME=derelay-$(git rev-parse --short HEAD)-linux-amd64" >> $GITHUB_ENV + echo "ARCHIVE_FILE_NAME=derelay-${GITHUB_REF/refs\/tags\//}-linux-amd64" >> $GITHUB_ENV - name: Archive artifacts run: | @@ -55,6 +55,7 @@ jobs: with: name: derelay-artifact path: $ARCHIVE_FILE_NAME.tar.gz + - name: Get release id: get_release uses: bruceadams/get-release@v1.2.3 diff --git a/relay/wsconn_test.go b/relay/wsconn_test.go index cb05b56..d084033 100644 --- a/relay/wsconn_test.go +++ b/relay/wsconn_test.go @@ -19,7 +19,7 @@ func TestSendChanWithNoReceiver(t *testing.T) { select { case i := <-send: fmt.Printf("received: %v\n", i) - if i == 5 { + if i == 3 { fmt.Printf("receiving routine exit\n") return } @@ -33,10 +33,15 @@ func TestSendChanWithNoReceiver(t *testing.T) { i := 0 for { - send <- i - fmt.Printf("send: %v\n", i) - i++ - time.Sleep(3 * time.Second) + select { + case send <- i: + fmt.Printf("send: %v\n", i) + i++ + time.Sleep(1 * time.Second) + default: + fmt.Printf("send buffer is full\n") + return + } } }()