Skip to content

Commit

Permalink
add test workflow and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
snkrheadz committed Jun 21, 2024
1 parent 050fc8c commit 29ae173
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
56 changes: 56 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test gocyclo Analysis Reports

on:
pull_request:
paths:
- "**/*.go"

permissions:
pull-requests: write

jobs:
test_gocyclo_analysis:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4.0.0

- name: Set up Go
uses: actions/setup-go@v4.0.1
with:
go-version-file: ./go.mod

- name: Run Go tests
run: |
cd tests
go test -v ./...
- name: Run gocyclo Analysis Reports
uses: ./
with:
ignore_pattern: '_test|_mock|mock_|.pb.go|proto'
over: '20'
top: '10'
id: gocyclo_analysis
continue-on-error: true

- name: Verify gocyclo report
run: |
# Example of a verification step
# You can add checks here to verify that the report has been generated correctly
if [ -f raw_gocyclo_output.txt ]; then
echo "raw_gocyclo_output.txt exists."
cat raw_gocyclo_output.txt
else
echo "raw_gocyclo_output.txt does not exist."
exit 1
fi
- name: Create a comment with the results
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
header: gocyclo Report
message: |
${{ env.gocyclo_report }}
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ The action supports the following inputs:
- `over`: Show functions with complexity > N only and return exit code 1 if the set is non-empty (default: '')
- `top`: Show the top N most complex functions only (default: '')

### Usage of `env.gocyclo_report`

The `env.gocyclo_report` is an environment variable that holds the results of the `gocyclo` analysis. This report includes details about the cyclomatic complexity of each function in your Go code.

Here's how you can use it:

1. **Accessing the report**: You can access the `gocyclo_report` in your workflow file using the `env` context. For example, you can print the report to the console with the following step:

```github-actions-workflow
- name: Print gocyclo report
run: echo "${{ env.gocyclo_report }}"
```

2. **Using the report in other steps:** The gocyclo_report can be used in other steps of your workflow. For example, you can use it to conditionally run steps based on the complexity of your code, or to post the report as a comment in a pull request.

3. **Storing the report:** If you want to store the gocyclo_report for future reference, you can write it to a file in your repository. For example:

```github-actions-workflow
- name: Store gocyclo report
run: echo "${{ env.gocyclo_report }}" > gocyclo_report.txt
```

Remember, the gocyclo_report is a powerful tool for understanding the complexity of your Go code. Use it wisely to maintain the quality of your codebase.

## Usage

Below is an example of how to use this action in your workflow:
Expand All @@ -40,6 +64,10 @@ on:
paths:
- "**/*.go"

# Permissions for marocchino/sticky-pull-request-comment@v2
permissions:
pull-requests: write

jobs:
gocyclo_analysis:
runs-on: ubuntu-latest
Expand All @@ -60,5 +88,13 @@ jobs:
recreate: true
header: gocyclo Report
message: |
${{ steps.gocyclo_analysis.outputs.report }}
${{ env.gocyclo_report }}
```
### About gocyclo
The gocyclo tool, created by [fzipp](https://github.com/fzipp), is a command-line utility that computes the cyclomatic complexity of functions in Go source code. Cyclomatic complexity is a metric that measures the number of linearly independent paths through a program's source code, which is a useful indicator of code complexity and maintainability.
For more information about `gocyclo` , visit the [gocyclo GitHub repository](https://github.com/fzipp/gocyclo).

By integrating gocyclo into your GitHub Actions workflow, you can continuously monitor and manage the complexity of your Go codebase, ensuring that your software remains maintainable and scalable.

0 comments on commit 29ae173

Please sign in to comment.