Skip to content

Commit

Permalink
feat: add brew release
Browse files Browse the repository at this point in the history
  • Loading branch information
eknowles committed Aug 16, 2024
1 parent 6528d62 commit ca58322
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 8 deletions.
42 changes: 34 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
push:
branches:
- main
workflow_dispatch: # Allows manual triggering
workflow_dispatch:

jobs:
release:
Expand All @@ -25,23 +25,49 @@ jobs:
with:
bun-version: latest

- name: Build artifacts
run: |
bun build --compile --minify --target=bun-linux-x64-modern src/cli.ts --outfile tile-packer-linux-x64
bun build --compile --minify --target=bun-darwin-arm64 src/cli.ts --outfile tile-packer-macos-arm64
bun build --compile --minify --target=bun-darwin-x64-modern src/cli.ts --outfile tile-packer-macos-x64
bun build --compile --minify --target=bun-windows-x64-modern src/cli.ts --outfile tile-packer-windows-x64.exe
- name: Upload release assets
uses: googleapis/release-please-action@v4
id: release
with:
token: ${{ secrets.RELEASE_TOKEN }}
release-type: node

- name: Build artifacts
run: |
bun build --compile --minify --target=bun-linux-x64-modern src/cli.ts --outfile tile-packer-linux-x64
bun build --compile --minify --target=bun-darwin-arm64 src/cli.ts --outfile tile-packer-macos-arm64
bun build --compile --minify --target=bun-darwin-x64-modern src/cli.ts --outfile tile-packer-macos-x64
bun build --compile --minify --target=bun-windows-x64-modern src/cli.ts --outfile tile-packer-windows-x64.exe
- name: Upload Release Artifact
if: ${{ steps.release.outputs.release_created }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
gh release upload ${{ steps.release.outputs.tag_name }} tile-packer-linux-x64 tile-packer-macos-arm64 tile-packer-macos-x64 tile-packer-windows-x64.exe
- name: Brew Release
if: ${{ steps.release.outputs.release_created }}
uses: Justintime50/homebrew-releaser@v1
with:
github_token: ${{ secrets.RELEASE_TOKEN }}
homebrew_owner: eknowles
homebrew_tap: tools
install: |
if Hardware::CPU.arm? && OS.mac?
bin.install "tile-packer-macos-arm64" => "tile-packer"
elsif Hardware::CPU.intel? && OS.mac?
bin.install "tile-packer-macos-x64" => "tile-packer"
elsif OS.linux?
bin.install "tile-packer-linux-x64" => "tile-packer"
end
test: 'assert_match("tile-packer ${{steps.release.outputs.tag_name}}", shell_output("#{bin}/tile-packer --version"))'

target_darwin_amd64: true
target_darwin_arm64: true
target_linux_amd64: true

update_readme_table: true

debug: false
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# tile-packer

Fetches XYZ tiles from a URL within a given zoom level range, creates an MBTiles
file that can be converted into a PMTiles file.

Supports custom headers, and concurrency control.

## Installation

```bash
brew tap eknowles/tools
brew install tile-packer
```

## Usage

```bash
tile-packer -i <input_url> [options]
```

## Options

- `-i, --input <input_url>` (required):
The base URL for the XYZ tiles.

- `-o, --output <output_file>` (default: `output.mbtiles`):
The path where the MBTiles file will be saved.

- `--minzoom <min_zoom>`:
The minimum zoom level to fetch tiles.

- `--maxzoom <max_zoom>`:
The maximum zoom level to fetch tiles.

- `--bbox <bounding_box>`:
The bounding box for the tile fetching in the
format `minLon,minLat,maxLon,maxLat`.

- `--header <header>` (can be used multiple times):
HTTP headers to include in tile requests. Use this option for each header.

- `--token <api_token>`:
An API token for authenticated requests.

- `--retry <retry_count>` (default: `0`):
The number of retry attempts for failed requests.

- `--format <image_format>` (default: `png`):
The format of the tiles (e.g., `png`, `jpeg`).

- `--concurrency <concurrent_requests>` (default: `15`):
The number of concurrent requests to fetch tiles.

## Example

```bash
tile-packer \
--input "https://example.com/tiles/{z}/{x}/{y}.png" \
--output satellite.mbtiles \
--minzoom 2 \
--maxzoom 13 \
--bbox=-180,-85,180,85 \
--header "Authorization: Bearer <token>" \
--concurrency 20
```

This command will fetch tiles from zoom level 5 to 13 within the specified
bounding box, save them as `satellite.mbtiles`, and use 20 concurrent requests
for fetching.

## Converting to PMTiles

Once the MBTiles file is generated, you can convert it to a PMTiles.

```shell
pmtiles convert satellite.mbtiles satellite.pmtiles
```
File renamed without changes.
8 changes: 8 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "./utils";

interface CliArgs {
version: boolean;
output: string;
input: string;
minzoom: number;
Expand All @@ -28,6 +29,7 @@ interface CliArgs {
const { values } = parseArgs({
args: Bun.argv.slice(2),
options: {
version: { type: "boolean", short: "v" },
output: { type: "string", short: "o", default: "output.mbtiles" },
input: { type: "string", short: "i" },
minzoom: { type: "string" },
Expand All @@ -44,6 +46,7 @@ const { values } = parseArgs({
});

const args: CliArgs = {
version: values.version as boolean,
output: values.output as string,
input: values.input as string,
minzoom: parseInt(values.minzoom as string),
Expand All @@ -56,6 +59,11 @@ const args: CliArgs = {
concurrency: parseInt(values.concurrency as string),
};

if (args.version) {
console.log("tile-packer v1.0.0");
process.exit(0);
}

if (!args.input || !args.bbox) {
console.error(
"Missing required arguments. Use --help for usage information.",
Expand Down

0 comments on commit ca58322

Please sign in to comment.