From 94219d0f2ab85d9a50590044d9e017c194db2b79 Mon Sep 17 00:00:00 2001 From: Serge Radinovich <47865535+sergerad@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:52:38 +1300 Subject: [PATCH] Fix/coverage (#3) --- .github/actions/test/action.yaml | 24 +++++++++++++++ .github/workflows/main.yaml | 43 ++++++++++++++++++++++++++ .github/workflows/pr.yaml | 52 +++----------------------------- CHANGELOG.md | 9 ------ 4 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 .github/actions/test/action.yaml create mode 100644 .github/workflows/main.yaml delete mode 100644 CHANGELOG.md diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml new file mode 100644 index 0000000..b303944 --- /dev/null +++ b/.github/actions/test/action.yaml @@ -0,0 +1,24 @@ +name: Build and Test Source + +runs: + using: composite + steps: + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: "go.mod" + + - name: Run lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55 + + - name: Go run examples + shell: bash + run: ./.github/workflows/scripts/examples.sh + + - name: Run Test + shell: bash + run: | + go test -v . -covermode=count -coverprofile=coverage.out + go tool cover -func=coverage.out -o=coverage.out diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..2f822ec --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,43 @@ +name: Test src and generate coverage badge + +on: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + + - uses: ./.github/actions/test + + - name: Go Coverage Badge + uses: tj-actions/coverage-badge-go@v2 + with: + filename: coverage.out + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v16 + id: verify-changed-files + with: + files: README.md + + - name: Commit changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add README.md + git commit -m "chore: Updated coverage badge." + + - name: Push changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ github.token }} + branch: ${{ github.head_ref }} diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5f1c420..b00a264 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,9 +1,6 @@ -name: Test src and generate coverage badge +name: Test src on: - push: - branches: - - main pull_request: branches: - main @@ -12,53 +9,14 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - - name: Setup go - uses: actions/setup-go@v4 - with: - go-version-file: "go.mod" + - uses: ./.github/actions/test - - name: Run lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.55 - - - name: Go run examples + - name: Check Coverage shell: bash - run: ./.github/workflows/scripts/examples.sh - - - name: Run Test - run: | - go test -v . -covermode=count -coverprofile=coverage.out - go tool cover -func=coverage.out -o=coverage.out - - - name: Go Coverage Badge # Pass the `coverage.out` output to this action - uses: tj-actions/coverage-badge-go@v2 - with: - filename: coverage.out - - - name: Verify Changed files - uses: tj-actions/verify-changed-files@v16 - id: verify-changed-files - with: - files: README.md - - - name: Commit changes - if: steps.verify-changed-files.outputs.files_changed == 'true' run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add README.md - git commit -m "chore: Updated coverage badge." - - - name: Push changes - if: steps.verify-changed-files.outputs.files_changed == 'true' - uses: ad-m/github-push-action@master - with: - github_token: ${{ github.token }} - branch: ${{ github.head_ref }} + grep 'total.*100\.0%' < coverage.out diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 7811b39..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# CHANGELOG - -## v2.0.0 - -* - -## v1.0.0 - -* Initial implementation