Skip to content
Open
57 changes: 57 additions & 0 deletions .circleci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# CircleCI Configuration

This directory contains CircleCI configuration files that are automatically generated and updated.

## Prerequisites

### CircleCI Local CLI

The CircleCI Local CLI is required to generate the `pull-request.yml` file from the source configuration.

**Installation:**

- **macOS (Homebrew):**
```bash
brew install circleci
```

- **Linux:**
```bash
curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | bash
```

- **Windows:**
```bash
choco install circleci-cli
```

- **Manual installation:**
Download from [CircleCI Local CLI releases](https://github.com/CircleCI-Public/circleci-cli/releases)

For more detailed installation instructions, see the [CircleCI Local CLI documentation](https://circleci.com/docs/2.0/local-cli/).

## Lint-Staged Rules

When files in this directory are modified, the following lint-staged rule will automatically run:

```bash
circleci config pack .circleci/workflows-src > .circleci/workflows.yml
```

This command:
1. Takes the source configuration from `./.circleci/workflows-src/`
2. Packs it into a single YAML file
3. Outputs the result to `./circleci/workflows.yml`

## File Structure

- `workflows-src/` - Source configuration files (modify these)
- `workflows.yml` - Generated configuration file (auto-generated, do not edit manually)

## Development Workflow

1. Make changes to files in `workflows-src/`
2. The lint-staged hook will automatically regenerate `workflows.yml` and stage it
3. Commit both the source changes and the generated file

**Note:** Always commit both the source files and the generated `workflows.yml` file together to ensure the CircleCI configuration stays in sync.
119 changes: 58 additions & 61 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
version: 2.1
setup: true

orbs:
continuation: circleci/[email protected]

jobs:
verify-ci-should-run:
resource_class: small
docker:
- image: cimg/node:current
steps:
- run:
name: Verify CI should run
command: |
# run CI when manually triggers via CircleCi Dashboard
if [ <<pipeline.trigger_source>> == 'api' ]; then
echo "Always run CI when manually triggered from the UI."
exit 0
fi

if [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "release/"* ]]; then
echo "Always run CI for develop and for release candidate branches."
exit 0
fi

LAST_COMMIT_MESSAGE=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_BRANCH}" | jq '.commit.message')

if [[ "$LAST_COMMIT_MESSAGE" =~ "run ci" ]]; then
echo "Always run CI when the commit message includes 'run ci'."
exit 0
fi

cancel_build () {
echo "Canceling the CI build..."
circleci-agent step halt
}

TRIGGER_INSTRUCTIONS="to trigger CI , include 'run ci' in the commit message or click the 'Trigger Pipeline' button in the CircleCI UI."

if [ ! -z "${CIRCLE_PULL_REQUEST##*/}" ]; then
DRAFT=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq '.draft')

if [[ "${DRAFT}" == true ]]; then
echo "Skipping CI; PR is in draft - $TRIGGER_INSTRUCTIONS"
cancel_build
fi

echo "Always run CI for PR that is ready for review."
exit 0
fi

echo "Skipping CI; branch in progress - $TRIGGER_INSTRUCTIONS"
cancel_build
- checkout
- continuation/continue:
configuration_path: .circleci/workflows.yml

verify-ci-should-run:
docker:
- image: cimg/node:current
resource_class: small
steps:
- run:
command: |
# run CI when manually triggers via CircleCi Dashboard
if [ <<pipeline.trigger_source>> == 'api' ]; then
echo "Always run CI when manually triggered from the UI."
exit 0
fi

if [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "release/"* ]]; then
echo "Always run CI for develop and for release candidate branches."
exit 0
fi

LAST_COMMIT_MESSAGE=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_BRANCH}" | jq '.commit.message')

if [[ "$LAST_COMMIT_MESSAGE" =~ "run ci" ]]; then
echo "Always run CI when the commit message includes 'run ci'."
exit 0
fi

cancel_build () {
echo "Canceling the CI build..."
circleci-agent step halt
}

TRIGGER_INSTRUCTIONS="to trigger CI , include 'run ci' in the commit message or click the 'Trigger Pipeline' button in the CircleCI UI."

if [ ! -z "${CIRCLE_PULL_REQUEST##*/}" ]; then
DRAFT=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq '.draft')

if [[ "${DRAFT}" == true ]]; then
echo "Skipping CI; PR is in draft - $TRIGGER_INSTRUCTIONS"
cancel_build
fi

echo "Always run CI for PR that is ready for review."
exit 0
fi

echo "Skipping CI; branch in progress - $TRIGGER_INSTRUCTIONS"
cancel_build
name: Verify CI should run
- checkout
- continuation/continue:
configuration_path: .circleci/workflows.yml
orbs:
continuation: circleci/[email protected]
setup: true
version: 2.1
workflows:
# the setup-workflow workflow is always triggered.
setup-workflow:
jobs:
- verify-ci-should-run
setup-workflow:
jobs:
- verify-ci-should-run

4 changes: 4 additions & 0 deletions .circleci/src/config/@config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 2.1
setup: true
orbs:
continuation: circleci/[email protected]
49 changes: 49 additions & 0 deletions .circleci/src/config/jobs/verify-ci-should-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource_class: small
docker:
- image: cimg/node:current
steps:
- run:
name: Verify CI should run
command: |
# run CI when manually triggers via CircleCi Dashboard
if [ <<pipeline.trigger_source>> == 'api' ]; then
echo "Always run CI when manually triggered from the UI."
exit 0
fi

if [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "release/"* ]]; then
echo "Always run CI for develop and for release candidate branches."
exit 0
fi

LAST_COMMIT_MESSAGE=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_BRANCH}" | jq '.commit.message')

if [[ "$LAST_COMMIT_MESSAGE" =~ "run ci" ]]; then
echo "Always run CI when the commit message includes 'run ci'."
exit 0
fi

cancel_build () {
echo "Canceling the CI build..."
circleci-agent step halt
}

TRIGGER_INSTRUCTIONS="to trigger CI , include 'run ci' in the commit message or click the 'Trigger Pipeline' button in the CircleCI UI."

if [ ! -z "${CIRCLE_PULL_REQUEST##*/}" ]; then
DRAFT=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq '.draft')

if [[ "${DRAFT}" == true ]]; then
echo "Skipping CI; PR is in draft - $TRIGGER_INSTRUCTIONS"
cancel_build
fi

echo "Always run CI for PR that is ready for review."
exit 0
fi

echo "Skipping CI; branch in progress - $TRIGGER_INSTRUCTIONS"
cancel_build
- checkout
- continuation/continue:
configuration_path: .circleci/workflows.yml
2 changes: 2 additions & 0 deletions .circleci/src/config/workflows/setup-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jobs:
- verify-ci-should-run
Loading
Loading