|
| 1 | +--- |
| 2 | +title: Integrating Go Test Execution Summary Reports in GitHub Actions |
| 3 | +date: 2025-06-21 11:31:00 +05:30 |
| 4 | +layout: post |
| 5 | +--- |
| 6 | + |
| 7 | +GitHub Actions is a powerful Continuous Integration/Continuous Deployment (CI/CD) tool that enables developers to automate workflows directly within their repositories. When working with Go projects, generating and publishing test execution summary reports can provide valuable insights into test results, simplifying debugging and tracking. This article outlines how to integrate Go test execution summary reports into your GitHub Actions workflow using only the `go-ctrf-json-reporter`. |
| 8 | + |
| 9 | +## **Prerequisites** |
| 10 | + |
| 11 | +Before you begin, ensure that you have the following: |
| 12 | + |
| 13 | +1. Your repository contains Go tests. |
| 14 | + |
| 15 | +2. You have a GitHub Actions workflow file set up. |
| 16 | + |
| 17 | +3. The essential tool `go-ctrf-json-reporter` is installed in your workflow. |
| 18 | + |
| 19 | +## **Setting Up GitHub Action for Go Tests with CTRF JSON Reporter** |
| 20 | + |
| 21 | +To define a GitHub Action for running Go tests with the go-ctrf-json-reporter, you can create a workflow file (e.g., .github/workflows/execute-tests.yml) in your repository. Below is an example of how to set up the workflow: |
| 22 | + |
| 23 | + name: Go Test with CTRF Reporter |
| 24 | + on: |
| 25 | + push: |
| 26 | + branches: |
| 27 | + - main |
| 28 | + workflow_dispatch: |
| 29 | + jobs: |
| 30 | + test: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Checkout code |
| 34 | + uses: actions/checkout@v2 |
| 35 | + - name: Set up Go |
| 36 | + uses: actions/setup-go@v2 |
| 37 | + with: |
| 38 | + go-version: '1.16'# Specify the Go version you want to use |
| 39 | + - name: Install Dependencies |
| 40 | + run: go mod tidy |
| 41 | + - name: Execute tests |
| 42 | + run: | |
| 43 | + cd tests |
| 44 | + go test -json -p=4 -timeout 3600s 2>&1 | tee ./gotest.json || true |
| 45 | + - name: Generate test reports |
| 46 | + if: always() |
| 47 | + run: | |
| 48 | + go-ctrf-json-reporter -output ctrf-report.json < gotest.json |
| 49 | + - name: Publish Test Summary Results |
| 50 | + if: always() |
| 51 | + run: npx github-actions-ctrf test_output/ctrf-report.json |
| 52 | + - name: Upload Test Results |
| 53 | + if: always() |
| 54 | + uses: actions/upload-artifact@v2 |
| 55 | + with: |
| 56 | + name: test-results |
| 57 | + path: ./gotest.json |
| 58 | + |
| 59 | +### **Explanation of the Workflow Steps:** |
| 60 | + |
| 61 | +1. **Triggering Events**: The workflow is triggered on `push` events to the `main` branch or can be initiated manually. |
| 62 | + |
| 63 | +2. **Checkout Code**: The `actions/checkout` step checks out your repository code. |
| 64 | + |
| 65 | +3. **Set up Go**: The `actions/setup-go` step sets up the specified version of Go. |
| 66 | + |
| 67 | +4. **Install Dependencies**: This step runs `go mod tidy` to ensure all dependencies are installed. |
| 68 | + |
| 69 | +5. **Execute Tests**: Go tests are executed with the `json` flag, and the output is saved to `gotest.json`. |
| 70 | + |
| 71 | +6. **Generate Test Reports**: The `go-ctrf-json-reporter` tool processes the JSON output and generates a CTRF-compliant report. |
| 72 | + |
| 73 | +7. **Publish Test Summary Results**: The generated CTRF report is published using `github-actions-ctrf`. |
| 74 | + |
| 75 | +8. **Upload Test Results**: Finally, the test results are uploaded as artifacts for future reference. |
| 76 | + |
| 77 | +## **Benefits of Adding Test Summary Reports** |
| 78 | + |
| 79 | +This workflow will help automate the testing process for your Go projects and provide valuable insights through the generated reports.Benefits of Adding Test Summary Reports |
| 80 | + |
| 81 | +* **Improved Visibility**: |
| 82 | + |
| 83 | + * Test summaries provide a quick overview of test results directly in the GitHub Actions interface. |
| 84 | + |
| 85 | +* **Enhanced Debugging**: |
| 86 | + |
| 87 | + * Detailed reports assist in identifying failing tests and their underlying causes. |
| 88 | + |
| 89 | +* **Integration with External Tools**: |
| 90 | + |
| 91 | + * Reports can be processed and integrated with tools like Jira and Xray for better tracking and management. |
| 92 | + |
| 93 | +## **Conclusion** |
| 94 | + |
| 95 | +Integrating Go test execution summary reports into your GitHub Actions workflow using only `go-ctrf-json-reporter` can streamline your CI/CD pipeline and enhance the visibility of test results. The provided workflow illustrates how to execute tests, generate reports, and publish them effectively. Feel free to adapt this workflow to meet your project's specific needs and leverage automated reporting in your development process.d reporting in your development process. |
0 commit comments