Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fb78331
Test commit for PR
Dec 2, 2025
5543722
Second commit to trigger sync event
Dec 2, 2025
729f575
Use official Buildkite trigger-pipeline-action
Dec 2, 2025
5ae2220
Test tracing behavior
Dec 3, 2025
6596b63
Trigger build for tracing test
Dec 3, 2025
ce7f3aa
Test OTEL tracing with notification service enabled
Dec 3, 2025
e043851
Test with tracing disabled via env var
Dec 3, 2025
07efc6b
Test with unreachable OTEL endpoint
Dec 3, 2025
7839a64
Test with BUILDKITE_TRACING_BACKEND='' (should have no timeout)
Dec 3, 2025
d5239f1
Add k8s test pipeline for mount-buildkite-agent and propagate-environ…
Dec 3, 2025
910dfe8
Fix k8s pipeline - remove command override from podSpec
Dec 3, 2025
8985a6a
Add environment hook test for propagate-environment
Dec 3, 2025
4d32397
Test BUILDKITE_ENV_FILE propagation
Dec 3, 2025
9fc09d6
Test controller-level hooks propagation
Dec 3, 2025
304bce0
Trigger rebuild - test controller pod-spec-patch env vars
Dec 3, 2025
1883270
Test cache plugin between steps
Dec 4, 2025
20db373
Use artifacts instead of cache plugin for cross-step sharing
Dec 4, 2025
a988354
Test cache plugin on mac agent
Dec 4, 2025
d956ebc
Add requirements.txt to repo for cache manifest
Dec 4, 2025
6cd4b68
Use correct S3 bucket for cache
Dec 4, 2025
b8f0e6f
Test both artifacts and cache plugin with UV
Dec 4, 2025
36c1115
Use pip instead of uv (not installed)
Dec 4, 2025
13f3a29
Test both approaches with UV
Dec 4, 2025
0294c2b
test: use pipeline_uuid in workflow
Dec 5, 2025
5cd6e3c
test: use pipeline_uuid in workflow
Dec 5, 2025
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
Binary file added .buildkite/.DS_Store
Binary file not shown.
125 changes: 125 additions & 0 deletions .buildkite/docs/knapsack-token-issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Knapsack Pro: Why Same Token + Same Parallelism Breaks Test Filtering

## The Issue

When running separate test suites (e.g., unit tests and feature tests) with:
- **Same** `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC`
- **Same** `parallelism` value
- Same branch and commit

Knapsack Pro treats all parallel jobs as **one unified test suite** and creates a shared queue.

## How Knapsack Pro Queue/Split Works

Knapsack Pro uses a cache key to identify unique test suite runs:

```
cache_key = (branch, commit_hash, node_total, api_token)
```

When this cache key is identical across different steps, Knapsack Pro assumes they are part of the **same test run** and distributes tests from a shared pool.

## The Timeline of the Customer's Issue

### Before Sep 26th (Working)
```yaml
# Unit tests
parallelism: 8 # Different!
token: SAME_TOKEN

# Feature tests
parallelism: 6 # Different!
token: SAME_TOKEN
```

Cache keys were **different** because `node_total` differed:
- Unit: `(main, abc123, 8, token123)`
- Feature: `(main, abc123, 6, token123)`

### After Sep 26th (Broken)
```yaml
# Unit tests
parallelism: 10 # Same!
token: SAME_TOKEN

# Feature tests
parallelism: 10 # Same!
token: SAME_TOKEN
```

Cache keys became **identical**:
- Unit: `(main, abc123, 10, token123)`
- Feature: `(main, abc123, 10, token123)`

Both steps now share the same queue, and `KNAPSACK_PRO_TEST_FILE_PATTERN` is ignored at the API level.

## The Fix

**Use separate API tokens for each test suite:**

```yaml
steps:
- label: "Unit Tests"
parallelism: 10
env:
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${KNAPSACK_PRO_TOKEN_UNIT}
KNAPSACK_PRO_TEST_FILE_PATTERN: "spec/**/*_spec.rb"
KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN: "spec/features/**/*_spec.rb"
plugins:
- docker-compose#v5.x.x:
run: app
command: bundle exec rake knapsack_pro:queue:rspec
env:
- BUILDKITE_PARALLEL_JOB_COUNT
- BUILDKITE_PARALLEL_JOB
- KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC
- KNAPSACK_PRO_TEST_FILE_PATTERN
- KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN

- label: "Feature Tests"
parallelism: 10
env:
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${KNAPSACK_PRO_TOKEN_FEATURE}
KNAPSACK_PRO_TEST_FILE_PATTERN: "spec/features/**/*_spec.rb"
plugins:
- docker-compose#v5.x.x:
run: app
command: bundle exec rake knapsack_pro:queue:rspec
env:
- BUILDKITE_PARALLEL_JOB_COUNT
- BUILDKITE_PARALLEL_JOB
- KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC
- KNAPSACK_PRO_TEST_FILE_PATTERN
```

