From a4df506ffeb1c3a3ab9dc1cf431ee98fb86385ce Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Wed, 15 Jan 2025 01:49:51 +0800 Subject: [PATCH 1/7] feat: add unit test workflow --- .github/workflows/unit-test.yml | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/unit-test.yml diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 00000000..a00c3a5e --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,76 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: "Unit Test" + +on: + push: + branches: [ master ] + pull_request: + branches: "*" + types: [opened, synchronize, reopened] + +permissions: + contents: read + +jobs: + unit-test: + name: Unit Test + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + matrix: + golang: + - 1.18 + + steps: + - name: "Set up Go" + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.golang }} + + - name: "Checkout code" + uses: actions/checkout@v3 + with: + submodules: true + + - name: "Cache dependencies" + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}" + restore-keys: | + "${{ runner.os }}-go-" + + - name: "Run Unit Tests" + run: | + echo "=== Starting Unit Tests ===" + go test -v ./... -coverprofile=coverage.txt -covermode=atomic -timeout 10m + if [ $? -ne 0 ]; then + echo "❌ Unit tests failed" + exit 1 + fi + echo "✅ Unit tests completed successfully" + + - name: "Upload Coverage" + uses: codecov/codecov-action@v3 + with: + file: ./coverage.txt + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true + verbose: true \ No newline at end of file From 17ef225c7d5ddd86b1a064d3bf252a2b07faf2e5 Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Sun, 19 Jan 2025 01:08:20 +0800 Subject: [PATCH 2/7] feat:the ability to automatically run unit tests after creating a pull request. --- .github/workflows/unit-test.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index a00c3a5e..13c9101c 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -65,12 +65,3 @@ jobs: exit 1 fi echo "✅ Unit tests completed successfully" - - - name: "Upload Coverage" - uses: codecov/codecov-action@v3 - with: - file: ./coverage.txt - flags: unittests - name: codecov-umbrella - fail_ci_if_error: true - verbose: true \ No newline at end of file From 73cf2a98e6b6a91b8486df88f3a0118aacc48cb8 Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Sun, 19 Jan 2025 01:26:59 +0800 Subject: [PATCH 3/7] feat:the ability to automatically run unit tests after creating a pull request. --- .github/workflows/unit-test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 13c9101c..621947d2 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -19,7 +19,10 @@ name: "Unit Test" on: push: - branches: [ master ] + branches: + - master + - 'feature/**' + - 'dev/**' pull_request: branches: "*" types: [opened, synchronize, reopened] From ac0af9606f113be8a12a8314e05ad2bf2ee387b2 Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Sun, 19 Jan 2025 01:46:05 +0800 Subject: [PATCH 4/7] feat:the ability to automatically run unit tests after creating a pull request. --- .github/workflows/build.yml | 8 +------- .github/workflows/unit-test.yml | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0f7b1f9..55b56d39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ # This is a workflow to help you test the unit case and show codecov -name: "build and codecov" +name: "build" on: push: @@ -60,9 +60,3 @@ jobs: - name: "run go build" run: go build -v ./... - - - name: "run go test and out codecov" - run: go test -v ./... -race -coverprofile=coverage.out -covermode=atomic - - - name: "upload coverage" - uses: codecov/codecov-action@v3 diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 621947d2..28ec0d65 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -59,12 +59,31 @@ jobs: restore-keys: | "${{ runner.os }}-go-" + - name: Shutdown default mysql + run: sudo service mysql stop + + - name: Create mysql database auth + uses: mirromutth/mysql-action@v1.1 + with: + host port: 3306 + container port: 3306 + mysql version: '8.0' + mysql database: 'seata_go_test' + mysql root password: 'seata_go' + - name: "Run Unit Tests" run: | echo "=== Starting Unit Tests ===" - go test -v ./... -coverprofile=coverage.txt -covermode=atomic -timeout 10m + go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic -timeout 10m if [ $? -ne 0 ]; then echo "❌ Unit tests failed" exit 1 fi echo "✅ Unit tests completed successfully" + + - name: "Archive test results" + uses: actions/upload-artifact@v3 + with: + name: test-results + path: coverage.txt + retention-days: 7 From 6f6324ac9acf94fbb46ed43bec42e547d6f09ec2 Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Sun, 19 Jan 2025 03:07:00 +0800 Subject: [PATCH 5/7] feat:the ability to automatically run unit tests after creating a pull request. --- .github/workflows/unit-test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 28ec0d65..2438507e 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -19,10 +19,7 @@ name: "Unit Test" on: push: - branches: - - master - - 'feature/**' - - 'dev/**' + branches: [ master ] pull_request: branches: "*" types: [opened, synchronize, reopened] From 32ccc651b2d38b8158adc0127f3f1753f729209f Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Sun, 19 Jan 2025 03:12:36 +0800 Subject: [PATCH 6/7] feat:the ability to automatically run unit tests after creating a pull request. --- .github/workflows/unit-test.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 2438507e..513794a4 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -59,14 +59,11 @@ jobs: - name: Shutdown default mysql run: sudo service mysql stop - - name: Create mysql database auth - uses: mirromutth/mysql-action@v1.1 - with: - host port: 3306 - container port: 3306 - mysql version: '8.0' - mysql database: 'seata_go_test' - mysql root password: 'seata_go' + - name: Set up MySQL + run: | + sudo systemctl start mysql + mysql -e 'CREATE DATABASE seata_go_test;' -uroot -proot + mysql -e 'ALTER USER "root"@"localhost" IDENTIFIED BY "seata_go";' -uroot -proot - name: "Run Unit Tests" run: | From e488a54746f0a06debdf8925dcba192895504462 Mon Sep 17 00:00:00 2001 From: HEXINGZE <2046084122@qq.com> Date: Sun, 19 Jan 2025 03:14:01 +0800 Subject: [PATCH 7/7] feat:the ability to automatically run unit tests after creating a pull request. --- .github/workflows/unit-test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 513794a4..388e1cf3 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,7 +21,7 @@ on: push: branches: [ master ] pull_request: - branches: "*" + branches: [ "*" ] types: [opened, synchronize, reopened] permissions: @@ -59,11 +59,6 @@ jobs: - name: Shutdown default mysql run: sudo service mysql stop - - name: Set up MySQL - run: | - sudo systemctl start mysql - mysql -e 'CREATE DATABASE seata_go_test;' -uroot -proot - mysql -e 'ALTER USER "root"@"localhost" IDENTIFIED BY "seata_go";' -uroot -proot - name: "Run Unit Tests" run: |