Skip to content

Commit

Permalink
limit CI
Browse files Browse the repository at this point in the history
Signed-off-by: avifenesh <[email protected]>
  • Loading branch information
avifenesh committed Aug 15, 2024
1 parent a23028d commit 37e5b62
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 414 deletions.
130 changes: 130 additions & 0 deletions .github/DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# CI/CD Workflow Guide

TODO: Add a description of the CI/CD workflow and its components.

### Overview

Our CI/CD pipeline tests and builds our project across multiple languages, versions, and environments. This guide outlines the key components and processes of our workflow.

### Workflow Triggers

* Push to `main` branch
* Pull requests
* Scheduled runs (daily)
* Manual trigger (workflow_dispatch)

### Language-Specific Workflows

Each language has its own workflow file with similar structure but language-specific steps, for example python.yml for Python, or java.yml for Java.

### Shared Components

#### Matrix Files

While workflows are language-specific, the matrix files are shared across all workflows.
Workflows are starting by loading the matrix files from the `.github/json_matrices` directory.

* `engine-matrix.json`: Defines the versions of Valkey engine to test against.
* `build-matrix.json`: Defines the host environments for testing.
* `supported-languages-version.json`: Defines the supported versions of languages.

All matrices have a `run` like field which specifies if the configuration should be tested on every workflow run.
This allows for flexible control over which configurations are tested in different scenarios, optimizing CI/CD performance and resource usage.

#### Engine Matrix (engine-matrix.json)

Defines the versions of Valkey engine to test against:

```json
[
{ "type": "valkey", "version": "7.2.5", "run": "always" },
]
```
* `type`: The type of engine (e.g., Valkey, Redis).
* `version`: The version of the engine.
* `run`: Specifies if the engine version should be tested on every workflow.

#### Build Matrix (build-matrix.json)

Defines the host environments for testing:

```json
[
{
"OS": "ubuntu",
"RUNNER": "ubuntu-latest",
"TARGET": "x86_64-unknown-linux-gnu",
"run": ["always", "python", "node", "java"]
}
// ... other configurations
]
```
* `OS`: The operating system of the host.
* `RUNNER`: The GitHub runner to use.
* `TARGET`: The target environment.
* `run`: Specifies which language workflows should use this host configuration, always means run on each workflow trigger.

#### Supported Languages Version (supported-languages-version.json)

Defines the supported versions of languages:

```json
[
{
"language": "java",
"versions": ["11", "17"],
"always-run-versions": ["17"]
},
// ... other configurations
]
```
* `language`: The language for which the version is supported.
* `versions`: The full versions supported of the language which will test against scheduled.
* `always-run-versions`: The versions which will be tested in every workflow run.

#### Triggering Workflows

Push to main or create a pull request to run workflows automatically.
Use workflow_dispatch for manual triggers, accepting inputs of full-matrix which is a boolean value to run all configurations.
Scheduled runs are triggered daily to ensure regular testing of all configurations.

### Mutual vs. Language-Specific Components

#### Mutual

`Matrix files` - `.github/json_matrices`
`Shared dependencies installation` - `.github/workflows/install-shared-dependencies/action.yml`
`Linting Rust` - `.github/workflows/lint-rust/action.yml`

#### Language-Specific

`Package manager commands`
`Testing frameworks`
`Build processes`

### Customizing Workflows

Modify `[language].yml` files to adjust language-specific steps.
Update matrix files to change tested versions or environments.
Adjust cron schedules in workflow files for different timing of scheduled runs.

### Workflow Matrices

We use dynamic matrices for our CI/CD workflows, which are created using the `create-test-matrices` action. This action is defined in `.github/workflows/create-test-matrices/action.yml`.

#### How it works

