homebrew
provider for stackql
This repository is used to generate and document the homebrew
provider for StackQL, allowing you to query Homebrew packages, formulas, and repositories using SQL-like syntax. The provider is built using the @stackql/provider-utils
package, which provides tools for converting OpenAPI specifications into StackQL-compatible provider schemas.
To use the Homebrew provider with StackQL, you'll need:
- StackQL CLI installed on your system (see StackQL)
- Basic understanding of Homebrew API endpoints
First, create an OpenAPI specification for the Homebrew API (since Homebrew doesn't provide an official one):
mkdir -p provider-dev/downloaded
# Create or download the homebrew OpenAPI spec
# You'll need to implement a script that generates an OpenAPI spec from Homebrew's API endpoints
python3 provider-dev/scripts/generate_homebrew_spec.py \
--output provider-dev/downloaded/openapi.json
Next, split the OpenAPI specification into service-specific files:
rm -rf provider-dev/source/*
npm run split -- \
--provider-name homebrew \
--api-doc provider-dev/downloaded/openapi.json \
--svc-discriminator tag \
--output-dir provider-dev/source \
--overwrite \
--svc-name-overrides "$(cat <<EOF
{
"formulas": "formulas",
"casks": "casks",
"analytics": "analytics",
"taps": "taps"
}
EOF
)"
Generate the mapping configuration that connects OpenAPI operations to StackQL resources:
npm run generate-mappings -- \
--provider-name homebrew \
--input-dir provider-dev/source \
--output-dir provider-dev/config
Update the resultant provider-dev/config/all_services.csv
to add the stackql_resource_name
, stackql_method_name
, stackql_verb
values for each operation.
This step transforms the split OpenAPI service specs into a fully-functional StackQL provider by applying the resource and method mappings defined in your CSV file.
rm -rf provider-dev/openapi/*
npm run generate-provider -- \
--provider-name homebrew \
--input-dir provider-dev/source \
--output-dir provider-dev/openapi/src/homebrew \
--config-path provider-dev/config/all_services.csv \
--servers '[{"url": "https://formulae.brew.sh/api"}]' \
--provider-config '{"auth": {"type": "none"}}' \
--overwrite
Before running tests, start a StackQL server with your provider:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
npm run start-server -- --provider homebrew --registry $PROVIDER_REGISTRY_ROOT_DIR
Test all metadata routes (services, resources, methods) in the provider:
npm run test-meta-routes -- homebrew --verbose
When you're done testing, stop the StackQL server:
npm run stop-server
Use this command to view the server status:
npm run server-status
Run some test queries against the provider using the stackql shell
:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
REG_STR='{"url": "file://'${PROVIDER_REGISTRY_ROOT_DIR}'", "localDocRoot": "'${PROVIDER_REGISTRY_ROOT_DIR}'", "verifyConfig": {"nopVerify": true}}'
./stackql shell --registry="${REG_STR}"
Example queries to try:
-- List all formulas
SELECT
name,
full_name,
desc,
license,
homepage,
versions,
dependencies,
conflicts_with
FROM homebrew.formulas.formulas;
-- Get information about a specific formula
SELECT
name,
full_name,
desc,
license,
homepage,
versions,
dependencies,
conflicts_with,
build_dependencies,
requirements
FROM homebrew.formulas.formula
WHERE name = 'wget';
-- List all casks
SELECT
name,
full_name,
token,
desc,
homepage,
version,
url
FROM homebrew.casks.casks;
-- Get analytics for popular formula installations
SELECT
formula,
count,
percent
FROM homebrew.analytics.install_30d
ORDER BY count DESC
LIMIT 10;
-- Get analytics for formula installations over longer periods
SELECT
formula,
count,
percent
FROM homebrew.analytics.install_365d
ORDER BY count DESC
LIMIT 10;
To publish the provider push the homebrew
dir to providers/src
in a feature branch of the stackql-provider-registry
. Follow the registry release flow.
Launch the StackQL shell:
export DEV_REG="{ \"url\": \"https://registry-dev.stackql.app/providers\" }"
./stackql --registry="${DEV_REG}" shell
Pull the latest dev homebrew
provider:
registry pull homebrew;
Run some test queries to verify the provider works as expected.
Provider doc microsites are built using Docusaurus and published using GitHub Pages.
a. Update headerContent1.txt
and headerContent2.txt
accordingly in provider-dev/docgen/provider-data/
b. Update the following in website/docusaurus.config.js
:
// Provider configuration - change these for different providers
const providerName = "homebrew";
const providerTitle = "Homebrew Provider";
c. Then generate docs using...
npm run generate-docs -- \
--provider-name homebrew \
--provider-dir ./provider-dev/openapi/src/homebrew/v00.00.00000 \
--output-dir ./website \
--provider-data-dir ./provider-dev/docgen/provider-data
cd website
# test build
yarn build
# run local dev server
yarn start
Under Pages in the repository, in the Build and deployment section select GitHub Actions as the Source. In Netlify DNS create the following records:
Source Domain | Record Type | Target |
---|---|---|
homebrew-provider.stackql.io | CNAME | stackql.github.io. |
MIT
Contributions are welcome! Please feel free to submit a Pull Request.