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
109 changes: 106 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ permissions:
jobs:
release:
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}

steps:
# Checkout code with full history to get tags
Expand All @@ -27,16 +30,116 @@ jobs:
with:
node-version: '22'

# Install dependencies and build Node.js project
# Install dependencies, test, and build
- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm run test
- run: npm run publint

- run: npm audit signatures

# Release to GitHub and NPM
- name: Release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm run semantic-release
git fetch --tags
TAG=$(git tag --points-at HEAD | grep "^v" | head -1 || true)
echo "new_release_version=${TAG#v}" >> $GITHUB_OUTPUT
echo "new_release_published=$( [ -n "$TAG" ] && echo true || echo false )" >> $GITHUB_OUTPUT

build-binaries:
needs: release
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest

steps:
# Checkout the release tag
- uses: actions/checkout@v4
with:
ref: v${{ needs.release.outputs.new_release_version }}

- uses: actions/setup-node@v4
with:
node-version: '22'

- uses: oven-sh/setup-bun@v2

- run: npm ci

- name: Set version in package.json
run: npm version ${{ needs.release.outputs.new_release_version }} --no-git-tag-version

- name: Build binaries for all platforms
run: npm run build:binary

- name: Verify binaries exist
run: |
cd bin
MISSING=0
for f in tigris-darwin-arm64 tigris-darwin-x64 tigris-linux-x64 tigris-linux-arm64; do
if [ ! -f "$f" ]; then
echo "ERROR: Missing binary: $f"
MISSING=1
fi
done
if [ ! -f "tigris-windows-x64.exe" ]; then
echo "ERROR: Missing binary: tigris-windows-x64.exe"
MISSING=1
fi
if [ "$MISSING" -eq 1 ]; then
echo "Binary build incomplete. Contents:"
ls -la
exit 1
fi
echo "All binaries present:"
ls -la

- name: Package archives
run: |
cd bin
for f in tigris-darwin-arm64 tigris-darwin-x64 tigris-linux-x64 tigris-linux-arm64; do
tar czf "${f}.tar.gz" "$f"
done
zip tigris-windows-x64.zip tigris-windows-x64.exe

- name: Upload to GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run semantic-release
run: |
TAG="v${{ needs.release.outputs.new_release_version }}"

# Verify release exists
if ! gh release view "$TAG" > /dev/null 2>&1; then
echo "ERROR: Release $TAG does not exist"
exit 1
fi

# Upload with retry
for asset in \
bin/tigris-darwin-arm64.tar.gz \
bin/tigris-darwin-x64.tar.gz \
bin/tigris-linux-x64.tar.gz \
bin/tigris-linux-arm64.tar.gz \
bin/tigris-windows-x64.zip \
scripts/install.sh \
scripts/install.ps1
do
echo "Uploading $asset..."
for attempt in 1 2 3; do
if gh release upload "$TAG" "$asset" --clobber; then
echo " Uploaded successfully"
break
fi
if [ "$attempt" -eq 3 ]; then
echo " ERROR: Failed to upload after 3 attempts"
exit 1
fi
echo " Retry $((attempt + 1))..."
sleep 5
done
done

echo "All assets uploaded to $TAG"
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ dist/
.env.local
.env.development.local
.env.test.local
.env.production.local
.env.production.local
bin/

# Auto-generated
src/command-registry.ts
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"publint": "publint",
"updatedocs": "tsx scripts/update-docs.ts",
"postinstall": "node postinstall.cjs",
"generate:registry": "tsx scripts/generate-registry.ts",
"build:binary": "npm run generate:registry && tsx scripts/build-binaries.ts",
"build:binary:current": "bun build src/cli-binary.ts --compile --outfile=bin/tigris",
"prepublishOnly": "npm run build",
"clean": "rm -rf dist",
"semantic-release": "semantic-release",
Expand Down
74 changes: 74 additions & 0 deletions scripts/build-binaries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env tsx

/**
* Build standalone binaries for all supported platforms using `bun build --compile`.
*
* Usage:
* npx tsx scripts/build-binaries.ts # build all targets
* npx tsx scripts/build-binaries.ts linux-x64 # build one target
*/

import { execSync } from 'child_process';
import { mkdirSync } from 'fs';
import { join } from 'path';

const ENTRY = 'src/cli-binary.ts';
const OUT_DIR = join(process.cwd(), 'bin');

const targets: Record<string, { bunTarget: string; outName: string }> = {
'darwin-arm64': {
bunTarget: 'bun-darwin-arm64',
outName: 'tigris-darwin-arm64',
},
'darwin-x64': {
bunTarget: 'bun-darwin-x64',
outName: 'tigris-darwin-x64',
},
'linux-x64': {
bunTarget: 'bun-linux-x64',
outName: 'tigris-linux-x64',
},
'linux-arm64': {
bunTarget: 'bun-linux-arm64',
outName: 'tigris-linux-arm64',
},
'windows-x64': {
bunTarget: 'bun-windows-x64',
outName: 'tigris-windows-x64.exe',
},
};

