Skip to content

CI CD Integration

Mikhail Deynekin edited this page Dec 23, 2025 · 1 revision

CI/CD Integration Guide

πŸš€ Automate BOM Cleaning in Your Pipeline

Integrate Clean BOM Senior into your CI/CD pipeline to automatically clean BOM artifacts on every commit or deploy.


🚠 GitHub Actions

Basic Workflow

Create .github/workflows/clean-bom.yml:

name: Clean BOM

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

jobs:
  clean-bom:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Download Clean BOM Senior
      run: |
        curl -O https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh
        chmod +x clean-bom-senior.sh
    
    - name: Check for BOM (dry-run)
      run: ./clean-bom-senior.sh --dry-run --verbose .
    
    - name: Fail if BOM found
      run: |
        ./clean-bom-senior.sh --dry-run . > /tmp/bom-check.log 2>&1
        if grep -q "BOM DETECTED" /tmp/bom-check.log; then
          echo "❌ BOM found! Please clean with: ./clean-bom-senior.sh"
          exit 1
        fi

Auto-Fix on Pull Request

name: Auto-Fix BOM

on:
  pull_request:
    branches: [ main ]

jobs:
  fix-bom:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.head_ref }}
    
    - name: Download Clean BOM Senior
      run: |
        curl -O https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh
        chmod +x clean-bom-senior.sh
    
    - name: Clean BOM
      run: ./clean-bom-senior.sh --exclude vendor,node_modules .
    
    - name: Commit changes
      run: |
        git config user.name "BOM Cleaner Bot"
        git config user.email "bot@example.com"
        git add -A
        git diff-index --quiet HEAD || git commit -m "fix: remove BOM artifacts"
        git push

πŸ›³ GitLab CI

Basic Pipeline

Create .gitlab-ci.yml:

stages:
  - check
  - fix

check-bom:
  stage: check
  image: ubuntu:latest
  script:
    - curl -O https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh
    - chmod +x clean-bom-senior.sh
    - ./clean-bom-senior.sh --dry-run --verbose . 2>&1 | tee bom-report.txt
    - 'if grep -q "BOM DETECTED" bom-report.txt; then echo "BOM found"; exit 1; fi'
  artifacts:
    reports:
      dotenv: bom-report.txt
    when: always

fix-bom:
  stage: fix
  image: ubuntu:latest
  script:
    - git config user.name "GitLab BOM Bot"
    - git config user.email "bot@gitlab.com"
    - curl -O https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh
    - chmod +x clean-bom-senior.sh
    - ./clean-bom-senior.sh --exclude vendor,node_modules .
    - git add -A
    - 'git commit -m "fix: remove BOM artifacts" || echo "No changes needed"'
    - git push https://oauth2:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git HEAD:${CI_COMMIT_REF_NAME}
  only:
    - merge_requests

🚠 Jenkins

Declarative Pipeline

In Jenkinsfile:

pipeline {
    agent any
    
    stages {
        stage('Download BOM Cleaner') {
            steps {
                sh '''#!/bin/bash
                    curl -O https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh
                    chmod +x clean-bom-senior.sh
                '''
            }
        }
        
        stage('Check BOM') {
            steps {
                sh '''#!/bin/bash
                    ./clean-bom-senior.sh --dry-run --verbose . > bom-report.txt 2>&1
                    cat bom-report.txt
                    if grep -q "BOM DETECTED" bom-report.txt; then
                        echo "❌ BOM found in files"
                        exit 1
                    fi
                '''
            }
        }
        
        stage('Clean BOM') {
            when {
                expression { currentBuild.previousBuild?.result == 'FAILURE' }
            }
            steps {
                sh '''#!/bin/bash
                    ./clean-bom-senior.sh --backup --verbose .
                '''
            }
        }
    }
    
    post {
        always {
            archiveArtifacts artifacts: 'bom-report.txt', allowEmptyArchive: true
            junit testResults: 'bom-report.txt', allowEmptyResults: true
        }
    }
}

πŸ“€ Docker

Dockerfile

FROM ubuntu:latest

