Skip to content
Open
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
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 1.2.0 (2026-11-30)
## 1.2.0 (2026-12-04)

### Features

Expand All @@ -25,7 +25,22 @@
- `rake release` runs `lint`, `test`, `itest` and `oobt` before tagging,
and refuses to start unless it runs from `master` with `SERPAPI_KEY` set
and an empty `git status --porcelain` (the previous `git diff --quiet`
missed staged and untracked files)
missed staged and untracked files). HEAD must also equal `origin/master`
after a fetch, so a stale checkout can't tag an older commit, and only the
new tag is pushed
- `rake release:docs`, run by `rake release`, checks that `CHANGELOG.md` and
the README's Changelog section announce the version from `build.zig.zon`,
dated today, and that the README install commands pin it
- `rake oobt:package` runs the out-of-box demo against the published
package: it fetches a git ref (the release tag by default, any ref with
`REF=`) with `zig fetch --save` into a copy of `oobt/package`, a standalone
consumer project, and builds and runs it there. `rake release` runs it on
the new tag, checks the fetched version, and refreshes the README's
pinned-dependency example
- CI tests Windows again (`windows-latest`: lint, build, unit tests and
demos). With Zig 0.16.0, a refused connection on Windows is reported as
`error.Unexpected`: std's `netConnectIpWindows` does not map
`STATUS_CONNECTION_REFUSED`
- CI: the coverage job runs on Linux arm64 (Debian trixie container) instead
of macOS, where kcov hung the unit-test binary until the step timed out on
every run. It is no longer advisory, and fails below 90% line coverage
Expand Down
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Zig 0.16.0 or higher is required.
Add the dependency to your project:

```bash
zig fetch --save 'git+https://github.com/serpapi/serpapi-zig#v1.1.0'
zig fetch --save 'git+https://github.com/serpapi/serpapi-zig#v1.2.0'
```

Then wire the module in your `build.zig`:
Expand All @@ -46,7 +46,7 @@ selects which one you get:

```bash
# a released version (recommended)
zig fetch --save 'git+https://github.com/serpapi/serpapi-zig#v1.1.0'
zig fetch --save 'git+https://github.com/serpapi/serpapi-zig#v1.2.0'

# the development branch — moves, may break
zig fetch --save 'git+https://github.com/serpapi/serpapi-zig'
Expand Down Expand Up @@ -77,7 +77,7 @@ resolves to the old package, and the build quietly keeps using it.
A release tarball works too, and produces the same hash as its tag:

```bash
zig fetch --save 'https://github.com/serpapi/serpapi-zig/archive/refs/tags/v1.1.0.tar.gz'
zig fetch --save 'https://github.com/serpapi/serpapi-zig/archive/refs/tags/v1.2.0.tar.gz'
```

Released versions are listed on the
Expand Down Expand Up @@ -432,6 +432,21 @@ zig build test --build-file demo/wasm/build.zig
A `Rakefile` wraps the same steps for anyone used to the other SerpApi
libraries — `rake --tasks` lists them all.

`rake oobt:package` tests the published package the way a user gets it.
It copies `oobt/package`, a standalone project with no dependency, to a
temporary directory, runs `zig fetch --save` there against GitHub, and runs
the out-of-box demo on what it fetched. It fetches the release tag by
default, or any branch, tag or commit with `REF`:

```bash
rake oobt:package # v<version from build.zig.zon>
REF=master rake oobt:package # what the next release would ship
```

`rake release` runs it on the new tag once the tag is pushed, and then
refreshes the pinned-dependency example above with the fetched URL and
hash, for you to commit.

## Cross compilation

Zig cross-compiles without a toolchain to install, so the library builds for
Expand Down Expand Up @@ -494,7 +509,7 @@ zig build cov
open zig-out/coverage/merged/kcov-merged/index.html
```

Current state: **98.28% of lines covered** (974 of 991) with `SERPAPI_KEY`
Current state: **98.29% of lines covered** (975 of 992) with `SERPAPI_KEY`
set, as measured by CI, which publishes the figure to every job summary and
fails below 90%. Without a key, the tests covering `html`, `md`,
`searchArchive`, and `account` skip themselves rather than fail, so those
Expand All @@ -517,13 +532,14 @@ binaries and merges the two reports.

Full details in [CHANGELOG.md](CHANGELOG.md).

