- Node.js (version 22 or higher)
- pnpm (version 10.23.0 or higher) - This is the package manager we use for this project
-
Clone the repository:
git clone <repository-url> cd analytics-uploader
-
Install dependencies:
pnpm install
This project uses the following tools:
- pnpm - Package manager for Node.js dependencies
- TypeScript - Type-safe JavaScript development
- Jest - Testing framework
- @vercel/ncc - Bundles TypeScript code into a single JavaScript file
- Trunk - Code quality and linting tool (configured in
.trunk/trunk.yaml) - ESLint - Code linting
- Prettier - Code formatting
This project must be built before it can run. The source code is written in TypeScript and located in src/, but the actual GitHub Action runs the bundled JavaScript file from dist/index.js.
To build the project, run:
pnpm buildThis command uses @vercel/ncc to bundle src/index.ts into dist/index.js, which is what gets executed when the GitHub Action runs (as specified in action.yaml).
Important: The code is automatically built before each commit via a pre-commit git hook. This is configured in .trunk/trunk.yaml and runs pnpm build && git add dist/index.js automatically. This ensures that:
- The built code is always up-to-date with your changes
- Tests can run against the built code (tests import from the built
dist/directory) - The committed code is ready to run in GitHub Actions
You don't need to manually build before committing, but you may want to build manually to test your changes locally.
The analytics-uploader is a wrapper around the trunk-io/analytics-cli tool. It provides a GitHub Actions interface for uploading test results to Trunk Analytics.
-
CLI Download and Caching
- The action downloads the
trunk-analytics-clibinary from GitHub releases (trunk-io/analytics-cli) - The binary is downloaded based on the platform and architecture (Linux x64/ARM64, macOS x64/ARM64, Windows x64)
- When
use-cacheis enabled, the binary is cached using GitHub Actions cache to reduce download times - The CLI version can be specified via the
cli-versioninput (defaults tolatest)
- The action downloads the
-
Flag Parsing and Forwarding
- GitHub Actions inputs are parsed from
action.yamlandcore.getInput() - Flags are converted from GitHub Actions input format to CLI flag format
- Boolean inputs are converted to flags like
--flag=trueor--flag=false - All flags are passed to the underlying
trunk-analytics-clibinary via command-line arguments - The command is constructed in
src/lib.tsin themain()function
- GitHub Actions inputs are parsed from
-
Telemetry Integration
- The action integrates with internal telemetry services to report failures
- Failure reasons are captured and reported when the CLI execution fails
- Telemetry failures are non-blocking and won't affect the action's execution
Here's how flags flow through the system:
- GitHub Actions Input → Defined in
action.yaml(e.g.,junit-paths,org-slug,verbose) - Input Parsing →
getInputs()function insrc/lib.tsreads inputs viacore.getInput() - Flag Conversion → Boolean inputs are converted using
parseBoolIntoFlag(), other inputs are formatted as CLI arguments - Command Construction → Flags are assembled into a command string in the
main()function - CLI Execution → The command is executed via
execSync(), passing all flags to the downloadedtrunk-analytics-clibinary
Example: The GitHub Actions input verbose: true becomes the CLI flag -v in the command.
Tests are located in the __tests__/ directory and use Jest. To run tests:
pnpm testNote: Tests import from the built code in dist/, so you need to build the project before running tests:
pnpm build
pnpm testThe pre-commit hook ensures the build is up-to-date, but for local development, you may need to build manually.
Tests use mocks for GitHub Actions modules (@actions/core, @actions/github) and global.fetch to avoid making real API calls during testing. The test fixtures are located in __fixtures__/.
Utilizing @github/local-action, this action can be run locally. To do so copy and update .env.example to .env and then run pnpm run local-action. At a minimum, INPUT_ORG-SLUG and INPUT_TOKEN need to be updated with your own values to complete an upload.
In .env inputs for the action can be specified with INPUT_<UPPERCASE-OF-INPUT-NAME> e.x. INPUT_REPO-ROOT or INPUT_CLI-VERSION. See action.yaml for the full list of inputs.
- Make your changes in
src/ - Build the project:
pnpm build(or let the pre-commit hook do it) - Run tests:
pnpm test - Check code quality: Trunk will run automatically on pre-commit, or you can run
trunk checkmanually - Commit: The pre-commit hook will automatically build and stage
dist/index.js
Releases are manually created via the Releases tab on GitHub:
- Go to the repository's Releases page on GitHub
- Click "Draft a new release"
- Create a new tag (e.g.,
v2.0.0) and generate release notes - Publish the release
After creating a new release and verifying it works correctly, update the major version tag (e.g., v2) to point to the latest release using the Update release version workflow:
- Go to the Actions tab on GitHub
- Select the Update release version workflow
- Click Run workflow
- Provide the following inputs:
- target: The tag of the release you just created (e.g.,
v1.2.3) - major_version: The major version tag to update (
v1orv2)
- target: The tag of the release you just created (e.g.,
- Run the workflow
This will move the major version tag (e.g., v2) to point to the specified release tag, allowing users to reference the action with a major version that automatically points to the latest release in that version line.
src/- TypeScript source codeindex.ts- Entry pointlib.ts- Main logic, CLI download, flag parsing, telemetry
dist/- Built JavaScript (generated, do not edit directly)__tests__/- Test files__fixtures__/- Test mocks and fixturesaction.yaml- GitHub Actions action definition
If you have questions or need help, please:
- Check the README.md for usage information
- Open an issue on GitHub
- Contact the maintainers