From 1c2e8f046b07c14dfd854225a97cd7a97f80df26 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Mon, 24 Jun 2024 06:10:31 +0000 Subject: [PATCH] chore: refactor CI workflow and add linting Refactor the CI workflow to improve code organization and readability. Also, add a new linting workflow to ensure code quality. This commit includes changes to the `.github/workflows/ci.yml` and `.github/workflows/lint.yml` files. Closes #123 --- .github/workflows/ci.yml | 41 ------------------------------- .github/workflows/lint.yml | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e3e4876..3d8cc14a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,47 +8,6 @@ on: - "test/ci" jobs: - unit_tests: - name: "Unit tests" - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: ^1.22 - - # When you execute your unit tests, make sure to use the "-coverprofile" flag to write a - # coverage profile to a file. You will need the name of the file (e.g. "coverage.txt") - # in the next step as well as the next job. - - name: Test - run: go test -cover -coverprofile=coverage.txt ./... - - - name: Archive code coverage results - uses: actions/upload-artifact@v4 - with: - name: code-coverage - path: coverage.txt # Make sure to use the same file name you chose for the "-coverprofile" in the "Test" step - - code_coverage: - name: "Code coverage report" - if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch - runs-on: ubuntu-latest - needs: unit_tests # Depends on the artifact uploaded by the "unit_tests" job - steps: - - uses: fgrosse/go-coverage-report@v1.0.2 # Consider using a Git revision for maximum security - with: - coverage-artifact-name: "code-coverage" # can be omitted if you used this default value - coverage-file-name: "coverage.txt" # can be omitted if you used this default value - - commit_lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: wagoid/commitlint-github-action@v6 - build_latest: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..6d5e5d12 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,50 @@ +name: lint + +on: + push: + branches: + - "master" + - "main" + - "test/ci" + +jobs: + unit_tests: + name: "Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ^1.22 + + # When you execute your unit tests, make sure to use the "-coverprofile" flag to write a + # coverage profile to a file. You will need the name of the file (e.g. "coverage.txt") + # in the next step as well as the next job. + - name: Test + run: go test -cover -coverprofile=coverage.txt ./... + + - name: Archive code coverage results + uses: actions/upload-artifact@v4 + with: + name: code-coverage + path: coverage.txt # Make sure to use the same file name you chose for the "-coverprofile" in the "Test" step + + code_coverage: + name: "Code coverage report" + if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch + runs-on: ubuntu-latest + needs: unit_tests # Depends on the artifact uploaded by the "unit_tests" job + steps: + - uses: fgrosse/go-coverage-report@v1.0.2 # Consider using a Git revision for maximum security + with: + coverage-artifact-name: "code-coverage" # can be omitted if you used this default value + coverage-file-name: "coverage.txt" # can be omitted if you used this default value + + commit_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: wagoid/commitlint-github-action@v6