diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4d95ee2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + +jobs: + install: + strategy: + fail-fast: false + matrix: + os: [macos-latest, macos-15-intel, ubuntu-latest, ubuntu-24.04-arm] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + # A PR tests itself; a push or the updater tests main as it now is. + ref: ${{ github.event.pull_request.head.sha || 'main' }} + + - name: Set up Homebrew + uses: Homebrew/actions/setup-homebrew@main + + - name: Install from this tap and test + run: | + brew tap-new --no-git local/test >/dev/null + cp Formula/dbdiff.rb "$(brew --repository local/test)/Formula/" + brew install local/test/dbdiff + brew test local/test/dbdiff + dbdiff --version diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..bb2a082 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,62 @@ +name: Update formula + +# Follows DBDiff's releases: daily, or on demand for a given version. Until a +# stable release exists the newest pre-release is used; after that, only +# stable releases — the same rule as npm's `latest` tag for @dbdiff/cli. +on: + schedule: + - cron: '0 5 * * *' + workflow_dispatch: + inputs: + version: + description: 'DBDiff version, no "v" (empty: the newest as above)' + required: false + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + outputs: + changed: ${{ steps.commit.outputs.changed }} + steps: + - uses: actions/checkout@v4 + + - name: Pick the version + id: pick + env: + GH_TOKEN: ${{ github.token }} + WANTED: ${{ inputs.version }} + run: | + if [ -n "$WANTED" ]; then + version="$WANTED" + else + releases="$(gh api repos/DBDiff/DBDiff/releases --jq '[.[] | select(.draft | not)]')" + version="$(jq -r '[.[] | select(.prerelease | not)][0].tag_name // empty' <<< "$releases")" + [ -n "$version" ] || version="$(jq -r '.[0].tag_name' <<< "$releases")" + version="${version#v}" + fi + current="$(sed -n 's/^ version "\(.*\)"$/\1/p' Formula/dbdiff.rb)" + echo "current $current, wanted $version" + echo "version=$version" >> "$GITHUB_OUTPUT" + [ "$version" != "$current" ] && echo "update=true" >> "$GITHUB_OUTPUT" || true + + - name: Rewrite the formula + if: steps.pick.outputs.update == 'true' + run: scripts/update-formula.sh "${{ steps.pick.outputs.version }}" + + - name: Commit + id: commit + if: steps.pick.outputs.update == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -am "dbdiff ${{ steps.pick.outputs.version }}" + git push + echo "changed=true" >> "$GITHUB_OUTPUT" + + test: + needs: update + if: needs.update.outputs.changed == 'true' + uses: ./.github/workflows/test.yml diff --git a/Formula/dbdiff.rb b/Formula/dbdiff.rb index 2eeeb26..29e3bd7 100644 --- a/Formula/dbdiff.rb +++ b/Formula/dbdiff.rb @@ -1,56 +1,38 @@ +# Written by scripts/update-formula.sh — edit that, not this. class Dbdiff < Formula - desc "Compare MySQL, Postgres or SQLite databases & generate schema/data migrations" + desc "Diff MySQL, PostgreSQL and SQLite databases and generate migrations" homepage "https://github.com/DBDiff/DBDiff" + version "3.0.0-rc.27" license "MIT" - version "2.0.0" - # ── Platform-specific binary downloads ────────────────────────────────────── - # ── Platform-specific binary downloads ────────────────────────────────────── - # - # SHA256 values are stamped by scripts/update-homebrew-formula.sh after each - # GitHub release is published. Run: - # - # scripts/update-homebrew-formula.sh 2.0.1 ../homebrew-dbdiff - # + # A self-contained static binary per platform: PHP and DBDiff in one file. on_macos do on_arm do url "https://github.com/DBDiff/DBDiff/releases/download/v#{version}/dbdiff-darwin-arm64" - sha256 "PLACEHOLDER_darwin_arm64" # bumped by update-homebrew-formula.sh + sha256 "f62cb84c35787526e2f596abb3aa1a98f10e67b984b99316221bac08f5b575e3" end on_intel do url "https://github.com/DBDiff/DBDiff/releases/download/v#{version}/dbdiff-darwin-x64" - sha256 "PLACEHOLDER_darwin_x64" # bumped by update-homebrew-formula.sh + sha256 "759f1661e1acb16f8c2369ae2dfa96dc3dd73afee5c41ce55352ce57ec192565" end end on_linux do on_arm do url "https://github.com/DBDiff/DBDiff/releases/download/v#{version}/dbdiff-linux-arm64" - sha256 "PLACEHOLDER_linux_arm64" # bumped by update-homebrew-formula.sh + sha256 "dc562dc2cc6bf9c8f8d616f974d4f19d947e5c393354cfd9869b8415aab31ae9" end on_intel do url "https://github.com/DBDiff/DBDiff/releases/download/v#{version}/dbdiff-linux-x64" - sha256 "PLACEHOLDER_linux_x64" # bumped by update-homebrew-formula.sh + sha256 "85444249d9db0d029bfeafae7379cca98e435d9f9306c2b16e355be80cfea492" end end - # No compilation — the binary is a fully self-contained static executable - # (static PHP micro SAPI + DBDiff PHAR combined into a single file) - bottle :unneeded - def install - # Determine the asset filename downloaded by Homebrew for this platform - asset = if OS.mac? - Hardware::CPU.arm? ? "dbdiff-darwin-arm64" : "dbdiff-darwin-x64" - else - Hardware::CPU.arm? ? "dbdiff-linux-arm64" : "dbdiff-linux-x64" - end - - bin.install asset => "dbdiff" + bin.install Dir["dbdiff-*"].first => "dbdiff" end test do - output = shell_output("#{bin}/dbdiff --version") - assert_match "DBDiff #{version}", output + assert_match "DBDiff #{version}", shell_output("#{bin}/dbdiff --version") end end diff --git a/README.md b/README.md index 17582c7..63a8454 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,44 @@ # homebrew-dbdiff -[Homebrew](https://brew.sh) tap for [DBDiff](https://github.com/DBDiff/DBDiff) — the database diff and migration tool for MySQL, Postgres, and SQLite. +[Homebrew](https://brew.sh) tap for [DBDiff](https://github.com/DBDiff/DBDiff): +diff MySQL, PostgreSQL and SQLite databases and generate migrations. It +installs DBDiff's self-contained binary — no PHP needed — on macOS and Linux, +Apple Silicon, Intel and ARM. ## Install ```bash -brew tap DBDiff/dbdiff -brew install dbdiff +brew install dbdiff/dbdiff/dbdiff ``` +or `brew tap dbdiff/dbdiff` then `brew install dbdiff`. + ## Usage ```bash -# Diff two MySQL schemas -dbdiff user:pass@host:3306 db1:db2 - -# Diff two Postgres schemas (full DSN) -dbdiff --server1-url postgres://user:pass@host:5432/db1 \ - --server2-url postgres://user:pass@host:5432/db2 +# Schema and data, Postgres to Postgres, from connection strings +dbdiff diff --server1-url postgres://user:pass@host:5432/staging \ + --server2-url postgres://user:pass@host:5432/production \ + --type=all --include=both --output=migration.sql -# Supabase shorthand -dbdiff --supabase --server1=user:pass@db.abc.supabase.co:5432 db1:db2 +# MySQL, two databases on one server +dbdiff diff --server1=user:pass@localhost:3306 --type=schema app_dev:app_prod -# Generate a migration file in a specific format -dbdiff --format=laravel user:pass@host:3306 db1:db2 +# SQLite files +dbdiff diff --server1-url sqlite:///path/to/a.db --server2-url sqlite:///path/to/b.db ``` +`dbdiff diff --help` lists every option. See the +[DBDiff README](https://github.com/DBDiff/DBDiff#readme) for the rest. + ## Upgrade ```bash -brew upgrade dbdiff +brew update && brew upgrade dbdiff ``` -## Uninstall - -```bash -brew uninstall dbdiff -brew untap DBDiff/dbdiff -``` +The formula follows DBDiff's releases automatically. -## More information +## License -- **GitHub:** https://github.com/DBDiff/DBDiff -- **npm:** `npm install -g @dbdiff/cli` -- **Issues:** https://github.com/DBDiff/DBDiff/issues +MIT diff --git a/package.json b/package.json deleted file mode 100644 index 415581d..0000000 --- a/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "homebrew-dbdiff", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "description": "" -} diff --git a/scripts/update-formula.sh b/scripts/update-formula.sh new file mode 100755 index 0000000..670f572 --- /dev/null +++ b/scripts/update-formula.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Rewrite Formula/dbdiff.rb for a DBDiff release: its version and the SHA-256 +# of each platform binary, read from the release's assets. +# +# scripts/update-formula.sh 3.0.0-rc.27 +set -euo pipefail + +version="${1:?usage: $0 e.g. 3.0.0-rc.27}" +base="https://github.com/DBDiff/DBDiff/releases/download/v${version}" +cd "$(dirname "$0")/.." + +sha() { + local sum + sum="$(curl -fsSL "$base/$1" | sha256sum | cut -d' ' -f1)" + [ ${#sum} -eq 64 ] || { echo "could not download $base/$1" >&2; exit 1; } + echo "$sum" +} + +darwin_arm64="$(sha dbdiff-darwin-arm64)" +darwin_x64="$(sha dbdiff-darwin-x64)" +linux_arm64="$(sha dbdiff-linux-arm64)" +linux_x64="$(sha dbdiff-linux-x64)" + +cat > Formula/dbdiff.rb < "dbdiff" + end + + test do + assert_match "DBDiff #{version}", shell_output("#{bin}/dbdiff --version") + end +end +RUBY +echo "Formula/dbdiff.rb → ${version}"