diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5b41017 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,124 @@ +name: Release + +on: + push: + tags: ["v*"] + +permissions: + contents: write + +jobs: + build: + strategy: + matrix: + include: + - target: bun-darwin-arm64 + name: ags-darwin-arm64 + os: macos-latest + - target: bun-darwin-x64 + name: ags-darwin-x64 + os: macos-latest + - target: bun-linux-x64 + name: ags-linux-x64 + os: ubuntu-latest + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - run: bun install + + - name: Build binary + run: | + mkdir -p dist + bun build --compile --target=${{ matrix.target }} --outfile=dist/${{ matrix.name }} ./src/index.ts + + - name: Generate checksum + run: | + cd dist + shasum -a 256 ${{ matrix.name }} > ${{ matrix.name }}.sha256 + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.name }} + path: | + dist/${{ matrix.name }} + dist/${{ matrix.name }}.sha256 + + release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + files: | + dist/ags-* + completions/* + + publish-npm: + needs: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - run: bun install + + - name: Publish to npm + run: bunx npm publish --access public + env: + NPM_CONFIG_REGISTRY: https://registry.npmjs.org + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + update-homebrew: + needs: release + runs-on: ubuntu-latest + steps: + - name: Get version + id: version + run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" + + - name: Download checksums + uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + + - name: Read checksums + id: checksums + run: | + echo "darwin_arm64=$(awk '{print $1}' dist/ags-darwin-arm64.sha256)" >> "$GITHUB_OUTPUT" + echo "darwin_x64=$(awk '{print $1}' dist/ags-darwin-x64.sha256)" >> "$GITHUB_OUTPUT" + echo "linux_x64=$(awk '{print $1}' dist/ags-linux-x64.sha256)" >> "$GITHUB_OUTPUT" + + - name: Update Homebrew formula + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} + repository: moqa-studio/homebrew-tap + event-type: update-formula + client-payload: | + { + "version": "${{ steps.version.outputs.version }}", + "darwin_arm64_sha": "${{ steps.checksums.outputs.darwin_arm64 }}", + "darwin_x64_sha": "${{ steps.checksums.outputs.darwin_x64 }}", + "linux_x64_sha": "${{ steps.checksums.outputs.linux_x64 }}" + } diff --git a/homebrew/agents-cli.rb b/homebrew/agents-cli.rb new file mode 100644 index 0000000..69e011f --- /dev/null +++ b/homebrew/agents-cli.rb @@ -0,0 +1,39 @@ +class AgentsCli < Formula + desc "AI agents CLI tool" + homepage "https://github.com/moqa-studio/agents-cli" + license "MIT" + version "0.1.0" + + on_macos do + if Hardware::CPU.arm? + url "https://github.com/moqa-studio/agents-cli/releases/download/v#{version}/ags-darwin-arm64" + sha256 "PLACEHOLDER" + + def install + bin.install "ags-darwin-arm64" => "ags" + end + else + url "https://github.com/moqa-studio/agents-cli/releases/download/v#{version}/ags-darwin-x64" + sha256 "PLACEHOLDER" + + def install + bin.install "ags-darwin-x64" => "ags" + end + end + end + + on_linux do + if Hardware::CPU.intel? + url "https://github.com/moqa-studio/agents-cli/releases/download/v#{version}/ags-linux-x64" + sha256 "PLACEHOLDER" + + def install + bin.install "ags-linux-x64" => "ags" + end + end + end + + test do + assert_match version.to_s, shell_output("#{bin}/ags --version") + end +end diff --git a/homebrew/update-formula.yml b/homebrew/update-formula.yml new file mode 100644 index 0000000..2cb0bf7 --- /dev/null +++ b/homebrew/update-formula.yml @@ -0,0 +1,72 @@ +# This workflow goes in the moqa-studio/homebrew-tap repo at .github/workflows/update-formula.yml +name: Update Formula + +on: + repository_dispatch: + types: [update-formula] + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update agents-cli formula + run: | + VERSION="${{ github.event.client_payload.version }}" + DARWIN_ARM64_SHA="${{ github.event.client_payload.darwin_arm64_sha }}" + DARWIN_X64_SHA="${{ github.event.client_payload.darwin_x64_sha }}" + LINUX_X64_SHA="${{ github.event.client_payload.linux_x64_sha }}" + + cat > Formula/agents-cli.rb << FORMULA + class AgentsCli < Formula + desc "AI agents CLI tool" + homepage "https://github.com/moqa-studio/agents-cli" + license "MIT" + version "${VERSION}" + + on_macos do + if Hardware::CPU.arm? + url "https://github.com/moqa-studio/agents-cli/releases/download/v${VERSION}/ags-darwin-arm64" + sha256 "${DARWIN_ARM64_SHA}" + + def install + bin.install "ags-darwin-arm64" => "ags" + end + else + url "https://github.com/moqa-studio/agents-cli/releases/download/v${VERSION}/ags-darwin-x64" + sha256 "${DARWIN_X64_SHA}" + + def install + bin.install "ags-darwin-x64" => "ags" + end + end + end + + on_linux do + if Hardware::CPU.intel? + url "https://github.com/moqa-studio/agents-cli/releases/download/v${VERSION}/ags-linux-x64" + sha256 "${LINUX_X64_SHA}" + + def install + bin.install "ags-linux-x64" => "ags" + end + end + end + + test do + assert_match version.to_s, shell_output("#{bin}/ags --version") + end + end + FORMULA + + - name: Commit and push + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add Formula/agents-cli.rb + git commit -m "Update agents-cli to ${{ github.event.client_payload.version }}" + git push diff --git a/package.json b/package.json index ad4646c..edfa06e 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,28 @@ { "name": "@moqa/ags", "version": "0.1.0", + "description": "AI agents CLI tool", "type": "module", "bin": { "ags": "./src/index.ts" }, + "files": [ + "src", + "completions" + ], "scripts": { "dev": "bun run src/index.ts", "build": "bun run build.ts", "test": "bun test", - "typecheck": "bun run --bun tsc --noEmit" + "typecheck": "bun run --bun tsc --noEmit", + "release": "bun run scripts/release.ts" }, "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/moqa-studio/agents-cli.git" + }, + "keywords": ["agents", "cli", "ai"], "devDependencies": { "bun-types": "^1.3.11" } diff --git a/scripts/release.ts b/scripts/release.ts new file mode 100644 index 0000000..b264cd7 --- /dev/null +++ b/scripts/release.ts @@ -0,0 +1,40 @@ +import { $ } from "bun"; + +const bump = process.argv[2] as "patch" | "minor" | "major" | undefined; + +if (!bump || !["patch", "minor", "major"].includes(bump)) { + console.error("Usage: bun run release "); + process.exit(1); +} + +// Ensure working tree is clean +const status = await $`git status --porcelain`.text(); +if (status.trim()) { + console.error("Working tree is dirty. Commit or stash changes first."); + process.exit(1); +} + +// Bump version in package.json +const pkg = await Bun.file("package.json").json(); +const [major, minor, patch] = pkg.version.split(".").map(Number); + +const newVersion = + bump === "major" + ? `${major + 1}.0.0` + : bump === "minor" + ? `${major}.${minor + 1}.0` + : `${major}.${minor}.${patch + 1}`; + +pkg.version = newVersion; +await Bun.write("package.json", JSON.stringify(pkg, null, 2) + "\n"); + +console.log(`Bumped version: ${pkg.version.replace(newVersion, "")}${major}.${minor}.${patch} → ${newVersion}`); + +// Commit, tag, push +await $`git add package.json`; +await $`git commit -m "release: v${newVersion}"`; +await $`git tag v${newVersion}`; +await $`git push origin main v${newVersion}`; + +console.log(`\nv${newVersion} released! CI will handle the rest.`); +console.log(`Watch progress: https://github.com/moqa-studio/agents-cli/actions`);