// Allow filtering to specific targets via CLI args
const requestedTargets = process.argv.slice(2);
const selectedTargets =
requestedTargets.length > 0
? Object.fromEntries(
Object.entries(targets).filter(([key]) =>
requestedTargets.includes(key)
)
)
: targets;

if (Object.keys(selectedTargets).length === 0) {
console.error(
`No matching targets. Available: ${Object.keys(targets).join(', ')}`
);
process.exit(1);
}

mkdirSync(OUT_DIR, { recursive: true });

for (const [name, { bunTarget, outName }] of Object.entries(selectedTargets)) {
const outFile = join(OUT_DIR, outName);
const cmd = `bun build ${ENTRY} --compile --target=${bunTarget} --outfile=${outFile}`;
console.log(`\n[${name}] ${cmd}`);
try {
execSync(cmd, { stdio: 'inherit' });
console.log(`[${name}] ✓ ${outFile}`);
} catch {
console.error(`[${name}] ✗ build failed`);
process.exit(1);
}
}

console.log('\nAll builds complete.');
147 changes: 147 additions & 0 deletions scripts/generate-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env tsx

/**
* Auto-generate command-registry.ts from specs.yaml.
*
* specs.yaml is the single source of truth for command structure.
* This script generates static imports for commands that have implementations.
*
* Run: npm run generate:registry
*/

import { readFileSync, existsSync, writeFileSync } from 'fs';
import { join } from 'path';
import * as YAML from 'yaml';

const ROOT = process.cwd();
const SPECS_PATH = join(ROOT, 'src/specs.yaml');
const OUTPUT_PATH = join(ROOT, 'src/command-registry.ts');

interface CommandSpec {
name: string;
alias?: string;
commands?: CommandSpec[];
default?: string;
}

interface Specs {
commands: CommandSpec[];
}

interface RegistryEntry {
key: string;
importName: string;
importPath: string;
}

/**
* Convert kebab-case to camelCase
*/
function toCamelCase(str: string): string {
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
}

/**
* Find the implementation file for a command path
*/
function findImplementationPath(commandPath: string[]): string | null {
const basePath = join(ROOT, 'src/lib', ...commandPath);

// Check for direct file: src/lib/{path}.ts
const directPath = `${basePath}.ts`;
if (existsSync(directPath)) {
return `./lib/${commandPath.join('/')}.js`;
}

// Check for index file: src/lib/{path}/index.ts
const indexPath = join(basePath, 'index.ts');
if (existsSync(indexPath)) {
return `./lib/${commandPath.join('/')}/index.js`;
}

return null;
}

/**
* Generate import name from command path
* e.g., ["buckets", "list"] -> "bucketsList"
* e.g., ["iam", "policies", "create"] -> "iamPoliciesCreate"
*/
function toImportName(path: string[]): string {
return path
.map((part, index) => {
const camel = toCamelCase(part);
return index === 0
? camel
: camel.charAt(0).toUpperCase() + camel.slice(1);
})
.join('');
}

/**
* Recursively collect all registry entries from the command tree
*/
function collectEntries(
commands: CommandSpec[],
parentPath: string[] = []
): RegistryEntry[] {
const entries: RegistryEntry[] = [];

for (const cmd of commands) {
const currentPath = [...parentPath, cmd.name];

if (cmd.commands && cmd.commands.length > 0) {
// Has sub-commands - recurse into them
entries.push(...collectEntries(cmd.commands, currentPath));
} else {
// Leaf command - check if implementation exists
const implPath = findImplementationPath(currentPath);
if (implPath) {
entries.push({
key: currentPath.join('/'),
importName: toImportName(currentPath),
importPath: implPath,
});
}
}
}

return entries;
}

/**
* Generate the command-registry.ts file content
*/
function generateRegistry(entries: RegistryEntry[]): string {
const imports = entries
.map((e) => `import * as ${e.importName} from '${e.importPath}';`)
.join('\n');

const registryEntries = entries
.map((e) => ` '${e.key}': ${e.importName},`)
.join('\n');

return `// Auto-generated from specs.yaml - DO NOT EDIT
// Run: npm run generate:registry

${imports}

export const commandRegistry: Record<string, Record<string, unknown>> = {
${registryEntries}
};
`;
}

// Main
const specsContent = readFileSync(SPECS_PATH, 'utf8');
const specs: Specs = YAML.parse(specsContent, { schema: 'core' });

const entries = collectEntries(specs.commands);

console.log(`Found ${entries.length} command implementations:`);
entries.forEach((e) => console.log(` ${e.key}`));

const output = generateRegistry(entries);
writeFileSync(OUTPUT_PATH, output);

console.log(`\nGenerated: ${OUTPUT_PATH}`);
Loading