# CI/CD

## GitHub Workflows

- `pr.yml`:
  - Runs tests for all pull requests
  - Runs `nx affected`, which only executes tasks with invalidated cache
  - Also uses `pkg-pr-new` to publish package previews and create links to our examples
- `release.yml`:
  - Runs tests for code merged into release branches
  - Runs `nx run-many`, which executes all tasks and ensures the outputs are present (necessary for publishing builds)
  - Uses [Changesets](https://github.com/changesets/changesets) to handle versioning and publishing
  - Creates a `vX.Y.Z` release for the shared actions when their version changes

## Shared Actions

Other TanStack repositories use three composite actions from this repository:

- `.github/setup`: sets up Node and pnpm
- `.github/changeset-preview`: comments on a pull request with the versions Changesets would release
- `.github/comment-on-release`: comments on pull requests and linked issues once they are released

The three actions share one version. Pin them to the commit of a release and put the release tag in the comment:

```yaml
- name: Setup Tools
  uses: TanStack/config/.github/setup@<commit-sha> # v1.0.0
```

Each "Actions vX.Y.Z" [release](https://github.com/TanStack/config/releases) lists the commit to pin. Renovate updates the commit and the comment together when a new release exists.

Do not put `# main` in the comment. zizmor checks that the ref in the comment still points at the pinned commit, and `main` moves with every package release.

### Releasing the Actions

Changesets versions the actions as the private package `@tanstack/config-actions` in `.github/package.json`. When you change an action, add a changeset for that package. After the "Version Packages" pull request is merged, `release.yml` creates the `vX.Y.Z` release for the new version.

Changesets would tag the package as `@tanstack/config-actions@X.Y.Z`, and Renovate does not read that as a version. The workflow creates the plain `vX.Y.Z` tag for that reason.

Release tags are immutable. Do not add a moving `v1` tag: a `# v1` comment would fail zizmor every time the tag moves.

## Nx

The TanStack projects use Nx to enable rapid execution of our tests and builds. Tasks are parallelised and cached both locally and in CI. While Nx has an extensive plugin system, we only utilise Nx as an NPM script runner.

### Config Files

- `./nx.json`: Main config file, which defines task dependencies, inputs, and outputs
- `./package.json`: Need to manually specify root-level scripts (e.g. `test:eslint`)
- `./**/package.json`: Package-level scripts (e.g. `build`) are automatically detected

### Nx Agents

- Nx allows you to distribute your tasks across multiple CI machines, increasing the number of jobs that can be run in parallel
- Please note that this does incur quite a significant startup delay
