Easily add annotations to your GitHub pull requests based on reports from your tests, linters, etc.
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Run Tests & Lint etc.
run: npm install && npm run test:lint:etc
- name: Report Annotate
id: annotate
if: always() # Run with test/lint failures.
uses: granodigital/report-annotate@v1
with:
reports: |
junit|reports/junit-generic.xml
junit-eslint|reports/*-eslint.xml
junit-jest|reports/junit-jest.xml
max-annotations: 20 # Keep the clutter down (50 is max by GitHub)
ignore: node_modules/**,dist/** # Ignore patterns for the report search (default).
- name: Annotations created
if: always()
run: |
echo "Total: ${{ steps.annotate.outputs.total }}"
echo "Errors: ${{ steps.annotate.outputs.errors }}"
echo "Warnings: ${{ steps.annotate.outputs.warnings }}"
echo "Notices: ${{ steps.annotate.outputs.notices }}"Note
You'll need to have a reasonably modern version of
Node.js handy (20.x or later should work!). If you are
using a version manager like nodenv or
fnm, this template has a .node-version
file at the root of the repository that can be used to automatically switch to
the correct version when you cd into the repository. Additionally, this
.node-version file is used by GitHub Actions in any actions/setup-node
actions.
You can define custom matchers to parse your reports and create annotations. Currently only XML reports are supported using XPath selectors.
Feel free to open a PR to add support for new report formats or matchers.
See matchers folder for examples.
---
- name: Report Annotate
id: annotate
if: always() # Run with test/lint failures.
uses: granodigital/report-annotate@v1
with:
reports: my-matcher|reports/*.xml
custom-matchers: |
{
"my-matcher": {
"format": "xml",
"item": "//testCase",
"title": "oopsie-daisy/@message",
"message": "oopsie-daisy/text()",
"file": "parent::testFile/@filePath",
"startLine": "oopsie-daisy/@line"
}
}-
Install the dependencies
npm install
-
🏗️ Package the TypeScript for distribution
npm run bundle
-
✅ Run the tests
$ npm test PASS ./index.test.js ✓ throws invalid number (3ms) ✓ wait 500 ms (504ms) ✓ test runs (95ms) ...
The action.yml file defines metadata about your action, such as
input(s) and output(s). For details about this file, see
Metadata syntax for GitHub Actions.
When you copy this repository, update action.yml with the name, description,
inputs, and outputs for your action.
The src/ directory is the heart of your action! This contains the
source code that will be run when your action is invoked. You can replace the
contents of this directory with your own code.
There are a few things to keep in mind when writing your action code:
-
Create a new branch
git checkout -b releases/v1
-
Replace the contents of
src/with your action code -
Add tests to
__tests__/for your source code -
Format, test, and build the action
npm run all
For information about versioning your action, see Versioning in the GitHub Actions toolkit.
This project includes a helper script, script/release
designed to streamline the process of tagging and pushing new releases for
GitHub Actions.
GitHub Actions allows users to select a specific version of the action to use, based on release tags. This script simplifies this process by performing the following steps:
- Retrieving the latest release tag: The script starts by fetching the most recent SemVer release tag of the current branch, by looking at the local data available in your repository.
- Prompting for a new release tag: The user is then prompted to enter a new release tag. To assist with this, the script displays the tag retrieved in the previous step, and validates the format of the inputted tag (vX.X.X). The user is also reminded to update the version field in package.json.
- Tagging the new release: The script then tags a new release and syncs the
separate major tag (e.g. v1, v2) with the new release tag (e.g. v1.0.0,
v2.1.2). When the user is creating a new major release, the script
auto-detects this and creates a
releases/v#branch for the previous major version. - Pushing changes to remote: Finally, the script pushes the necessary commits, tags and branches to the remote repository. From here, you will need to create a new release in GitHub so users can easily reference the new tags in their workflows.