Skip to content

Release Production (SDK) #8

Release Production (SDK)

Release Production (SDK) #8

Workflow file for this run

name: Release Production (SDK)
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
id-token: write
jobs:
# First job: Prepare production release
release-sdk:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/setup-project
- name: Calculate and update production version
id: bump_version
run: |
cd sdk
# Get current version and bump it
CURRENT_VERSION=$(bun -e "console.log(require('./package.json').version)")
echo "Current version: $CURRENT_VERSION"
# Bump version using Node.js semver since npm doesn't work with workspace: protocol
NEW_VERSION=$(node -e "
const fs = require('fs');
const semver = require('semver');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const newVersion = semver.inc(pkg.version, '${{ inputs.version_type }}');
pkg.version = newVersion;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\\n');
console.log(newVersion);
")
echo "New production version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-project
- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and push version bump
run: |
git stash
git pull --rebase origin main
git stash pop
git add sdk/package.json
git commit -m "Bump SDK version to ${{ steps.bump_version.outputs.new_version }}"
- name: Set environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
ENV_OVERRIDES: '{"NEXT_PUBLIC_CODEBUFF_BACKEND_URL": "manicode-backend.onrender.com", "NEXT_PUBLIC_CB_ENVIRONMENT": "prod"}'
shell: bash
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts --scope client)
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
# Set default environment variables
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
# Apply environment variable overrides
if [ "$ENV_OVERRIDES" != "{}" ]; then
echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV
fi
- name: Build SDK
run: |
cd sdk
bun run build:verify
- name: Set up Node.js for npm publishing
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Publish to npm
run: |
cd sdk
bun run publish-sdk
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Push to git
run: |
git push