diff --git a/.github/workflows/coverage_report.yml b/.github/workflows/coverage_report.yml new file mode 100644 index 0000000..fa41350 --- /dev/null +++ b/.github/workflows/coverage_report.yml @@ -0,0 +1,54 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Coverage Report + +on: + workflow_run: + workflows: ["Test lint and build"] + branches: [main] + types: + - completed + +jobs: + + workflow: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.22' + cache: false + + - uses: extractions/setup-just@v1 + + - 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 + 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/go.yml b/.github/workflows/test_lint_and_build.yml similarity index 74% rename from .github/workflows/go.yml rename to .github/workflows/test_lint_and_build.yml index d02667b..4c4db46 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/test_lint_and_build.yml @@ -1,7 +1,7 @@ # This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go -name: Go +name: Test lint and build on: push: @@ -15,6 +15,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v4 @@ -24,14 +27,19 @@ jobs: - uses: extractions/setup-just@v1 - - name: Test - run: just test - - name: Lint uses: golangci/golangci-lint-action@v3 with: version: v1.57.2 args: --out-format=colored-line-number -v ./... + - name: Test + run: just test-ci + + - name: Go Coverage Badge + uses: tj-actions/coverage-badge-go@v2 + with: + filename: coverage.out + - name: Build run: go build -v ./... diff --git a/.gitignore b/.gitignore index a5c9323..03a821c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +coverage.out + playground/ diff --git a/justfile b/justfile index 898b631..298240c 100644 --- a/justfile +++ b/justfile @@ -14,6 +14,10 @@ test: test-all: go test -tags=integration ./... +# run test generating coverage +test-ci: + go test -v ./... -covermode=count -coverprofile=coverage.out & go tool cover -func=coverage.out -o=coverage.out + # lint the code lint: golangci-lint run -v ./...