In the world of software development, it's easy to get lost in the daily rhythm of pull requests, bug fixes, and feature releases. We measure our output in commits and lines of code. But a nagging question often lingers in the back of our minds: How does this specific commit actually move the needle for the business?
The gap between engineering execution and high-level company strategy is a well-known challenge. Objectives and Key Results (OKRs) are often tracked in spreadsheets or separate project management tools, requiring manual updates that feel like a chore and quickly become outdated. This disconnect means developers miss out on the crucial context of their work, and leadership loses real-time visibility into progress.
What if we could treat our strategic goals with the same rigor an engineer treats application code? This is the core idea behind Goals as Code.
At Goals.do, we believe that strategic objectives should be defined, versioned, and automated right alongside the code that brings them to life. This article provides a hands-on guide to bridging the gap between your codebase and your company's goals by integrating the Goals.do SDK directly into your CI/CD pipeline.
Before we dive into the code, let's establish why managing goals programmatically is a game-changer:
First, let's define a company objective using the Goals.do SDK. Imagine our goal for Q4 is to launch a major new version of our flagship product. This definition can live in a dedicated strategy/ or okrs/ directory within your repository.
import { Goals } from 'goals.do';
// This script can be run once to set up the objective for the quarter
// Or checked into your repo as the source of truth
async function setupQ4Objective() {
const newObjective = await Goals.create({
title: 'Launch V2 of Flagship Product',
owner: 'product-team@example.com',
timeframe: 'Q4 2024',
keyResults: [
{
id: 'kr_users_10k', // Use a stable ID for easy reference
description: 'Achieve 10,000 active users',
target: 10000,
current: 0
},
{
id: 'kr_features_50', // We will automate this one!
description: 'Ship 50 new features and major fixes for V2',
target: 50,
current: 0
},
{
id: 'kr_rating_48',
description: 'Maintain an app store rating of 4.8+',
target: 4.8,
current: 4.9
}
]
});
console.log(`Objective created with ID: ${newObjective.id}`);
}
setupQ4Objective();
In this example, we've defined our objective and three key results. We've assigned a custom, human-readable ID (kr_features_50) to the Key Result we want to automate. This will make it easy to target in our script.
Now for the magic. We want to increment the "Ship 50 new features..." Key Result every time a relevant commit is merged into our main branch. We'll use GitHub Actions for this example, but the principle applies to any CI/CD system.
Let's establish a convention: any commit message starting with feat(v2): or fix(v2): should count towards this goal.
First, add your GOALS_DO_API_KEY as a repository secret in GitHub under Settings > Secrets and variables > Actions.
Next, create a simple Node.js script that will call the Goals.do API. Save this file as .scripts/update-goal.js.
// .scripts/update-goal.js
import { Goals } from 'goals.do';
// The SDK will automatically pick up the API key from process.env.GOALS_DO_API_KEY
const KEY_RESULT_ID = 'kr_features_50';
async function incrementFeatureCount() {
console.log(`Incrementing Key Result: ${KEY_RESULT_ID}`);
try {
const updatedKr = await Goals.KeyResults.increment({
id: KEY_RESULT_ID,
value: 1 // Increment by 1 for each relevant commit
});
console.log(`Successfully updated KR: "${updatedKr.description}"`);
console.log(`Progress: ${updatedKr.current} / ${updatedKr.target}`);
} catch (error) {
console.error('Failed to update Key Result:', error);
process.exit(1); // Fail the CI job if the update fails
}
}
incrementFeatureCount();
Finally, create the workflow file that triggers this script on every push to the main branch. Save this as .github/workflows/goal-updater.yml.
# .github/workflows/goal-updater.yml
name: Update V2 Launch Goal
on:
push:
branches:
- main
jobs:
update-key-result:
name: Update Feature Shipped KR
runs-on: ubuntu-latest
# This condition is key: only run the job if the commit message matches our pattern
if: |
contains(github.event.head_commit.message, 'feat(v2):') ||
contains(github.event.head_commit.message, 'fix(v2):')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm install goals.do
- name: Update Key Result Progress
run: node .scripts/update-goal.js
env:
GOALS_DO_API_KEY: ${{ secrets.GOALS_DO_API_KEY }}
That's it! Now, every time a developer merges a feature or a major fix for V2 into the main branch with the correct commit message format, the GitHub Action will trigger, run your script, and automatically update your company's strategic goal. The progress is live, accurate, and requires zero manual intervention.
Connecting goals to commits is just the beginning. The power of a developer-first, API-driven goal management platform is its extensibility. Consider these other workflows:
By treating OKRs and goals as a native part of your operational workflows, you create a powerful, real-time feedback loop. Your strategy stops being a static document and becomes a living, breathing part of your development lifecycle.
Ready to stop updating spreadsheets and start shipping code that counts? Explore Goals.do and turn your company's strategy into executable code.