From 0f542686834bd338e6deacc645ab696cf7b62aa5 Mon Sep 17 00:00:00 2001 From: barco Date: Mon, 18 Mar 2024 15:24:37 +0100 Subject: [PATCH 1/4] feat: add coverage for tests in `reback-admin-backend folder` --- rebac-admin-backend/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rebac-admin-backend/Makefile b/rebac-admin-backend/Makefile index 458785d6e..0d8b4f94d 100644 --- a/rebac-admin-backend/Makefile +++ b/rebac-admin-backend/Makefile @@ -22,5 +22,9 @@ mocks: # Run tests test: mocks - go test ./... + go test ./... -cover -coverprofile coverage_source.out + # this will be cached, just needed to the test.json + go test ./... -cover -coverprofile coverage_source.out -json > test_source.json + cat coverage_source.out | grep -v "mock_*" | tee coverage.out + cat test_source.json | grep -v "mock_*" | tee test.json .PHONY: test From ee991c919867a70c2e7fd4ee20d8314e4c1100e8 Mon Sep 17 00:00:00 2001 From: barco Date: Mon, 18 Mar 2024 15:25:14 +0100 Subject: [PATCH 2/4] feat: add CI linting and unittest run for rebac-admin-backend code --- .github/workflows/ci-rebac-admin-backend.yaml | 19 ++++++++++++ .../workflows/rebac-admin-backend-lint.yaml | 28 ++++++++++++++++++ .../rebac-admin-backend-unittest.yaml | 29 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 .github/workflows/ci-rebac-admin-backend.yaml create mode 100644 .github/workflows/rebac-admin-backend-lint.yaml create mode 100644 .github/workflows/rebac-admin-backend-unittest.yaml diff --git a/.github/workflows/ci-rebac-admin-backend.yaml b/.github/workflows/ci-rebac-admin-backend.yaml new file mode 100644 index 000000000..454ba5d28 --- /dev/null +++ b/.github/workflows/ci-rebac-admin-backend.yaml @@ -0,0 +1,19 @@ +name: ci-rebac-admin-backend +run-name: CI (rebac-admin) for ${{ github.sha }} on ${{ github.ref_name }} + +on: + workflow_dispatch: + push: + branches: + - "feature-rebac-admin-ui-backend" + pull_request: + branches: + - "*" + +jobs: + lint: + name: Perform linting + uses: ./.github/workflows/rebac-admin-backend-lint.yaml + unit-test: + name: Run unit tests + uses: ./.github/workflows/rebac-admin-backend-unittest.yaml diff --git a/.github/workflows/rebac-admin-backend-lint.yaml b/.github/workflows/rebac-admin-backend-lint.yaml new file mode 100644 index 000000000..79091c90c --- /dev/null +++ b/.github/workflows/rebac-admin-backend-lint.yaml @@ -0,0 +1,28 @@ +run-name: Unit test steps for ${{ github.sha }} on ${{ github.ref_name }} + +on: + workflow_call: + +permissions: + contents: read + pull-requests: read + checks: write + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + name: Checkout repo + + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 + name: Setup Go version + with: + go-version: '1.21' + + - uses: golangci/golangci-lint-action@v3 + name: Perform linting and annotate code + with: + version: latest + working-directory: ./rebac-admin-backend + only-new-issues: true diff --git a/.github/workflows/rebac-admin-backend-unittest.yaml b/.github/workflows/rebac-admin-backend-unittest.yaml new file mode 100644 index 000000000..e589612de --- /dev/null +++ b/.github/workflows/rebac-admin-backend-unittest.yaml @@ -0,0 +1,29 @@ +run-name: Unit test steps for ${{ github.sha }} on ${{ github.ref_name }} + +on: + workflow_call: + +jobs: + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 + with: + go-version: '1.21' + + - name: Build and test Go code + working-directory: ./rebac-admin-backend + run: make test + + + - uses: codecov/codecov-action@c4cf8a4f03f0ac8585acb7c1b7ce3460ec15782f # v4 + with: + files: ./rebac-admin-backend/coverage.out + + - name: Upload Go test results + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3 + with: + name: Go-results + path: ./rebac-admin-backend/test.json From ef85066c65e91763be1ddf82ddae555efe453b6b Mon Sep 17 00:00:00 2001 From: barco Date: Tue, 19 Mar 2024 11:20:27 +0100 Subject: [PATCH 3/4] refactor: make jobs inline --- .github/workflows/ci-rebac-admin-backend.yaml | 46 ++++++++++++++++++- .../workflows/rebac-admin-backend-lint.yaml | 28 ----------- .../rebac-admin-backend-unittest.yaml | 29 ------------ 3 files changed, 44 insertions(+), 59 deletions(-) delete mode 100644 .github/workflows/rebac-admin-backend-lint.yaml delete mode 100644 .github/workflows/rebac-admin-backend-unittest.yaml diff --git a/.github/workflows/ci-rebac-admin-backend.yaml b/.github/workflows/ci-rebac-admin-backend.yaml index 454ba5d28..5bd3602e6 100644 --- a/.github/workflows/ci-rebac-admin-backend.yaml +++ b/.github/workflows/ci-rebac-admin-backend.yaml @@ -10,10 +10,52 @@ on: branches: - "*" +permissions: + contents: read + pull-requests: read + checks: write + jobs: lint: name: Perform linting - uses: ./.github/workflows/rebac-admin-backend-lint.yaml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + name: Checkout repo + + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 + name: Setup Go version + with: + go-version-file: 'go.mod' + + - uses: golangci/golangci-lint-action@v3 + name: Perform linting and annotate code + with: + version: latest + working-directory: ./rebac-admin-backend + only-new-issues: true + unit-test: name: Run unit tests - uses: ./.github/workflows/rebac-admin-backend-unittest.yaml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 + with: + go-version-file: 'go.mod' + + - name: Build and test Go code + working-directory: ./rebac-admin-backend + run: make ARGS="-count=1" test + + + - uses: codecov/codecov-action@c4cf8a4f03f0ac8585acb7c1b7ce3460ec15782f # v4 + with: + files: ./rebac-admin-backend/coverage.out + + - name: Upload Go test results + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3 + with: + name: Go-results + path: ./rebac-admin-backend/test.json diff --git a/.github/workflows/rebac-admin-backend-lint.yaml b/.github/workflows/rebac-admin-backend-lint.yaml deleted file mode 100644 index 79091c90c..000000000 --- a/.github/workflows/rebac-admin-backend-lint.yaml +++ /dev/null @@ -1,28 +0,0 @@ -run-name: Unit test steps for ${{ github.sha }} on ${{ github.ref_name }} - -on: - workflow_call: - -permissions: - contents: read - pull-requests: read - checks: write - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: Checkout repo - - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 - name: Setup Go version - with: - go-version: '1.21' - - - uses: golangci/golangci-lint-action@v3 - name: Perform linting and annotate code - with: - version: latest - working-directory: ./rebac-admin-backend - only-new-issues: true diff --git a/.github/workflows/rebac-admin-backend-unittest.yaml b/.github/workflows/rebac-admin-backend-unittest.yaml deleted file mode 100644 index e589612de..000000000 --- a/.github/workflows/rebac-admin-backend-unittest.yaml +++ /dev/null @@ -1,29 +0,0 @@ -run-name: Unit test steps for ${{ github.sha }} on ${{ github.ref_name }} - -on: - workflow_call: - -jobs: - unit-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 - with: - go-version: '1.21' - - - name: Build and test Go code - working-directory: ./rebac-admin-backend - run: make test - - - - uses: codecov/codecov-action@c4cf8a4f03f0ac8585acb7c1b7ce3460ec15782f # v4 - with: - files: ./rebac-admin-backend/coverage.out - - - name: Upload Go test results - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3 - with: - name: Go-results - path: ./rebac-admin-backend/test.json From fb19d101f14008ca6de72afe032118a307e3c829 Mon Sep 17 00:00:00 2001 From: barco Date: Tue, 19 Mar 2024 11:20:49 +0100 Subject: [PATCH 4/4] refactor: split test and test-coverage targets + add cov artifacts to gitignore --- .github/workflows/ci-rebac-admin-backend.yaml | 2 +- .gitignore | 2 ++ rebac-admin-backend/Makefile | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-rebac-admin-backend.yaml b/.github/workflows/ci-rebac-admin-backend.yaml index 5bd3602e6..9cb1edc27 100644 --- a/.github/workflows/ci-rebac-admin-backend.yaml +++ b/.github/workflows/ci-rebac-admin-backend.yaml @@ -47,7 +47,7 @@ jobs: - name: Build and test Go code working-directory: ./rebac-admin-backend - run: make ARGS="-count=1" test + run: make ARGS="-count=1" test-coverage - uses: codecov/codecov-action@c4cf8a4f03f0ac8585acb7c1b7ce3460ec15782f # v4 diff --git a/.gitignore b/.gitignore index 22e4ad7d9..bfec11368 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,8 @@ yarn-error.log* # Output of the go coverage tool, specifically when used with LiteIDE *.out +test.json +test_source.json # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/rebac-admin-backend/Makefile b/rebac-admin-backend/Makefile index 0d8b4f94d..e7891d64d 100644 --- a/rebac-admin-backend/Makefile +++ b/rebac-admin-backend/Makefile @@ -20,11 +20,16 @@ mocks: go generate ./... .PHONY: mocks -# Run tests -test: mocks - go test ./... -cover -coverprofile coverage_source.out - # this will be cached, just needed to the test.json - go test ./... -cover -coverprofile coverage_source.out -json > test_source.json +# Run tests with coverage +test-coverage: mocks + go test ./... -cover -coverprofile coverage_source.out $(ARGS) + # this will be cached, just needed to get the test.json + go test ./... -cover -coverprofile coverage_source.out $(ARGS) -json > test_source.json cat coverage_source.out | grep -v "mock_*" | tee coverage.out cat test_source.json | grep -v "mock_*" | tee test.json +.PHONY: test-coverage + +# Run tests +test: mocks + go test ./... $(ARGS) .PHONY: test