{"id":13411260,"url":"https://github.com/gha-common/go-beautiful-html-coverage","last_synced_at":"2025-03-14T17:30:25.720Z","repository":{"id":239401153,"uuid":"799406916","full_name":"gha-common/go-beautiful-html-coverage","owner":"gha-common","description":"A GitHub Action to track code coverage in your pull requests, with a beautiful HTML preview, for free.","archived":false,"fork":false,"pushed_at":"2024-05-22T05:15:41.000Z","size":254,"stargazers_count":5,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T20:45:21.218Z","etag":null,"topics":["coverage","coverage-report","go","golang"],"latest_commit_sha":null,"homepage":"https://gha-common.github.io/go-beautiful-html-coverage/go-test-app-01/head/head.html#file1","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gha-common.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-12T03:36:39.000Z","updated_at":"2024-07-28T20:01:16.000Z","dependencies_parsed_at":"2024-05-22T06:25:06.382Z","dependency_job_id":"7c81d79f-48eb-4b53-98d6-51f1923fc3e0","html_url":"https://github.com/gha-common/go-beautiful-html-coverage","commit_stats":null,"previous_names":["kilianc/go-coverage","kilianc/go-coverage-action","kilianc/github-action-go-coverage","gha-common/go-beautiful-html-coverage"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha-common%2Fgo-beautiful-html-coverage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha-common%2Fgo-beautiful-html-coverage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha-common%2Fgo-beautiful-html-coverage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha-common%2Fgo-beautiful-html-coverage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gha-common","download_url":"https://codeload.github.com/gha-common/go-beautiful-html-coverage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618576,"owners_count":20320261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coverage","coverage-report","go","golang"],"created_at":"2024-07-30T20:01:12.498Z","updated_at":"2025-03-14T17:30:25.421Z","avatar_url":"https://github.com/gha-common.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/kilianciuffolo"],"categories":["Continuous Integration","持续集成"],"sub_categories":["Standard CLI","标准CLI"],"readme":"\u003c!-- markdownlint-disable MD041 MD033 --\u003e\n# `go-beautiful-html-coverage`\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)\n\nA GitHub Action to track code coverage in your pull requests, with [a beautiful HTML preview ↗](https://kilianc.github.io/pretender/head/head.html#file0), for free.\n\n\u003ca href=\"https://www.buymeacoffee.com/kilianciuffolo\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\n## Usage\n\nTo use this action simply add it to your pre-existent ci workflow. A bare minimal example might look like this:\n\n```yaml\nname: Go\n\non:\n  push:\n    branches: [ \"main\" ]\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  test:\n    name: Build and Test\n    runs-on: ubuntu-latest\n    permissions:\n      pull-requests: write        # required for posting comments\n      contents: write             # required for git push\n    steps:\n      - uses: actions/checkout@v4\n\n      - name: Set up Go\n        uses: actions/setup-go@v5\n\n      - name: Test                # this should generate cover.out\n        run: make test\n\n      - name: Go Beautiful HTML Coverage\n        uses: 'gha-common/go-beautiful-html-coverage@v1'\n```\n\n## How it works\n\nThis GHA expects `cover.out` to be present in the root of your repo at runtime. `cover.out` is usually generated by `go test` when passing the `-coverprofile=cover.out` flag:\n\n```sh\ngo test -coverprofile=cover.out ./...\n```\n\nFor examples on how you might do that you can peak at [`go-test-app/Makefile`](./Makefile), or some of my other go projects like [`pretender`](https://github.com/kilianc/pretender/blob/main/Makefile#L44-L57) and [`base-go-cli`](https://github.com/kilianc/base-golang-cli/blob/main/Makefile#L76-L92).\n\nOnce your test has ran and `cover.out` has been generated, the GHA does the following:\n\n1. Create and push [new orphan branch](https://github.com/gha-common/go-beautiful-html-coverage/tree/cover) if one doesn't exist.\n1. Generate `cover.html` and `cover.txt` from `cover.out`.\n1. Customize `cover.html` and rename it `\u003csha\u003e.html`.\n1. `git-push` the `\u003csha\u003e.html` file to the orphan branch. This will trigger a `GitHub Pages` deployment.\n1. Post a comment to your PR with your code coverage summary (`cover.txt`) and a link to your `\u003csha\u003e.html`.\n\n### Screenshots\n\n\u003cbr\u003e\n\u003cimg alt=\"PR Comment\" src=\"https://github.com/gha-common/go-beautiful-html-coverage/assets/385716/e155c0aa-14ec-4740-9824-f00399e6b170\"\u003e\n\u003cimg alt=\"HTML Preview (Dark)\" src=\"https://github.com/gha-common/go-beautiful-html-coverage/assets/385716/154f0af6-f5a9-4eb5-bc3a-721bab2e4263\"\u003e\n\u003cimg alt=\"HTML Preview (Light)\" src=\"https://github.com/gha-common/go-beautiful-html-coverage/assets/385716/11256803-59c5-45c4-8ad0-e83ac3374388\"\u003e\n\u003cbr\u003e\u003cbr\u003e\n\n\u003e [!NOTE]\n\u003e In order for the HTML preview links to work, configure `GitHub Pages` in your target repo *(`Settings \u003e Pages`)* to `Deploy from a branch` and pick your target branch, which is, by default, `cover`.\n\u003e\n\u003e ![GitHub Pages Setup](https://github.com/gha-common/go-beautiful-html-coverage/assets/385716/a14f4df6-6263-4ae3-8685-e7901a1dbbe2)\n\n## Reference\n\n```yaml\n- name: Go Beautiful HTML Coverage\n  uses: 'gha-common/go-beautiful-html-coverage@v1'\n  with:\n    # Repository name with owner. For example, actions/checkout.\n    # Default: ${{ github.repository }}\n    repository: ''\n\n    # The branch to checkout or create and push coverage to.\n    # Default: 'cover'\n    branch: ''\n\n    # The token to use for pushing to the repository.\n    # Default: ${{ github.token }}\n    token: ''\n\n    # The relative path of your go project. Useful for monorepos and custom folder structures.\n    # Default: ./\n    path: ''\n\n    # The minimum % of coverage required.\n    # Default: 0\n    threshold: ''\n```\n\n## Examples\n\n**You can customize the name of the branch that hosts the code coverage files.**\n\n```yaml\n- name: Go Beautiful HTML Coverage\n  uses: 'gha-common/go-beautiful-html-coverage@v1'\n  with:\n    branch: 'my-coverage'\n```\n\nJust make sure to update the `GitHub Pages` deployment settings to match.\n\n**You can customize the repository that hosts the code coverage files.**\n\nThis is helpful if you don't want to clutter your project's repo, or if you want to centralize coverage reporting across multiple repos, or you can't turn on `GitHub Pages` in your project's repo.\n\n```yaml\n- name: Go Beautiful HTML Coverage\n  uses: 'gha-common/go-beautiful-html-coverage@v1'\n  with:\n    repository: yourname/coverage\n    token: ${{ secrets.GHA_COVERAGE_TOKEN }}\n```\n\nWhere `GHA_COVERAGE_TOKEN` is a repository secret with a personal token that has write access to `yourname/coverage`.\n\n**You can customize the path to your go project in the repo.**\n\nThis is helpful if you have a monorepo with multiple apps, or simply you keep your go files in a subfolder. Just make sure to generate `cover.out` for all your apps before running this GHA.\n\n```yaml\n- name: Go Beautiful HTML Coverage\n  uses: 'gha-common/go-beautiful-html-coverage@v1'\n  with:\n    path: ./go-app-01\n\n- name: Go Beautiful HTML Coverage\n  uses: 'gha-common/go-beautiful-html-coverage@v1'\n  with:\n    path: ./go-app-02\n```\n\n## License\n\nMIT License, see [LICENSE](./LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgha-common%2Fgo-beautiful-html-coverage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgha-common%2Fgo-beautiful-html-coverage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgha-common%2Fgo-beautiful-html-coverage/lists"}