RUN apt-get update && apt-get install -y \
    curl \
    bash \
    && rm -rf /var/lib/apt/lists/*

RUN curl -O https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh && \
    chmod +x clean-bom-senior.sh && \
    mv clean-bom-senior.sh /usr/local/bin/

WORKDIR /workspace

ENTRYPOINT ["clean-bom-senior.sh"]
CMD ["--help"]

Docker Compose

version: '3'
services:
  bom-cleaner:
    build: .
    volumes:
      - ./:/workspace
    command: --dry-run --verbose /workspace

πŸ”¨ Makefile

.PHONY: bom-check bom-clean bom-install

BOM_SCRIPT := clean-bom-senior.sh
BOM_URL := https://raw.githubusercontent.com/paulmann/Clean_BOM_Senior/main/clean-bom-senior.sh

bom-install:
	@curl -O $(BOM_URL)
	@chmod +x $(BOM_SCRIPT)

bom-check: bom-install
	@./$(BOM_SCRIPT) --dry-run --verbose .

bom-clean: bom-install
	@./$(BOM_SCRIPT) --backup --verbose .

bom-fix-crlf: bom-install
	@./$(BOM_SCRIPT) --fix-crlf --verbose .

bom-ci: bom-install
	@./$(BOM_SCRIPT) --dry-run . && echo "βœ“ No BOM found" || echo "βœ— BOM detected"

Usage:

make bom-check      # Check for BOM
make bom-clean      # Clean BOM
make bom-fix-crlf   # Fix both BOM and CRLF
make bom-ci         # CI/CD check

πŸ›° Pre-commit Framework

Create .pre-commit-config.yaml:

repos:
  - repo: https://github.com/paulmann/Clean_BOM_Senior
    rev: main
    hooks:
      - id: clean-bom
        name: Clean BOM
        entry: ./clean-bom-senior.sh
        language: script
        types: [text]
        exclude: ^
        stages: [commit]

Setup:

pip install pre-commit
pre-commit install
pre-commit run --all-files  # Run manually

πŸ›« Webhook Integration

GitHub Push Event

Create AWS Lambda trigger:

import json
import subprocess
import os

def lambda_handler(event, context):
    # Get repository details
    repo = event['repository']['full_name']
    clone_url = event['repository']['clone_url']
    
    # Clone repo
    subprocess.run(['git', 'clone', clone_url, '/tmp/repo'])
    os.chdir('/tmp/repo')
    
    # Run cleaner
    result = subprocess.run([
        './clean-bom-senior.sh',
        '--dry-run',
        '--verbose',
        '.'
    ], capture_output=True, text=True)
    
    return {
        'statusCode': 200,
        'body': json.dumps(result.stdout)
    }

πŸ“‹ Best Practices

1. Gate Checks

Use dry-run in pull request checks:

# Fail PR if BOM found
if ./clean-bom-senior.sh --dry-run .; then
    echo "βœ“ No BOM artifacts"
else
    echo "βœ— BOM detected - please clean"
    exit 1
fi

2. Automatic Fixes

Commit fixes automatically:

./clean-bom-senior.sh --backup .
git add -A
git commit -m "style: remove BOM artifacts" || true
git push

3. Scheduled Checks

Run daily maintenance:

schedule: '0 2 * * *'  # 2 AM daily

4. Exclusions

Always exclude dependencies:

./clean-bom-senior.sh --exclude vendor,node_modules,dist .

5. Reporting

Generate detailed reports:

./clean-bom-senior.sh --report bom-report.json --verbose .

πŸ’‘ Pipeline Strategies

Strategy 1: Check-Only (Strict)

Fail pipeline if BOM found:

./clean-bom-senior.sh --dry-run .

Use: Production branches, code review gates


Strategy 2: Auto-Fix (Lenient)

Automatically clean and commit:

./clean-bom-senior.sh --backup .
git commit -am "fix: remove BOM artifacts"

Use: Feature branches, development pipelines


Strategy 3: Report-Only

Generate report, don't fail:

./clean-bom-senior.sh --report report.txt --verbose .

Use: Logging, auditing, monitoring


Integrate Clean BOM Senior into your CI/CD for automated BOM management.

Clone this wiki locally