Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ workflows:
```

The `rust` module installs the toolchain your project pins, caches cargo's downloads and build output, and adds
`Cargo.toml`, `Cargo.lock` and the toolchain file to the job's hash. `node`, Playwright and services are next.
`Cargo.toml`, `Cargo.lock` and the toolchain file to the job's hash. The `node` module does the same for
Node with npm, pnpm or Yarn. Playwright and services are next.

## Install

Expand Down
59 changes: 56 additions & 3 deletions docs/src/content/docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A module is setup you'd otherwise paste into every job: installing a toolchain,
that setup depends on. A job lists its modules under `modules:`, and cigen expands each into ordinary steps before a
provider sees the job.

The project in this page's examples is a Rust crate:
The project in this page's examples is a Rust crate with a Node frontend:

```toml title="Cargo.toml"
[package]
Expand Down Expand Up @@ -98,8 +98,61 @@ It installs with `rustup`, which GitHub's runners and the Rust images ship. On G
architecture, the toolchain and `Cargo.lock`. Its full reference is
[`src/modules/rust/README.md`](https://github.com/DocSpring/cigen/blob/main/src/modules/rust/README.md).

## The `node` module

Installs Node and the package manager your project pins (npm, pnpm or Yarn), runs a frozen install, and caches the
package manager's downloads. Node's version comes from `.nvmrc` or `.node-version`, else `engines.node` in
`package.json`, and pnpm's or Yarn's from `packageManager` in `package.json`:

```json title="package.json"
{
"private": true,
"packageManager": "pnpm@9.15.0",
"scripts": { "lint": "eslint ." }
}
```

```yaml title="pnpm-lock.yaml"
lockfileVersion: '9.0'
```

```text title=".nvmrc"
22
```

```yaml
# cigen.yml
provider: github

workflows:
ci:
jobs:
lint:
modules: [node]
inputs: ['src/**']
steps:
- run: pnpm lint
```

| Parameter | Default | Meaning |
| ----------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `version` | what `.nvmrc` or `.node-version` in `path` or the root says, else `package.json`'s `engines.node`, else an error | a Node version, or `preinstalled` for the Node the image or runner already has |
| `package_manager` | `package.json`'s `packageManager`, else the one lockfile present, else an error | `npm`, `pnpm` or `yarn` |
| `install` | `true` | run a frozen install (`npm ci`, `pnpm install --frozen-lockfile`, `yarn install --immutable`) |
| `cache` | `true` | cache the package manager's downloads |
| `path` | `.` | the directory holding `package.json` and the lockfile |

On GitHub Actions it uses `pnpm/action-setup` for pnpm, Corepack for Yarn, and `actions/setup-node` (pinned to commits)
with its cache. On CircleCI, Node comes from the job's image: a `cimg/node` or `node` image whose tag starts with the
pinned version, or any image with `version: preinstalled`; pnpm and Yarn come through Corepack, and the cache through
`restore_cache` and `save_cache`. It adds every tracked `package.json` under `path`, and in `path` and each folder above
it the lockfiles, workspace and package manager config, the pnpmfile, Yarn's plugins, releases and cache, patches and
the version files, to the job's inputs, along with files the config names elsewhere (a `pnpmfile`, Yarn's `yarnPath`,
plugins, `cacheFolder` and `patchFolder`). A loose version (`22`, `lts/*`, an `engines.node` range) resolves when the job
runs, and only the spec is hashed, so a new Node release doesn't rerun a job that passed. Its full reference is
[`src/modules/node/README.md`](https://github.com/DocSpring/cigen/blob/main/src/modules/node/README.md).

## More modules

`rust` is the first. Node with npm, pnpm or Yarn comes next, then Playwright, services (Postgres, an S3-compatible
store), a shared compile cache and Ruby with Bundler. The
Playwright, services (Postgres, an S3-compatible store), a shared compile cache and Ruby with Bundler come next. The
[module catalogue](https://github.com/DocSpring/cigen/blob/main/src/modules/README.md) lists the ones that exist.
6 changes: 3 additions & 3 deletions docs/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const skipped = run.jobs.filter((job) => job.status === 'skipped').length;

<section class="modules wrap" aria-labelledby="modules-title">
<div class="modules__head">
<p class="chip chip--soon"><span class="chip__dot" aria-hidden="true"></span>Started · rust is built; node, Playwright and services are coming</p>
<p class="chip chip--soon"><span class="chip__dot" aria-hidden="true"></span>Started · rust and node are built; Playwright and services are coming</p>
<h2 id="modules-title">Modules replace the setup you paste into every job</h2>
<p>
Toolchains, dependency caches, services and upload steps, pinned and tested once. Each module also adds the
Expand Down Expand Up @@ -197,15 +197,15 @@ const skipped = run.jobs.filter((job) => job.status === 'skipped').length;
<li>Skipping on GitHub Actions, with markers in its cache</li>
<li>Generated workflows install a checksum-checked cigen release</li>
<li>Byte-for-byte deterministic output</li>
<li>Modules, starting with <code>rust</code></li>
<li>Modules for Rust and Node</li>
</ul>
</div>
<div>
<p class="label">Coming</p>
<ul class="ticks ticks--soon">
<li>The v0.2.0 release, the first those workflows can install</li>
<li>A planner job, so skipped jobs never start a runner</li>
<li>More modules: Node, Playwright, services and caches</li>
<li>More modules: Playwright, services and caches</li>
<li><code>cigen plan</code>: which jobs will run or skip, and why</li>
<li>Free hosted pass records on VisualCI, shared across branches</li>
<li>Skipping on CircleCI</li>
Expand Down
248 changes: 248 additions & 0 deletions integration_tests/module_node/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
version: '2.1'
setup: true
parameters:
skip_cache:
type: boolean
default: false
description: Disable job-status cache and rerun all jobs
orbs:
continuation: circleci/continuation@1.0.0
commands:
cigen_shallow_checkout:
description: |
Fast shallow git checkout using configurable clone depth and options. 99% faster than full checkout for most CI jobs that don't need git history.
parameters:
clone_options:
type: string
default: --depth 1
description: |
git clone options such as '--depth 1 --verbose' or '--depth 1 --shallow-since "5 days ago"'
fetch_options:
type: string
default: --depth 10
description: |
git fetch options such as '--depth 1 --verbose' or '--depth 1 --shallow-since "5 days ago"' Note: '--force' is already set by default. For tags, use tag_fetch_options instead.
tag_fetch_options:
type: string
default: --tags
description: |
Git fetch options specifically for tag operations. Use fetch_options for PR and other operations. To exclude tags, use '--no-tags' in both this option and tag_fetch_options.
keyscan_github:
type: boolean
default: false
description: |
Enable SSH keyscan for github.com
keyscan_gitlab:
type: boolean
default: false
description: |
Enable SSH keyscan for gitlab.com
keyscan_bitbucket:
type: boolean
default: false
description: |
Enable SSH keyscan for bitbucket.org
path:
type: string
default: .
description: |
Checkout directory (default: job working_directory)
steps:
- run:
name: Shallow Git Checkout
command: |
# Shallow checkout implementation
# Based on git-shallow-clone-orb (MIT license)

set -e

# Set parameters
CLONE_OPTIONS="<< parameters.clone_options >>"
FETCH_OPTIONS="<< parameters.fetch_options >>"
TAG_FETCH_OPTIONS="<< parameters.tag_fetch_options >>"
KEYSCAN_GITHUB="<< parameters.keyscan_github >>"
KEYSCAN_GITLAB="<< parameters.keyscan_gitlab >>"
KEYSCAN_BITBUCKET="<< parameters.keyscan_bitbucket >>"
CHECKOUT_PATH="<< parameters.path >>"

# Verify ssh is available (required for git ssh operations and keyscan)
if ! command -v ssh >/dev/null 2>&1; then
echo "ERROR: ssh command not found" >&2
echo "" >&2
echo "You must run this command from a Docker image that has openssh-client installed." >&2
echo "" >&2
echo "Use a CircleCI convenience image (cimg/*) or install openssh-client in your Dockerfile:" >&2
echo " - Debian/Ubuntu: RUN apt-get update && apt-get install -y openssh-client" >&2
echo " - Alpine: RUN apk add --no-cache openssh-client" >&2
echo " - RHEL/CentOS: RUN yum install -y openssh-clients" >&2
exit 1
fi

# Create SSH directory if not exists
if [ ! -d ~/.ssh ]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
fi

# Add SSH host keys based on keyscan parameters
if [ "$KEYSCAN_GITHUB" = "true" ]; then
echo "Adding GitHub SSH host key..."
ssh-keyscan -H github.com >> ~/.ssh/known_hosts 2>/dev/null || true
fi

if [ "$KEYSCAN_GITLAB" = "true" ]; then
echo "Adding GitLab SSH host key..."
ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts 2>/dev/null || true
fi

if [ "$KEYSCAN_BITBUCKET" = "true" ]; then
echo "Adding Bitbucket SSH host key..."
ssh-keyscan -H bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null || true
fi

# Set up repository URL and branch info
if [ -n "$CIRCLE_REPOSITORY_URL" ]; then
REPO_URL="$CIRCLE_REPOSITORY_URL"
else
echo "Error: CIRCLE_REPOSITORY_URL not set"
exit 1
fi

# Determine checkout target
if [ -n "$CIRCLE_TAG" ]; then
CHECKOUT_TARGET="$CIRCLE_TAG"
FETCH_OPTIONS="$TAG_FETCH_OPTIONS"
elif [ -n "$CIRCLE_BRANCH" ]; then
CHECKOUT_TARGET="$CIRCLE_BRANCH"
else
CHECKOUT_TARGET="HEAD"
fi

echo "Repository: $REPO_URL"
echo "Target: $CHECKOUT_TARGET"
echo "Path: $CHECKOUT_PATH"
echo "Clone options: $CLONE_OPTIONS"
echo "Fetch options: $FETCH_OPTIONS"

# Create checkout directory
mkdir -p "$CHECKOUT_PATH"
cd "$CHECKOUT_PATH"

# Initialize or update repository
if [ ! -d ".git" ]; then
echo "Initializing new repository..."
git init
git remote add origin "$REPO_URL"
else
echo "Updating existing repository..."
# Ensure origin is set correctly
if git remote get-url origin >/dev/null 2>&1; then
git remote set-url origin "$REPO_URL"
else
git remote add origin "$REPO_URL"
fi
fi

# Configure Git for CircleCI
git config gc.auto 0

# Perform shallow fetch
echo "Fetching with options: $FETCH_OPTIONS"

if [ -n "$CIRCLE_TAG" ]; then
# For tags, fetch the specific tag
git fetch $FETCH_OPTIONS origin "refs/tags/$CIRCLE_TAG:refs/tags/$CIRCLE_TAG" || \
git fetch $FETCH_OPTIONS origin "$CIRCLE_TAG"
git checkout "refs/tags/$CIRCLE_TAG"
elif [ -n "$CIRCLE_SHA1" ]; then
# For specific commit
git fetch $FETCH_OPTIONS origin "$CIRCLE_SHA1" || \
git fetch $FETCH_OPTIONS origin "$CHECKOUT_TARGET"
git checkout "$CIRCLE_SHA1" 2>/dev/null || git checkout "$CHECKOUT_TARGET"
else
# For branch
git fetch $FETCH_OPTIONS origin "$CHECKOUT_TARGET:$CHECKOUT_TARGET" || \
git fetch $FETCH_OPTIONS origin "$CHECKOUT_TARGET"
git checkout "$CHECKOUT_TARGET"
fi

# Show final state
echo "Checked out to: $(git rev-parse HEAD)"
echo "Current branch/tag: $(git describe --always --tags 2>/dev/null || git rev-parse --abbrev-ref HEAD)"

# Set CircleCI environment variables for consistency
echo "export GIT_COMMIT_SHA=\"$(git rev-parse HEAD)\"" >> $BASH_ENV
echo "export GIT_BRANCH=\"$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'HEAD')\"" >> $BASH_ENV
jobs:
setup:
docker:
- image: cimg/rust:1.76
steps:
- checkout
- run:
name: Handle skip_cache parameter
command: |
set -euo pipefail
if [ "<< pipeline.parameters.skip_cache >>" = "true" ]; then
cigen generate main
circleci step halt
fi
- run:
name: Prepare skip list
command: |
rm -rf /tmp/skip && mkdir -p /tmp/skip /tmp/cigen /tmp/cigen_job_exists
- run:
name: Hash sources for docs
command: |
set -euo pipefail
mkdir -p /tmp/cigen
JOB_HASH=$(cigen hash --job docs --modules-digest 6309559df8466e00 | tr -d '\r')
printf '%s' "$JOB_HASH" > /tmp/cigen/job_hash
echo "export JOB_HASH=$JOB_HASH" >> $BASH_ENV
echo 'Computed hash for docs: '$JOB_HASH
- restore_cache:
name: 'Restore job status: docs'
keys:
- linux-{{ checksum "/etc/os-release" }}-job_status-exists-v1-docs-{{ checksum "/tmp/cigen/job_hash" }}
- linux-{{ checksum "/etc/os-release" }}-job_status-exists-v1-
- run:
name: 'Probe exists: docs'
command: |
set -euo pipefail
if [ -f '/tmp/cigen_job_exists/done_${JOB_HASH}' ]; then echo 'docs' >> /tmp/skip/main.txt; fi
rm -rf /tmp/cigen_job_exists
- run:
name: Hash sources for lint
command: |
set -euo pipefail
mkdir -p /tmp/cigen
JOB_HASH=$(cigen hash --job lint --modules-digest fe1690dbdc5677cc | tr -d '\r')
printf '%s' "$JOB_HASH" > /tmp/cigen/job_hash
echo "export JOB_HASH=$JOB_HASH" >> $BASH_ENV
echo 'Computed hash for lint: '$JOB_HASH
- restore_cache:
name: 'Restore job status: lint'
keys:
- linux-{{ checksum "/etc/os-release" }}-job_status-exists-v1-lint-{{ checksum "/tmp/cigen/job_hash" }}
- linux-{{ checksum "/etc/os-release" }}-job_status-exists-v1-
- run:
name: 'Probe exists: lint'
command: |
set -euo pipefail
if [ -f '/tmp/cigen_job_exists/done_${JOB_HASH}' ]; then echo 'lint' >> /tmp/skip/main.txt; fi
rm -rf /tmp/cigen_job_exists
- run:
name: Generate filtered main
command: |
set -euo pipefail
if [ -s "/tmp/skip/main.txt" ]; then
CIGEN_SKIP_JOBS_FILE="/tmp/skip/main.txt" cigen generate main
else
cigen generate main
fi
- continuation/continue:
configuration_path: .circleci/main.yml
workflows:
main:
jobs:
- setup
Loading