Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
77 changes: 77 additions & 0 deletions .github/scripts/logger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# GitHub Actions Logger Script for Public Repositories
# Usage: logger -l <level> -m <message>
# Levels: info, warn, error, debug

# Color codes with bold
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
NC='\033[0m' # No Color

# Default values
LOG_LEVEL=""
MESSAGE=""

# Parse command line arguments
while getopts "l:m:" opt; do
case $opt in
l)
LOG_LEVEL="$OPTARG"
;;
m)
MESSAGE="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

# Validate inputs
if [ -z "$LOG_LEVEL" ]; then
echo "Error: Log level (-l) is required" >&2
echo "Usage: logger -l <level> -m <message>" >&2
echo "Levels: info, warn, error, debug" >&2
exit 1
fi

if [ -z "$MESSAGE" ]; then
echo "Error: Message (-m) is required" >&2
echo "Usage: logger -l <level> -m <message>" >&2
exit 1
fi

# Convert log level to uppercase for display
LOG_LEVEL_UPPER=$(echo "$LOG_LEVEL" | tr '[:lower:]' '[:upper:]')

# Process based on log level
case "$LOG_LEVEL" in
info|INFO)
echo -e "${GREEN}INFO:${NC} $MESSAGE"
;;
warn|WARN)
echo -e "${YELLOW}WARN:${NC} $MESSAGE"
;;
error|ERROR)
echo -e "${RED}ERROR:${NC} $MESSAGE"
exit 1
;;
debug|DEBUG)
# Only print debug messages when GitHub Actions is in debug mode
if [[ "$RUNNER_DEBUG" == "1" || "$ACTIONS_STEP_DEBUG" == "true" || "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
echo -e "${YELLOW}DEBUG:${NC} $MESSAGE"
fi
;;
*)
echo "Error: Invalid log level '$LOG_LEVEL'" >&2
echo "Valid levels: info, warn, error, debug" >&2
exit 1
;;
esac
122 changes: 83 additions & 39 deletions .github/workflows/publish-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ on:
default: false
type: boolean

permissions:
contents: write

jobs:
publish:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Checkout agents-sdk repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}

- name: Setup logger
run: |
sudo cp .github/scripts/logger.sh /usr/local/bin/logger
sudo chmod +x /usr/local/bin/logger

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -31,32 +37,50 @@ jobs:
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile
run: |
logger -l info -m "Installing dependencies"
yarn install --frozen-lockfile \
|| logger -l error -m "Failed to install dependencies"

- name: Build package
run: yarn build
run: |
logger -l info -m "Building package"
yarn build \
|| logger -l error -m "Failed to build package"

- name: Determine version and tag
id: version
run: |
if [ "${{ github.ref_name }}" = "main" ]; then
# For main branch - staging versions with run number
BASE_VERSION=$(jq -r '.version' package.json)
logger -l info -m "Base version: $BASE_VERSION"

if [ "$BASE_VERSION" = "null" ]; then
echo "Error: Could not read version from package.json"
exit 1
logger -l error -m "Could not read version from package.json"
fi

CLEAN_VERSION=$(echo "$BASE_VERSION" | sed 's/-.*$//')
STAGING_VERSION="${CLEAN_VERSION}-staging.${{ github.run_number }}"

logger -l info -m "Clean version: $CLEAN_VERSION"
logger -l info -m "Staging version: $STAGING_VERSION"

echo "version=$STAGING_VERSION" >> $GITHUB_OUTPUT
echo "tag=staging" >> $GITHUB_OUTPUT
echo "description=Staging release from main branch" >> $GITHUB_OUTPUT
echo "should_sync=false" >> $GITHUB_OUTPUT
else
# For prod branch - production versions
logger -l info -m "Determining production version"

# Use npm version command (official npm way to bump versions)
NEW_VERSION=$(npm version patch --no-git-tag-version --silent)
logger -l info -m "New version: $NEW_VERSION"