1. The action is called with a `language-name` input and `dispatch-run-full-matrix` input.
2. It reads the `engine-matrix.json`, `build-matrix.json`, and `supported-languages-version.json` files.
3. It filters the matrices based on the inputs and the event type.
2. It generates three matrices:
- Engine matrix: Defines the types and versions of the engine to test against, for example Valkey 7.2.5.
- Host matrix: Defines the host platforms to run the tests on, for example Ubuntu on ARM64.
- Language-version matrix: Defines the supported versions of languages, for example python 3.8.

#### Outputs
- `engine-matrix-output`: The generated engine matrix.
- `host-matrix-output`: The generated host matrix.
- `language-version-matrix-output`: The generated language version matrix.

This dynamic matrix generation allows for flexible and efficient CI/CD workflows, adapting the test configurations based on the type of change and the specific language being tested.
18 changes: 12 additions & 6 deletions .github/json_matrices/build-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"RUNNER": "ubuntu-latest",
"ARCH": "x64",
"TARGET": "x86_64-unknown-linux-gnu",
"PACKAGE_MANAGERS": ["pypi", "npm"]
"PACKAGE_MANAGERS": ["pypi", "npm"],
"run": ["always", "python", "node", "java"]
},
{
"OS": "ubuntu",
Expand All @@ -14,23 +15,26 @@
"ARCH": "arm64",
"TARGET": "aarch64-unknown-linux-gnu",
"PACKAGE_MANAGERS": ["pypi", "npm"],
"CONTAINER": "2_28"
"CONTAINER": "2_28",
"run": ["python", "node", "java"]
},
{
"OS": "macos",
"NAMED_OS": "darwin",
"RUNNER": "macos-12",
"ARCH": "x64",
"TARGET": "x86_64-apple-darwin",
"PACKAGE_MANAGERS": ["pypi", "npm"]
"PACKAGE_MANAGERS": ["pypi", "npm"],
"run": ["python", "node", "java"]
},
{
"OS": "macos",
"NAMED_OS": "darwin",
"RUNNER": "macos-latest",
"ARCH": "arm64",
"TARGET": "aarch64-apple-darwin",
"PACKAGE_MANAGERS": ["pypi", "npm"]
"PACKAGE_MANAGERS": ["pypi", "npm"],
"run": ["python", "node", "java"]
},
{
"OS": "ubuntu",
Expand All @@ -40,7 +44,8 @@
"RUNNER": ["self-hosted", "Linux", "ARM64"],
"IMAGE": "node:alpine",
"CONTAINER_OPTIONS": "--user root --privileged --rm",
"PACKAGE_MANAGERS": ["npm"]
"PACKAGE_MANAGERS": ["npm"],
"run": ["node"]
},
{
"OS": "ubuntu",
Expand All @@ -50,6 +55,7 @@
"RUNNER": "ubuntu-latest",
"IMAGE": "node:alpine",
"CONTAINER_OPTIONS": "--user root --privileged",
"PACKAGE_MANAGERS": ["npm"]
"PACKAGE_MANAGERS": ["npm"],
"run": ["node"]
}
]
8 changes: 4 additions & 4 deletions .github/json_matrices/engine-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"run": "always"
},
{
"type": "valkey",
"version": "redis-7.0.15"
"type": "redis",
"version": "7.0"
},
{
"type": "valkey",
"version": "redis-6.2.14",
"type": "redis",
"version": "6.2",
"run": "always"
}
]
17 changes: 17 additions & 0 deletions .github/json_matrices/supported-languages-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"language": "java",
"versions": ["11", "17"],
"always-run-versions": ["17"]
},
{
"language": "python",
"versions": ["3.8", "3.9", "3.10", "3.11", "3.12"],
"always-run-versions": ["3.8", "3.12"]
},
{
"language": "node",
"full-versions": ["16.x", "17.x", "18.x", "19.x", "20.x"],
"always-run-versions": ["16.x", "20.x"]
}
]
54 changes: 54 additions & 0 deletions .github/workflows/create-test-matrices/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
inputs:
language-name:
description: "Language name"
required: true
dispatch-run-full-matrix:
description: "Run the full matrix"
required: false
default: "false"
outputs:
engine-matrix-output:
description: "Engine matrix"
value: ${{ steps.load-engine-matrix.outputs.engine-matrix }}
host-matrix-output:
description: "Host matrix"
value: ${{ steps.load-host-matrix.outputs.host-matrix }}
version-matrix-output:
description: "Version matrix"
value: ${{ steps.create-version-matrix.outputs.version-matrix }}