- [2026-11-30] 1.2.0 Image API, error details, User-Agent usage reporting and a safer client dump
- [2026-12-04] 1.2.0 Image API, error details, User-Agent usage reporting and a safer client dump
- Added `uploadImage()` and `uploadImageBytes()` (and typed `uploadImageAs()` / `uploadImageBytesAs()`) for the [Image API](https://serpapi.com/image-api), returning the `image_id` to use with engines such as `google_lens`. The `api_key` goes in the form body, never in the URL, and images over 500 KiB fail fast with `error.ImageTooLarge`
- Added `lastError()`, returning a `serpapi.ErrorInfo` with the message, HTTP status, request URL (without the `api_key`) and `search_id` of the last failure
- Printing a client with `{f}` masks the API key (`abcd****wxyz`)
- `errorMessage()` and `lastError()` describe the most recent request only: a success or a transport error clears the previous failure
- **Breaking:** the API key moved out of `Client.params` (use `apiKey()`), `Client.last_error` is now `?serpapi.ErrorInfo`, and `serpapi.Error` gains `ImageTooLarge`. Pin `v1.1.0` to keep the old API
- `rake release` runs lint, tests, integration tests and oobt, and only from a clean `master`
- `rake release` runs lint, tests, integration tests and oobt, only from a clean `master` identical to `origin/master`, and only once the CHANGELOG, the README install commands and the release date match the version. After pushing the tag, it fetches it as a user would (`rake oobt:package`)
- CI tests Windows again. With Zig 0.16.0, a refused connection on Windows is reported as `error.Unexpected`
- Every request identifies the library, the Zig version and the platform in its `User-Agent` header (`serpapi.user_agent`, e.g. `serpapi-zig/1.2.0 zig/0.16.0 (macos; aarch64)`) instead of the `source` query parameter, as serpapi-ruby does
- A `source` passed to the constructor is sent once, as given; it was previously sent alongside the library's own
- [2026-09-23] 1.1.0 Markdown output, timeouts and connection reuse
Expand Down
103 changes: 95 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@
# The Zig build system does the real work; these tasks mirror the
# serpapi-ruby Rakefile so every SerpApi library automates the same steps.

require 'date'
require 'tmpdir'

REPO_URL = 'https://github.com/serpapi/serpapi-zig'

# The version lives in one place, build.zig.zon.
def zon_version
version = File.read('build.zig.zon')[/\.version\s*=\s*"([^"]+)"/, 1]
raise 'cannot read version from build.zig.zon' if version.nil?

version
end

# Point the README's pinned-dependency example at `tag`, with the url and
# hash that `zig fetch --save` recorded for it.
def update_readme_pin(tag, url, hash)
replacements = {
/Pinning `v[^`]+`, for instance, produced:/ => "Pinning `#{tag}`, for instance, produced:",
%r{\.url = "git\+https://github\.com/serpapi/serpapi-zig\?ref=[^"]+"} => %(.url = "#{url}"),
/\.hash = "serpapi-[^"]+"/ => %(.hash = "#{hash}")
}
readme = File.read('README.md')
replacements.each do |pattern, text|
raise "README.md: no match for #{pattern.inspect}" unless readme.match?(pattern)

readme = readme.sub(pattern) { text }
end
File.write('README.md', readme)
end

# Cross-compilation targets, named after the CPU architectures listed in
# https://zig.guide/build-system/cross-compilation
# Zig spells i386 as "x86"; every other name maps one to one.
Expand All @@ -22,6 +52,38 @@ task oobt: %i[lint build] do
sh 'zig build oobt'
end

namespace :oobt do
desc 'out-of-box test of the published package: zig fetch a git ref (REF, default: the ' \
'release tag) into a fresh copy of oobt/package and run the demo (needs SERPAPI_KEY)'
task :package, [:ref] do |_task, args|
raise 'SERPAPI_KEY is required: the demo runs a live search' if ENV['SERPAPI_KEY'].to_s.empty?

tag = "v#{zon_version}"
ref = args[:ref] || ENV.fetch('REF', tag)
url = hash = nil
Dir.mktmpdir('serpapi-zig-oobt-') do |dir|
cp %w[oobt/package/build.zig oobt/package/build.zig.zon oobt/demo.zig], dir
Dir.chdir(dir) do
# exactly what the README tells users to run
sh "zig fetch --save '#{REPO_URL.sub('https://', 'git+https://')}##{ref}'"
sh 'zig build run'
zon = File.read('build.zig.zon')
url = zon[/\.url = "([^"]+)"/, 1]
hash = zon[/\.hash = "([^"]+)"/, 1]
end
end
raise 'zig fetch --save recorded no url or hash' if url.nil? || hash.nil?

puts "fetched: #{url}", "hash: #{hash}"
next unless ref == tag

raise "#{tag} holds #{hash}, not version #{zon_version}" unless hash.start_with?("serpapi-#{zon_version}-")

