From 3fb4832dd17ae5c9658ff04da507d79b07f96326 Mon Sep 17 00:00:00 2001 From: Jean-Paul Bonnetouche Date: Tue, 2 Feb 2021 15:29:21 +0100 Subject: [PATCH] postgresql: 12.4 Closes #1. Signed-off-by: Jean-Paul Bonnetouche <16782+goodtouch@users.noreply.github.com> --- .github/workflows/tests.yml | 4 +- Formula/postgresql@12.4.rb | 132 ++++++++++++++++++++++++++++++++++++ README.md | 45 ++++++++++-- 3 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 Formula/postgresql@12.4.rb diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2e59fd9..b09c37e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: test-bot: strategy: matrix: - os: [ubuntu-latest, macOS-latest] + os: [macOS-latest] runs-on: ${{ matrix.os }} steps: - name: Set up Homebrew @@ -40,4 +40,4 @@ jobs: uses: actions/upload-artifact@main with: name: bottles - path: '*.bottle.*' + path: "*.bottle.*" diff --git a/Formula/postgresql@12.4.rb b/Formula/postgresql@12.4.rb new file mode 100644 index 0000000..ee7d216 --- /dev/null +++ b/Formula/postgresql@12.4.rb @@ -0,0 +1,132 @@ +class PostgresqlAT124 < Formula + desc "Object-relational database system" + homepage "https://www.postgresql.org/" + url "https://ftp.postgresql.org/pub/source/v12.4/postgresql-12.4.tar.bz2" + sha256 "bee93fbe2c32f59419cb162bcc0145c58da9a8644ee154a30b9a5ce47de606cc" + license "PostgreSQL" + head "https://github.com/postgres/postgres.git" + + livecheck do + url "https://www.postgresql.org/docs/current/static/release.html" + regex(/Release v?(\d+(?:\.\d+)+)/i) + end + + depends_on "pkg-config" => :build + depends_on "icu4c" + + # GSSAPI provided by Kerberos.framework crashes when forked. + # See https://github.com/Homebrew/homebrew-core/issues/47494. + depends_on "krb5" + + depends_on "openssl@1.1" + depends_on "readline" + + uses_from_macos "libxml2" + uses_from_macos "libxslt" + uses_from_macos "perl" + + on_linux do + depends_on "util-linux" + end + + def install + ENV.prepend "LDFLAGS", "-L#{Formula["openssl@1.1"].opt_lib} -L#{Formula["readline"].opt_lib}" + ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@1.1"].opt_include} -I#{Formula["readline"].opt_include}" + + args = %W[ + --disable-debug + --prefix=#{prefix} + --datadir=#{HOMEBREW_PREFIX}/share/postgresql + --libdir=#{HOMEBREW_PREFIX}/lib + --includedir=#{HOMEBREW_PREFIX}/include + --sysconfdir=#{etc} + --docdir=#{doc} + --enable-thread-safety + --with-bonjour + --with-gssapi + --with-icu + --with-ldap + --with-libxml + --with-libxslt + --with-openssl + --with-pam + --with-perl + --with-tcl + --with-uuid=e2fs + ] + + # PostgreSQL by default uses xcodebuild internally to determine this, + # which does not work on CLT-only installs. + args << "PG_SYSROOT=#{MacOS.sdk_path}" if MacOS.sdk_root_needed? + + system "./configure", *args + system "make" + system "make", "install-world", "datadir=#{pkgshare}", + "libdir=#{lib}", + "pkglibdir=#{lib}/postgresql", + "includedir=#{include}", + "pkgincludedir=#{include}/postgresql", + "includedir_server=#{include}/postgresql/server", + "includedir_internal=#{include}/postgresql/internal" + end + + def post_install + return if ENV["CI"] + + (var/"log").mkpath + (var/"postgres").mkpath + unless File.exist? "#{var}/postgres/PG_VERSION" + system "#{bin}/initdb", "--locale=C", "-E", "UTF-8", "#{var}/postgres" + end + end + + def caveats + <<~EOS + To migrate existing data from a previous major version of PostgreSQL run: + brew postgresql-upgrade-database + + This formula has created a default database cluster with: + initdb --locale=C -E UTF-8 #{var}/postgres + For more details, read: + https://www.postgresql.org/docs/#{version.major}/app-initdb.html + EOS + end + + plist_options manual: "pg_ctl -D #{HOMEBREW_PREFIX}/var/postgres start" + + def plist + <<~EOS + + + + + KeepAlive + + Label + #{plist_name} + ProgramArguments + + #{opt_bin}/postgres + -D + #{var}/postgres + + RunAtLoad + + WorkingDirectory + #{HOMEBREW_PREFIX} + StandardOutPath + #{var}/log/postgres.log + StandardErrorPath + #{var}/log/postgres.log + + + EOS + end + + test do + system "#{bin}/initdb", testpath/"test" unless ENV["CI"] + assert_equal "#{HOMEBREW_PREFIX}/share/postgresql", shell_output("#{bin}/pg_config --sharedir").chomp + assert_equal "#{HOMEBREW_PREFIX}/lib", shell_output("#{bin}/pg_config --libdir").chomp + assert_equal "#{HOMEBREW_PREFIX}/lib/postgresql", shell_output("#{bin}/pg_config --pkglibdir").chomp + end +end diff --git a/README.md b/README.md index 00deea3..bcc1b7d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,46 @@ # Klaxit Postgresql +Tap with fixed minor versions of PostgreSQL from Homebrew. + ## How do I install these formulae? -`brew install klaxit/postgresql/` -Or `brew tap klaxit/postgresql` and then `brew install `. +```sh +brew install klaxit/postgresql/postgresql@12.4 +``` + +Or + +```sh +brew tap klaxit/postgresql +brew install postgresql@12.4 +``` + +## How to relese a new version? + +### Extract selected version + +```sh +brew extract --force --version=12.4 postgresql klaxit/postgresql +``` + +## Create a PR with new version + +```sh +git checkout -b postgres-12.4 +git add Formula/postgresql@12.4.rb +git commit --message "postgresql: 12.4" +git push --set-upstream origin postgres-12.4 +``` + +Create a PR then when checks are green, label your PR with the `pr-pull` label. + +After a couple of minutes you should observe the PR closed, bottles uploaded and commits pushed to the main branch of your repository. + +## How was the initial repo created? -## Documentation -`brew help`, `man brew` or check [Homebrew's documentation](https://docs.brew.sh). +```sh +brew tap-new klaxit/postgresql; +cd $(brew --repository klaxit/postgresql) +git remote add origin git@github.com:klaxit/homebrew-postgresql.git +git push --set-upstream origin main +```