runs:
using: "composite"
steps:
- name: Load engine matrix
id: load-engine-matrix
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "push" || "${{inputs.dispatch-run-full-matrix}}" == "false" ]]; then
echo "engine-matrix=$(jq -c '[.[] | select(.run == "always")]' < .github/json_matrices/engine-matrix.json)" >> $GITHUB_OUTPUT
else
echo "engine-matrix=$(jq -c . < .github/json_matrices/engine-matrix.json)" >> $GITHUB_OUTPUT
fi
echo "engine-matrix=$(cat $GITHUB_OUTPUT)"
- name: Load host matrix
id: load-host-matrix
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "push" || "${{inputs.dispatch-run-full-matrix}}" == "false" ]]; then
echo 'host-matrix={"include":'"$(jq -c '[.[] | select(.run | type == "array" and contains(["always"]))]' .github/json_matrices/build-matrix.json)"'}' >> $GITHUB_OUTPUT
else
echo 'host-matrix={"include":'"$(jq -c '[.[] | select(.run | type == "array" and contains(["${{ inputs.language-name }}"]))]' .github/json_matrices/build-matrix.json)"'}' >> $GITHUB_OUTPUT
fi
echo "host-matrix=$(cat $GITHUB_OUTPUT)"
- name: Create version matrix
id: create-version-matrix
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "push" || "${{inputs.dispatch-run-full-matrix}}" == "false" ]]; then
echo 'version-matrix={"include":'"$(jq -c '[.[] | select(.language == "${{ inputs.language-name }}") | .["always-run-versions"] | map({version: .})]' .github/json_matrices/supported-languages-versions.json)"'}' >> $GITHUB_OUTPUT
else
echo 'version-matrix={"include":'"$(jq -c '[.[] | select(.language == "${{ inputs.language-name }}") | (.versions // .["full-versions"]) | map({version: .})]' .github/json_matrices/supported-languages-versions.json)"'}' >> $GITHUB_OUTPUT
fi
echo "version-matrix=$(cat $GITHUB_OUTPUT)"
23 changes: 12 additions & 11 deletions .github/workflows/csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ jobs:
load-engine-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load-engine-matrix.outputs.matrix }}
matrix: ${{ steps.load-engine-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Load the engine matrix
id: load-engine-matrix
shell: bash
run: echo "matrix=$(jq -c . < .github/json_matrices/engine-matrix.json)" >> $GITHUB_OUTPUT

run-tests:
needs: load-engine-matrix
timeout-minutes: 25
Expand All @@ -56,19 +56,19 @@ jobs:
engine: ${{ fromJson(needs.load-engine-matrix.outputs.matrix) }}
dotnet:
# - '6.0'
- '8.0'
- "8.0"
host:
- {
OS: ubuntu,
RUNNER: ubuntu-latest,
TARGET: x86_64-unknown-linux-gnu
}
OS: ubuntu,
RUNNER: ubuntu-latest,
TARGET: x86_64-unknown-linux-gnu,
}
# - {
# OS: macos,
# RUNNER: macos-latest,
# TARGET: aarch64-apple-darwin
# }

runs-on: ${{ matrix.host.RUNNER }}

steps:
Expand All @@ -80,7 +80,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet }}

- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
benchmarks/results/*
utils/clusters/**
# TODO Add amazonlinux
# TODO Add amazonlinux

lint-rust:
timeout-minutes: 10
Expand All @@ -125,3 +125,4 @@ jobs:
- uses: ./.github/workflows/lint-rust
with:
cargo-toml-folder: ./csharp/lib
github-token: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit 37e5b62

Please sign in to comment.