CI/CD Pipeline Integration
Learn how to integrate RefineAI into your Continuous Integration and Continuous Deployment (CI/CD) pipelines to automate code optimization as part of your development workflow.
Overview
RefineAI can be integrated into your CI/CD pipeline to automatically analyze and optimize your code during the build process. This ensures that your code is always optimized before deployment, improving performance and reducing technical debt.
Key Benefits
- Automated code optimization as part of your CI/CD pipeline
- Early detection of performance issues and technical debt
- Consistent code quality across all deployments
- Integration with popular CI/CD platforms like GitHub Actions, Jenkins, GitLab CI, and CircleCI
- Customizable optimization rules and thresholds
Supported CI/CD Platforms
RefineAI provides official integrations for the following CI/CD platforms:
GitHub Actions
Official GitHub Action for seamless integration with GitHub repositories.
GitLab CI
Official GitLab CI template for GitLab repositories and pipelines.
Jenkins
Jenkins plugin and pipeline script for traditional CI/CD setups.
CircleCI
CircleCI orb for easy integration with CircleCI pipelines.
For other CI/CD platforms, you can use our CLI tool or REST API to integrate RefineAI into your pipeline.
Integration Examples
GitHub Actions Example
Add the following workflow file to your repository at .github/workflows/refine-ai.yml:
name: RefineAI Code Optimization
on:
# Run on pull requests
pull_request:
branches: [ main, develop ]
# Run on push to main branch
push:
branches: [ main ]
# Allow manual triggering
workflow_dispatch:
# Run weekly on Sunday
schedule:
- cron: '0 2 * * 0'
jobs:
analyze:
name: Analyze and Optimize Code
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: RefineAI Analyze
uses: refine-ai/github-action@v1
with:
api-key: ${{ secrets.REFINE_AI_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
# Optional: Path to config file
config-file: '.refineai.yml'
# Optional: Analysis depth
depth: 'standard'
# Optional: Create optimization PRs
create-optimization-prs: trueGitLab CI Example
Add the following to your .gitlab-ci.yml file:
include:
- template: RefineAI.gitlab-ci.yml
stages:
- test
- analyze
- build
- deploy
refine-ai-analyze:
stage: analyze
variables:
REFINE_AI_API_KEY: $REFINE_AI_API_KEY
REFINE_AI_CONFIG_FILE: .refineai.yml
REFINE_AI_DEPTH: standard
REFINE_AI_CREATE_MR: "true"
# Only run on merge requests and main branch
only:
- merge_requests
- main
# Don't block the pipeline if analysis fails
allow_failure: trueJenkins Pipeline Example
Add the following to your Jenkinsfile:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('RefineAI Analysis') {
steps {
withCredentials([string(credentialsId: 'refine-ai-api-key', variable: 'REFINE_AI_API_KEY')]) {
sh '''
curl -L https://get.refine-ai.tech/install.sh | bash
refine analyze --api-key $REFINE_AI_API_KEY --config .refineai.yml
'''
}
}
// Don't fail the build if analysis fails
failFast false
}
stage('Deploy') {
steps {
sh 'npm run deploy'
}
}
}
}CircleCI Example
Add the following to your .circleci/config.yml file:
version: 2.1
orbs:
refine-ai: refine-ai/refine-ai@1.0.0
workflows:
version: 2
build-test-analyze:
jobs:
- build
- test:
requires:
- build
- refine-ai/analyze:
api-key: $REFINE_AI_API_KEY
config-file: .refineai.yml
depth: standard
create-optimization-prs: true
requires:
- test
- deploy:
requires:
- refine-ai/analyze
filters:
branches:
only: mainConfiguration Options
RefineAI CI/CD integrations support the following configuration options:
| Option | Description | Default |
|---|---|---|
| api-key | Your RefineAI API key | Required |
| config-file | Path to your RefineAI configuration file | .refineai.yml |
| depth | Analysis depth (basic, standard, deep) | standard |
| create-optimization-prs | Whether to create PRs with optimizations | false |
| fail-on-issues | Whether to fail the build if issues are found | false |
| github-token | GitHub token for PR creation (GitHub Actions only) | ${{ github.token }} |
CI/CD Integration Best Practices
Consider these best practices when integrating RefineAI into your CI/CD pipeline:
- •Store your RefineAI API key as a secret in your CI/CD platform to keep it secure.
- •For large repositories, consider running RefineAI analysis only on changed files to speed up the CI/CD process.
- •Set
fail-on-issuestofalseinitially to avoid blocking your pipeline, then gradually increase strictness as your codebase improves. - •Use the
create-optimization-prsoption to automatically create pull requests with optimizations, but review them carefully before merging.