update_readme_pin(tag, url, hash)
puts "README.md: the pinned-dependency example now shows #{tag}; commit it"
end
end

desc 'execute all the steps except release'
task default: %i[lint build test doc]

Expand Down Expand Up @@ -128,7 +190,7 @@ namespace :install do
end

namespace :release do
desc 'fail fast unless on a clean master with SERPAPI_KEY set'
desc 'fail fast unless on a clean master, identical to origin/master, with SERPAPI_KEY set'
task :preflight do
# release pushes master and the tag, so it must run from master
branch = `git rev-parse --abbrev-ref HEAD`.strip
Expand All @@ -140,16 +202,41 @@ namespace :release do
raise 'git status failed' unless $?.success?
raise "working tree is dirty, commit first:\n#{dirty}" unless dirty.strip.empty?
raise 'SERPAPI_KEY is required: without it the integration tests skip' if ENV['SERPAPI_KEY'].to_s.empty?

# the tag goes on HEAD, so HEAD must be exactly what GitHub's master holds
sh 'git fetch --quiet origin master'
head = `git rev-parse HEAD`.strip
upstream = `git rev-parse origin/master`.strip
unless head == upstream
raise "HEAD #{head[0, 7]} is not origin/master #{upstream[0, 7]}: run `git pull --ff-only` (or push) first"
end
end
end

desc 'release: run every check, then tag the current version and push it to GitHub'
task release: %i[release:preflight lint test itest oobt] do
version = File.read('build.zig.zon')[/\.version\s*=\s*"([^"]+)"/, 1]
raise 'cannot read version from build.zig.zon' if version.nil?
desc "fail unless CHANGELOG.md and README.md announce this version, dated today"
task :docs do
version = zon_version
today = Date.today.iso8601

latest, date = File.read('CHANGELOG.md').match(/^## (\S+) \((\d{4}-\d{2}-\d{2})\)$/)&.captures
raise "CHANGELOG.md: the latest entry is #{latest.inspect}, not #{version}" unless latest == version
raise "CHANGELOG.md: #{version} is dated #{date}; the release date is today, #{today}" unless date == today

readme = File.read('README.md')
stale = readme.scan(%r{serpapi-zig(?:#|/archive/refs/tags/)v(\d+\.\d+\.\d+)}).flatten.uniq - [version]
raise "README.md: install commands pin v#{stale.join(', v')}, not v#{version}" unless stale.empty?

date = readme[/^- \[(\d{4}-\d{2}-\d{2})\] #{Regexp.escape(version)} /, 1]
raise "README.md: the Changelog section dates #{version} #{date.inspect}, not #{today}" unless date == today
end
end

desc 'release: check the docs, run every check, tag the version, push it, then fetch the tag as a user would'
task release: %i[release:preflight release:docs lint test itest oobt] do
version = zon_version
puts "releasing v#{version}"
sh "git tag -a v#{version} -m 'Release v#{version}'"
sh 'git push origin master --tags'
puts "released: https://github.com/serpapi/serpapi-zig/releases/tag/v#{version}"
# master is already on GitHub (preflight); push this tag only, not every local tag
sh "git push origin v#{version}"
puts "released: #{REPO_URL}/releases/tag/v#{version}"
Rake::Task['oobt:package'].invoke("v#{version}")
end
34 changes: 34 additions & 0 deletions oobt/package/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Out-of-box test of the published package.
//!
//! A standalone consumer project, built the way a user's project is: it
//! gets serpapi with `zig fetch --save`, not from this checkout. Its
//! `build.zig.zon` lists no dependency on purpose. `rake oobt:package`
//! copies this directory and `oobt/demo.zig` to a temporary directory,
//! fetches a git ref of serpapi-zig there (the release tag by default), and
//! runs the demo against it.

const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const serpapi = b.dependency("serpapi", .{
.target = target,
.optimize = optimize,
});

const exe = b.addExecutable(.{
.name = "oobt",
.root_module = b.createModule(.{
.root_source_file = b.path("demo.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "serpapi", .module = serpapi.module("serpapi") }},
}),
});

const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the out-of-box demo against the fetched package (needs SERPAPI_KEY)");
run_step.dependOn(&run_exe.step);
}
14 changes: 14 additions & 0 deletions oobt/package/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.{
.name = .serpapi_oobt,
.version = "0.0.0",
.fingerprint = 0x4e6198af6f9f6dcc,
.minimum_zig_version = "0.16.0",
// Empty on purpose: `rake oobt:package` adds serpapi with
// `zig fetch --save`, in a temporary copy of this directory.
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"demo.zig",
},
}
Loading