NEW_VERSION=${NEW_VERSION#v} # Remove 'v' prefix if present
logger -l info -m "New version without 'v' prefix: $NEW_VERSION"

echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_OUTPUT
echo "description=Production release" >> $GITHUB_OUTPUT
Expand All @@ -65,90 +89,103 @@ jobs:

- name: Update package.json version
run: |
logger -l info -m "Updating package.json version"
jq --arg version "${{ steps.version.outputs.version }}" '.version = $version' package.json > package.json.tmp

if ! jq empty package.json.tmp 4>/dev/null; then
echo "Error: Generated invalid JSON"
rm -f package.json.tmp
exit 1
logger -l error -m "Generated invalid JSON"
fi

mv package.json.tmp package.json

echo "Updated package.json version to: $(jq -r '.version' package.json)"
logger -l info -m "Updated package.json version to: ${{ steps.version.outputs.version }}"

- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "🔍 DRY RUN MODE: Would publish version ${{ steps.version.outputs.version }} with tag ${{ steps.version.outputs.tag }}"
echo "📦 Package would be published to: https://www.npmjs.com/package/@d-id/client-sdk/v/${{ steps.version.outputs.version }}"
echo "🏷️ NPM tag would be: ${{ steps.version.outputs.tag }}"
echo "✅ Dry run completed successfully - no actual publishing occurred"
logger -l info -m "🔍 DRY RUN MODE: Would publish version ${{ steps.version.outputs.version }} with tag ${{ steps.version.outputs.tag }}"
logger -l info -m "📦 Package would be published to: https://www.npmjs.com/package/@d-id/client-sdk/v/${{ steps.version.outputs.version }}"
logger -l info -m "🏷️ NPM tag would be: ${{ steps.version.outputs.tag }}"
logger -l info -m "✅ Dry run completed successfully - no actual publishing occurred"
else
echo "🚀 Publishing version ${{ steps.version.outputs.version }} with tag ${{ steps.version.outputs.tag }}"
logger -l info -m "🚀 Publishing version ${{ steps.version.outputs.version }} with tag ${{ steps.version.outputs.tag }}"
npm publish --access public --tag ${{ steps.version.outputs.tag }}
echo "✅ Successfully published to NPM"
logger -l info -m "✅ Successfully published to NPM"
fi

- name: Create Git tag for production
if: github.ref_name == 'prod' && github.event.inputs.dry_run != 'true'
run: |
logger -l info -m "Creating Git tag for production"

logger -l info -m "Configuring Git user"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

logger -l info -m "Creating Git tag"
git tag "v${{ steps.version.outputs.version }}"
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git "v${{ steps.version.outputs.version }}"

logger -l info -m "Pushing Git tag to origin"
git push origin "v${{ steps.version.outputs.version }}"

- name: Commit version bump (prod only)
if: github.ref_name == 'prod' && github.event.inputs.dry_run != 'true'
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
logger -l info -m "Committing version bump"

logger -l info -m "Configuring Git user"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git add package.json
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} [skip ci]" || echo "No changes to commit"
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git prod

logger -l info -m "Committing version bump without triggering the CICD pipeline"
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} [skip ci]" || logger -l info -m "No changes to commit"
git push origin prod

- name: Sync version back to main (prod only)
if: github.ref_name == 'prod' && github.event.inputs.dry_run != 'true'
env:
GH_TOKEN: ${{ secrets.DEVOPS_TOKEN }}
run: |
# Fetch latest main
logger -l info -m "Fetching latest main"
git fetch origin main
git checkout main
git pull origin main

logger -l info -m "Updating package.json version"
jq --arg version "${{ steps.version.outputs.version }}" '.version = $version' package.json > package.json.tmp

if ! jq empty package.json.tmp 4>/dev/null; then
echo "Error: Generated invalid JSON"
rm -f package.json.tmp
exit 1
logger -l error -m "Generated invalid JSON"
fi

mv package.json.tmp package.json

if git diff --quiet package.json; then
echo "No version changes needed"
logger -l info -m "No version changes needed"
else
logger -l info -m "Configuring Git user"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

logger -l info -m "Adding and committing package.json to main branch without triggering the CICD pipeline"
git add package.json
git commit -m "chore: sync version ${{ steps.version.outputs.version }} from prod [skip ci]"

logger -l info -m "Pushing package.json to main branch"
git push origin main
fi

- name: Create GitHub Release (prod only)
if: github.ref_name == 'prod' && github.event.inputs.dry_run != 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
with:
name: Release v${{ steps.version.outputs.version }}
tag_name: v${{ steps.version.outputs.version }}
release_name: Release v${{ steps.version.outputs.version }}
draft: false
prerelease: false
body: |
## Release v${{ steps.version.outputs.version }}

Expand All @@ -160,39 +197,46 @@ jobs:
```

${{ steps.version.outputs.description }}
draft: false
prerelease: false

- name: Checkout agents-ui repository
if: github.ref_name == 'prod' && github.event.inputs.dry_run != 'true'
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
repository: de-id/agents-ui
token: ${{ secrets.DEVOPS_TOKEN }}
path: agents-ui

- name: Update SDK version and create PR
if: github.ref_name == 'prod' && github.event.inputs.dry_run != 'true'
working-directory: agents-ui
env:
GH_TOKEN: ${{ secrets.DEVOPS_TOKEN }}
run: |
cd agents-ui
logger -l info -m "Updating SDK version in agents-ui"

jq --arg version "${{ steps.version.outputs.version }}" '.dependencies."@d-id/client-sdk" = $version' package.json > package.json.tmp
mv package.json.tmp package.json

if git diff --quiet package.json; then
echo "No version changes needed in agents-ui"
logger -l info -m "No version changes needed in agents-ui"
exit 0
fi

logger -l info -m "Creating new branch"
git checkout -b "chore/bump-sdk-version-${{ steps.version.outputs.version }}"

logger -l info -m "Configuring Git user"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

logger -l info -m "Adding and committing package.json"
git add package.json
git commit -m "chore: bump @d-id/client-sdk to v${{ steps.version.outputs.version }}"

logger -l info -m "Publishing branch to origin"
git push origin "chore/bump-sdk-version-${{ steps.version.outputs.version }}"

logger -l info -m "Creating PR on agents-ui repository"
gh pr create \
--repo de-id/agents-ui \
--title "chore: bump @d-id/client-sdk to v${{ steps.version.outputs.version }}" \
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.34",
"version": "1.1.35",
"type": "module",
"description": "d-id client sdk",
"repository": {
Expand Down