## How to Generate Additional Tokens

1. Go to [Knapsack Pro Dashboard](https://knapsackpro.com/dashboard)
2. Navigate to your organization → project
3. Create a new test suite for "Feature Tests"
4. Copy the new API token
5. Add it to Buildkite as a secret environment variable

## Key Documentation

From [Knapsack Pro Reference](https://docs.knapsackpro.com/ruby/reference/):

> **`KNAPSACK_PRO_TEST_SUITE_TOKEN_*`**
>
> API token required to run Knapsack Pro.
> **Each Knapsack Pro command defined on CI should use an individual API token.**

## Additional Considerations

When using the `docker-compose` plugin, ensure these env vars are passed to the container:

```yaml
env:
- BUILDKITE_PARALLEL_JOB_COUNT
- BUILDKITE_PARALLEL_JOB
- BUILDKITE_BUILD_NUMBER
- BUILDKITE_COMMIT
- BUILDKITE_BRANCH
```

Without these, Knapsack Pro inside the container won't know which parallel job it is.
4 changes: 4 additions & 0 deletions .buildkite/hooks/environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export HOOK_VAR="set-in-environment-hook"
export HOOK_SECRET="secret-from-hook"
111 changes: 111 additions & 0 deletions .buildkite/knapsack-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Demo pipeline to illustrate Knapsack Pro token behavior
# This simulates what happens when two test steps share the same API token
# with the same parallelism value

env:
# Simulating a shared Knapsack Pro token (the problematic scenario)
SHARED_TOKEN: "same-token-for-both"

steps:
- group: ":warning: PROBLEMATIC: Same token + Same parallelism"
steps:
- label: ":test_tube: Unit Tests (parallelism=2)"
parallelism: 2
command: |
echo "=== Unit Tests Step ==="
echo "BUILDKITE_PARALLEL_JOB_COUNT: $BUILDKITE_PARALLEL_JOB_COUNT"
echo "BUILDKITE_PARALLEL_JOB: $BUILDKITE_PARALLEL_JOB"
echo "KNAPSACK Token: $SHARED_TOKEN"
echo ""
echo "Knapsack Pro cache key would be:"
echo " (branch=$BUILDKITE_BRANCH, commit=$BUILDKITE_COMMIT, nodes=$BUILDKITE_PARALLEL_JOB_COUNT)"
echo ""
echo "⚠️ With SAME token and SAME parallelism, both steps"
echo " would share the SAME queue in Knapsack Pro API!"
env:
TEST_FILE_PATTERN: "spec/models/**/*_spec.rb"
agents:
queue: mac

- label: ":sparkles: Feature Tests (parallelism=2)"
parallelism: 2
command: |
echo "=== Feature Tests Step ==="
echo "BUILDKITE_PARALLEL_JOB_COUNT: $BUILDKITE_PARALLEL_JOB_COUNT"
echo "BUILDKITE_PARALLEL_JOB: $BUILDKITE_PARALLEL_JOB"
echo "KNAPSACK Token: $SHARED_TOKEN"
echo ""
echo "Knapsack Pro cache key would be:"
echo " (branch=$BUILDKITE_BRANCH, commit=$BUILDKITE_COMMIT, nodes=$BUILDKITE_PARALLEL_JOB_COUNT)"
echo ""
echo "❌ This step might receive unit test files because"
echo " it shares the same queue with Unit Tests step!"
env:
TEST_FILE_PATTERN: "spec/features/**/*_spec.rb"
agents:
queue: mac

- wait

- group: ":white_check_mark: CORRECT: Separate tokens"
steps:
- label: ":test_tube: Unit Tests (separate token)"
parallelism: 2
command: |
echo "=== Unit Tests Step ==="
echo "BUILDKITE_PARALLEL_JOB_COUNT: $BUILDKITE_PARALLEL_JOB_COUNT"
echo "BUILDKITE_PARALLEL_JOB: $BUILDKITE_PARALLEL_JOB"
echo "KNAPSACK Token: $UNIT_TEST_TOKEN"
echo ""
echo "✅ With SEPARATE token, this step has its OWN queue"
echo " and will only receive unit test files."
env:
UNIT_TEST_TOKEN: "token-for-unit-tests"
TEST_FILE_PATTERN: "spec/models/**/*_spec.rb"
agents:
queue: mac

- label: ":sparkles: Feature Tests (separate token)"
parallelism: 2
command: |
echo "=== Feature Tests Step ==="
echo "BUILDKITE_PARALLEL_JOB_COUNT: $BUILDKITE_PARALLEL_JOB_COUNT"
echo "BUILDKITE_PARALLEL_JOB: $BUILDKITE_PARALLEL_JOB"
echo "KNAPSACK Token: $FEATURE_TEST_TOKEN"
echo ""
echo "✅ With SEPARATE token, this step has its OWN queue"
echo " and will only receive feature test files."
env:
FEATURE_TEST_TOKEN: "token-for-feature-tests"
TEST_FILE_PATTERN: "spec/features/**/*_spec.rb"
agents:
queue: mac

- wait

- label: ":memo: Summary"
command: |
echo "=============================================="
echo "KNAPSACK PRO TOKEN BEHAVIOR SUMMARY"
echo "=============================================="
echo ""
echo "THE PROBLEM:"
echo "When two steps have:"
echo " - Same API token"
echo " - Same parallelism value"
echo " - Same branch/commit"
echo ""
echo "Knapsack Pro sees them as ONE test suite and creates"
echo "a shared queue. Both steps pull from the same pool of"
echo "tests, ignoring TEST_FILE_PATTERN filtering."
echo ""
echo "THE FIX:"
echo "Use SEPARATE API tokens for each test suite:"
echo " - KNAPSACK_PRO_TEST_SUITE_TOKEN_UNIT for unit tests"
echo " - KNAPSACK_PRO_TEST_SUITE_TOKEN_FEATURE for feature tests"
echo ""
echo "Generate additional tokens at:"
echo "https://knapsackpro.com/dashboard"
echo "=============================================="
agents:
queue: mac
72 changes: 57 additions & 15 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
env:
BUILDKITE_PLUGIN_S3_CACHE_BUCKET: "ola-buildkite-cache"

steps:
- label: "Job with dynamic priorityy"
# ===== ARTIFACTS APPROACH =====
- label: ":package: Artifacts - Install (UV)"
agents:
queue: mac
command: |
if [ "$BUILDKITE_RETRY_COUNT" -eq 0 ]; then
PRIORITY=1
else
PRIORITY=0
fi

buildkite-agent pipeline upload <<YAML
steps:
- label: "Actual work (priority \$PRIORITY)"
command: "echo 'Running tests'; exit 1"
priority: \$PRIORITY
retry:
automatic: true
YAML
uv venv .venv
source .venv/bin/activate
uv pip install -r requirements.txt
tar -czf venv.tar.gz .venv
buildkite-agent artifact upload venv.tar.gz

- wait

- label: ":white_check_mark: Artifacts - Use deps"
agents:
queue: mac
command: |
buildkite-agent artifact download venv.tar.gz .
tar -xzf venv.tar.gz
source .venv/bin/activate
pip list

- wait

# ===== CACHE PLUGIN APPROACH =====
- label: ":floppy_disk: Cache - Install (UV)"
agents:
queue: mac
plugins:
- cache#v1.8.1:
backend: s3
path: .venv-cached
manifest: requirements.txt
save: file
compression: tgz
command: |
uv venv .venv-cached
source .venv-cached/bin/activate
uv pip install -r requirements.txt

- wait

- label: ":white_check_mark: Cache - Use deps"
agents:
queue: mac
plugins:
- cache#v1.8.1:
backend: s3
path: .venv-cached
manifest: requirements.txt
restore: file
compression: tgz
command: |
source .venv-cached/bin/activate
pip list
24 changes: 10 additions & 14 deletions .github/workflows/trigger-buildkite-on-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ name: Trigger Buildkite on PR Sync
on:
pull_request:
types: [synchronize]
workflow_dispatch:

jobs:
trigger-buildkite:
runs-on: ubuntu-latest
steps:
- name: Trigger Buildkite Build
env:
BUILDKITE_API_TOKEN: ${{ secrets.BUILDKITE_API_TOKEN }}
run: |
curl -X POST "https://api.buildkite.com/v2/organizations/${{ vars.BUILDKITE_ORG_SLUG }}/pipelines/${{ vars.BUILDKITE_PIPELINE_SLUG }}/builds" \
-H "Authorization: Bearer $BUILDKITE_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"commit": "${{ github.event.pull_request.head.sha }}",
"branch": "${{ github.event.pull_request.head.ref }}",
"message": "PR #${{ github.event.pull_request.number }} sync - triggered from GitHub Actions",
"pull_request_id": "${{ github.event.pull_request.number }}",
"pull_request_base_branch": "${{ github.event.pull_request.base.ref }}"
}'
- name: Trigger Buildkite Build (using pipeline_uuid)
uses: buildkite/trigger-pipeline-action@pipeline-uuid-support
with:
buildkite_api_access_token: ${{ secrets.BUILDKITE_API_TOKEN }}
pipeline_uuid: ${{ vars.BUILDKITE_PIPELINE_UUID }}
branch: ${{ github.head_ref || github.ref_name }}
commit: ${{ github.event.pull_request.head.sha || github.sha }}
message: ":github: Triggered via pipeline_uuid"
send_pull_request: true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ This project demonstrates a simple CI/CD pipeline with build and verification sc
The build process creates:
- `build/build-info.txt` - Build metadata
- `build/manifest.json` - Build manifest with status and version info
# Test
# Another test line
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0