Shared github workflows created by the digicatapult organisation.
The following workflows are included in this repository
Synchronises the version in a package.json on a pull-request branch in relation to a trunk branch based on the presence of one of three labels: [v:major, v:minor, v:patch]. The workflow calculates the next version by incrementing the trunk branch version according to the label (major increments X.0.0, minor increments 0.X.0, patch increments 0.0.X). If the PR's current version doesn't match the expected version, the workflow commits the correction. The v:stale label is removed if present to indicate the version is now current. This workflow is typically called from repository-specific workflows when PR labels are added or changed.
| input | type | description | default |
|---|---|---|---|
pr-number |
number |
The PR to run this workflow for | |
trunk-branch |
string |
The trunk branch to synchronise against | main |
This workflow also requires two secrets in order to run
| secret | description |
|---|---|
bot-id |
Id of the Github App to use when committing version updates |
bot-key |
Private Key for the Github App |
Synchronises the version in package.json for all open pull-requests that have one of the version labels: [v:major, v:minor, v:patch]. This workflow finds all PRs with these labels and calls the Synchronise PR Version workflow for each one. It's useful after the trunk branch version changes to ensure all open PRs have the correct calculated versions. Like the single PR workflow, it removes the v:stale label and commits corrections as needed.
| input | type | description | default |
|---|---|---|---|
trunk-branch |
string |
The trunk branch to synchronise against | main |
This workflow also requires two secrets in order to run
| secret | description |
|---|---|
bot-id |
Id of the Github App to use when committing version updates |
bot-key |
Private Key for the Github App |
Builds a Docker container and optionally pushes it to GitHub Container Registry (GHCR), DockerHub, or both. The workflow is configurable to support multi-platform builds and various tagging options.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| build_args | string | Build arguments to pass to Docker build | "" |
false |
| env_vars | string | JSON string of environment variables in key:value format, parsed and added to $GITHUB_ENV at the start of the run |
{} |
false |
| push_dockerhub | boolean | Whether to push the built image to DockerHub | false |
false |
| push_ghcr | boolean | Whether to push the built image to GHCR | false |
false |
| docker_platforms | string | Specifies architectures to build the container for | "linux/amd64,linux/arm64" |
false |
| docker_file | string | Dockerfile to be used for building the container | Dockerfile |
false |
| Secret | Description |
|---|---|
| DOCKERHUB_USERNAME | DockerHub username used for authentication when pushing to DockerHub |
| DOCKERHUB_TOKEN | DockerHub token (or password) used for authentication when pushing to DockerHub |
This GitHub Actions workflow is designed to build a Docker container, optionally pushing it to GHCR and/or DockerHub. It includes multi-platform support and customizable tagging for version management. Key steps are as follows:
- Repository Identifier Extraction: Captures the repository and organization names, converting them to lowercase for consistency in tags.
- Set Environment Variables: Parses JSON
env_varsand sets them in the workflow environment. - Version Management: Uses
digicatapult/check-versionto determine the version and release type, which is then used in image tagging. - Docker Setup:
- QEMU Setup: Enables emulation for multi-platform builds.
- Buildx Setup: Sets up Docker Buildx for advanced build features.
- Tag Generation: Based on version data and push preferences, generates tags for GHCR and DockerHub, including
:latesttags for stable releases. - Generate CVEs with Docker Scout: Scout is used to generate a SARIF report from any CVEs found for the image.
- Upload Scout's SARIF results: Any SARIF findings are pushed to GitHub's Advanced Security API.
- Push to GHCR Only: If
push_ghcris true andpush_dockerhubis false, builds and pushes the image to GHCR. - Push to DockerHub Only: If
push_dockerhubis true andpush_ghcris false, builds and pushes the image to DockerHub. - Push to Both GHCR and DockerHub: If both
push_ghcrandpush_dockerhubare true, builds and pushes the image to both registries. - Build Only: If neither
push_ghcrnorpush_dockerhubare true, builds the image without pushing to any registry.
For all images, the workflow adds OCI-compliant metadata labels to enrich the image with information about the repository source, version, and build date. This metadata provides valuable information for tracking the image’s origin and history.
This workflow is versatile, offering a full pipeline for Docker image creation and optional registry publishing, adapting to a range of requirements from simple builds to multi-platform, multi-registry deployments.
Determines the versioning information of the repository, setting output values related to version, release type, and build date. This workflow is typically used as a prerequisite step in other workflows that need version information for tagging, releasing, or publishing. It detects if the current commit represents a new version by comparing the package.json version against existing git tags, determines if the version follows pre-release naming conventions (e.g., contains alpha, beta, rc), and captures the build timestamp.
| Output | Type | Description |
|---|---|---|
| is_new_version | boolean | Indicates if the detected version is a new release |
| version | string | The current version string |
| build_date | string | The date when the build was initiated |
| is_prerelease | boolean | Indicates if the version is a pre-release |
This GitHub Actions workflow verifies and checks the versioning details of the repository. It uses the digicatapult/check-version action to assess the version information, outputting details such as whether it’s a new version, the version string, if it's a pre-release, and the build date. These outputs can be used by subsequent jobs to conditionally perform tasks based on the versioning state.
Automates the release process on GitHub, creating a versioned release based on the repository's current version. This workflow is typically called after merging to the main branch when a new version is detected. It creates two GitHub releases: one with the specific version tag (e.g., v1.2.3) and another that updates the latest tag to point to this release. Release notes are automatically generated from the most recent merged PR's body, extracting sections for linked tickets, high-level description, and detailed description.
| Input | Type | Description | Default |
|---|---|---|---|
| env_vars | string | A JSON string representing environment variables in the format key:value; parsed and added to $GITHUB_ENV at the beginning of the run |
{} |
| get_sbom | boolean | An option to disable the retrieval of SBOM artefacts, e.g. if none are expected from other workflows | true |
This GitHub Actions workflow creates a new release on GitHub. It uses the digicatapult/check-version action to determine the current version and then applies softprops/action-gh-release to create a versioned release and update the latest release tag. The process involves:
- Setting Environment Variables: Parses and sets environment variables from a JSON string.
- Version Check: Uses
digicatapult/check-versionto retrieve the current version information. - Generate Release Notes: Creates release notes based on the PR Body used by Digital Catapult.
- Build Versioned Release: Creates a GitHub release using the version retrieved from the Version Check step and SBOMs if available.
- Build Latest Release: Updates the
latesttag to point to the newly created release.
This workflow helps streamline the release process by automating version checks and tagging, making it easy to manage versioned releases and update the latest release reference.
Publishes an NPM package to the specified registry, optionally building the package before publishing. This workflow supports configurable registry details, package access settings, and the option to build the package.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| env_vars | string | A JSON string representing environment variables in the format key:value; parsed and added to $GITHUB_ENV at the beginning of the run |
{} |
false |
| node_version | string | The node version to use | 24.x |
false |
| registry_url | string | The NPM registry URL to which the package will be published | https://registry.npmjs.org |
false |
| registry_scope | string | The NPM registry scope to use for the package | @digicatapult |
false |
| npm_build_command | string | CLI command to run as a build step. Skipped if empty string | '' |
false |
| package_access | string | The access level for the published package (public or restricted) |
public |
false |
| Secret | Description |
|---|---|
| REGISTRY_AUTH_TOKEN | Authentication token required to publish the package to the NPM registry. Only needed if registry_url is not https://npm.pkg.github.com |
This GitHub Actions workflow publishes an NPM package, optionally building it beforehand. It is highly configurable, allowing users to specify registry details, scope, and access level. The workflow includes the following steps:
- Setting Environment Variables: Parses and sets environment variables from a JSON string.
- Version Check: Uses
digicatapult/check-versionto retrieve the current version information. - Node Setup: Configures the Node.js environment, including setting the registry URL and scope.
- Install Packages: Installs the package dependencies.
- Build: Builds the package if
npm_build_commandis provided. - Publish to NPM: Publishes the package to the specified registry with the given access level, using the provided authentication token.
This workflow simplifies the process of publishing NPM packages by handling environment setup, versioning, and publication in a single automated sequence.
Generates a Software Bill of Materials (SBOM) for an NPM project using CycloneDX tools. This workflow supports multiple generation tools, output formats, and optional build steps.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| dtrack_project_name | string | A project name to use within Dependency Track | ${{ github.event.repository.name }} |
false |
| enable_check_version | boolean | An option to enable the use of the digicatapult/check-version action | false |
false |
| enable_dtrack_project | boolean | An option to enable the use of Dependency Track | false |
false |
| env_vars | string | A JSON string representing environment variables in the format key:value; parsed and added to $GITHUB_ENV at the beginning of the run |
{} |
false |
| node_version | string | The node version to use | 24.x |
false |
| sbom_tool | string | SBOM generation tool to use. Options: @cyclonedx/cyclonedx-npm, @cyclonedx/cdxgen |
@cyclonedx/cyclonedx-npm |
false |
| sbom_format | string | SBOM output format. Options: json, xml |
json |
false |
| sbom_output_file | string | Custom output filename. Defaults to {repo-name}.cdx.{format} |
"" |
false |
| npm_build_command | string | Optional build command to run before generating SBOM | "" |
false |
| additional_args | string | Additional arguments to pass to the SBOM generation tool | "" |
false |
| upload_artifact | boolean | Whether to upload the SBOM as a workflow artifact | true |
false |
| Secret | Description |
|---|---|
DTRACK_APIKEY |
The Dependency Track API key; requires both the BOM_UPLOAD and PROJECT_CREATION_UPLOAD permissions |
DTRACK_HOSTNAME |
The hostname of the Dependency Track server; the HTTP schema is set separately with the inputs protocol (default: https) and port (443) |
| Output | Description |
|---|---|
| sbom_file | The name of the generated SBOM file |
This GitHub Actions workflow generates an SBOM for an NPM project. It allows flexibility in choosing the generation tool and format.
- Set Environment Variables: Parses and sets environment variables from a JSON string.
- Node Setup: Configures the Node.js environment.
- Install Packages: Installs project dependencies.
- Build (Optional): Runs a build command if specified, useful for projects that need compilation before SBOM generation.
- Generate SBOM: Uses the selected tool (
@cyclonedx/cyclonedx-npmor@cyclonedx/cdxgen) to generate the SBOM. - Upload Artifact: Optionally uploads the generated SBOM file as a workflow artifact.
- Upload SBOM to Dependency Track: Optionally uploads the CycloneDX SBOM to a DT server. Docker Scout SBOMs are currently incompatible with DT due to inaccuracies in the CycloneDX spec implementation; CycloneDX-NPM is a more faithful implementation. To upload successfully, the step must have a DT hostname via the
DTRACK_HOSTNAMEsecret and an API key (DTRACK_APIKEY) with both theBOM_UPLOADandPROJECT_CREATION_UPLOADpermissions.
Performs configurable static analysis checks on an NPM project, such as linting, dependency checking, XSS scanning, and additional checks, based on the specified commands.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| enable_semgrep_action | bool | An option to enable a Semgrep CE scan for bugs, security vulnerabilities, and compliance issues | true | false |
| enable_trufflehog_action | bool | An option to enable a TruffleHog GitHub Actions, scanning for exposed secrets | false | false |
| env_vars | string | A JSON string representing environment variables in the format key:value; parsed and added to $GITHUB_ENV at the beginning of the run |
{} |
false |
| node_version | string | The node version to use | 24.x |
false |
| matrix_commands | string | A JSON array of commands to run in the static checks matrix, each representing an NPM script defined in the package | ["lint","depcheck","check"] |
false |
| semgrep_extra_args | string | Extra arguments to be passed to the Semgrep CE CLI | '--config="p/default"' |
false |
| semgrep_sarif_path | string | A file path used to locate the SARIF result(s) from the Semgrep CLI | semgrep.sarif |
false |
| semgrep_upload_type | string | Upload format for Semgrep results; "sarif" uses the CodeQL SARIF upload action, "artefact" uses vanilla artefact upload, and "none" skips | sarif |
false |
| trufflehog_extra_args | string | Extra arguments to be passed to the TruffleHog CLI | "--results=verified,unknown" |
true |
This GitHub Actions workflow runs a series of static checks on an NPM project based on a configurable list of commands. The commands run in parallel through a matrix strategy, allowing selective failure without interrupting the entire workflow.
- Setting Environment Variables: Parses and sets environment variables from a JSON string.
- Node Setup: Configures the Node.js environment.
- Node Modules Caching: Caches
node_modulesbased on thepackage-lock.jsonhash to speed up dependency installation. - Install Packages: Installs the necessary dependencies.
- Run Static Checks: Executes each specified command in the matrix (
lint,depcheck,checkor others as configured) as defined in the NPM scripts. - Secrets Scanning: Run TruffleHog against the calling branch for both verified and unverified secrets.
- Vulnerability Scanning: Run Semgrep CE to identify security vulnerabilities and upload the results in SARIF format to GitHub.
This flexible workflow enables dynamic static analysis checks to maintain code quality, making it adaptable to different project requirements.
Executes end-to-end (E2E) tests for an NPM project using Docker Compose, supporting optional build commands and project-specific configurations.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| env_vars | string | JSON string of environment variables in key:value format, parsed and added to $GITHUB_ENV at the beginning of the run |
{} |
false |
| npm_build_command | string | Optional command to build the application before running tests | "" |
false |
| pre_test_command | string | Optional command to execute before running the main test command | "" |
false |
| docker_compose_file | string | The Docker Compose file used for building the testing environment | docker-compose.yml |
false |
| node_version | string | The node version to use | 24.x |
false |
| test_command | string | Command used to run E2E tests, which can be customized as needed | "npm run test:e2e" |
false |
This GitHub Actions workflow is tailored for running end-to-end tests within a Dockerized environment, with customizable build and test steps. The workflow supports conditional handling for specific repositories that require additional environment variables or secrets during test execution.
- Set Environment Variables: Parses and applies environment variables from a JSON string to the workflow environment.
- Docker Buildx Setup: Configures Docker Buildx for advanced Docker build support.
- Build E2E Containers: Uses Docker Bake to build containers based on the provided Docker Compose file.
- Build Step (Optional): Runs the specified
npm_build_commandif provided. - Pre-Test Command (Optional): Executes
pre_test_commandbefore running tests if specified. - Run E2E Tests: Executes the test command with repository-specific environment variables injected as needed.
- Upload Playwright Report: Saves the Playwright report as an artifact, accessible for 90 days.
- Publish CTRF Test Summary: Publishes a summary of the test results in CTRF format for comprehensive reporting.
This workflow is designed to accommodate different testing needs, offering flexibility with custom commands and environment-specific configurations for robust E2E testing.
Runs specified NPM tests (e.g., unit and integration tests) with optional build and pre-test commands, as well as Docker-based dependency setup. Collects and reports code coverage by default, comparing coverage between the current branch and main branch.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| env_vars | string | JSON string of environment variables in key:value format, parsed and added to $GITHUB_ENV at the start of the run |
{} |
false |
| npm_build_command | string | Optional command to build the application before running tests | "" |
false |
| pre_test_command | string | Optional command to execute before the main test command | "" |
false |
| docker_compose_file | string | The Docker Compose file to use for setting up dependencies | docker-compose.yml |
false |
| node_version | string | The node version to use | 24.x |
false |
| tests | string | JSON array of test commands defined in NPM scripts (e.g., ["test:unit", "test:integration"]) |
["test:unit","test:integration"] |
false |
| coverage | boolean | Whether to collect and report code coverage | true |
false |
| coverage_config_json | string | Path to a custom c8 configuration JSON file | "" |
false |
This GitHub Actions workflow runs a series of NPM test commands in a matrix strategy, testing both the current branch and main branch for coverage comparison. Each test command runs as a separate matrix job. When coverage is enabled, it collects coverage data from all test jobs and generates a comprehensive comparison report.
Tests Job:
- Set Environment Variables: Parses
env_varsfrom JSON and sets them in the workflow environment. - Node Setup: Installs the specified Node.js version.
- Node Modules Caching: Caches
node_modulesbased onpackage-lock.jsonfor faster dependency installation. - Install Packages: Installs project dependencies using
npm ci. - Get Coverage Temp Directory: Determines the coverage temporary directory from the provided config file or uses the default
coverage/tmp. - Build Step (Optional): Executes
npm_build_commandif it is provided. - Environment File Creation: Creates a
.envfile for environment configuration. - Setup Docker Dependencies: Brings up services defined in the specified Docker Compose file to support test dependencies.
- Wait for Initialization: Adds a delay to ensure all Docker services are ready.
- Pre-Test Command (Optional): Runs
pre_test_commandif provided. - Run Tests: Executes each test command using c8 for coverage collection (e.g.,
npx c8 npm run test:unit). - Upload Coverage: If
coverageis enabled, uploads coverage data from each test job, tagged by branch and test command.
Coverage Job:
- Setup c8 Config: Uses the provided
coverage_config_jsonif specified, otherwise creates a default configuration. - Download Coverage Artifacts: Downloads coverage summaries from both the current branch and main branch test jobs.
- Generate Reports: Creates HTML, JSON summary, and JSON reports for the current branch coverage.
- Generate Main Branch Reports: Creates JSON summary and JSON reports for the main branch coverage in a separate directory.
- Setup Vite Config: Checks for an existing vite/vitest config file, creating a minimal one if none exists to prevent warnings from the coverage report action.
- Pretty Coverage Summary: Uses
davelosert/vitest-coverage-report-actionto generate a formatted coverage report with trend indicators comparing current branch to main. - Upload Reports for Current Branch: Saves current branch coverage reports as an artifact.
- Fail if Under Thresholds: Runs c8's threshold check, failing the workflow if coverage is below configured thresholds.
This workflow provides a comprehensive testing and coverage solution with branch comparison, custom build commands, Docker-based dependencies, and detailed coverage reporting including trend analysis.
Runs scanners to detect the exposure of secrets, with the option to add in extra arguments to exclude directories, fail on detection, or output the results in JSON format.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| base | string | An optional branch to base the scan on | "" |
false |
| enable_trufflehog_action | bool | An option to enable a TruffleHog GitHub Actions, scanning for exposed secrets | false | true |
| env_vars | string | Extra variables to be passed to the environment | {} |
false |
| extra_args | string | Extra arguments to be passed to the TruffleHog CLI | "--results=verified,unknown" |
true |
This GitHub Actions workflow runs TruffleHog scans.
- Set Environment Variables: Parses
env_varsfrom JSON and sets them in the workflow environment. - TruffleHog PR Scan: Execute the TruffleHog scan of the PR, checking for verified and unverified secrets.
This workflow can be complemented with the complete list of TruffleHog arguments, found in that project's repository.
Runs scanners to detect bugs, security vulnerabilities, and compliance issues, with the option to add in extra arguments, e.g. additional Semgrep rulesets.
| Input | Type | Description | Default | Required |
|---|---|---|---|---|
| enable_semgrep_action | bool | An option to enable a Semgrep CE scan for bugs, security vulnerabilities, and compliance issues | true | false |
| extra_args | string | Extra arguments to be passed to the Semgrep CE CLI | '--config="p/default"' |
false |
| sarif_path | string | A file path used to locate the SARIF result(s) from the Semgrep CLI | semgrep.sarif |
false |
| upload_type | string | Upload format for Semgrep results; "sarif" uses the CodeQL SARIF upload action, "artefact" uses vanilla artefact upload, and "none" skips | sarif |
false |
This GitHub Actions workflow runs Semgrep CE vulnerability scans.
- Semgrep CE Scan: Execute the Semgrep CE CLI scan.
- Upload Semgrep CE's SARIF Results: Upload the results to GitHub either as a SARIF report directly to the GitHub Advanced Security panel or as an artefact.
This workflow can be complemented with rulesets from the Semgrep registry of first- and third-party rules.