Skip to content

Commit 6277a45

Browse files
committed
Refresh codebase
I copied most of these changes from many other projects I maintain * Update all dependencies * Set MSRV * Add `justfile` similar to many other FOSS projects to simplify development * Update README * Add pre-commit-config to allow https://pre-commit.com/hooks.html once enabled * Consolidate testing in the `justfile` - this way CI tests can be run locally with the same command * Add ability to auto-publish directly from github on release (needs tokens) * add dependabot
1 parent 0cffc73 commit 6277a45

9 files changed

+241
-53
lines changed

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
- package-ecosystem: cargo
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
time: "02:00"
13+
open-pull-requests-limit: 10

.github/workflows/ci.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- staging
8+
- trying
9+
- release/**
10+
pull_request:
11+
branches: [ main ]
12+
release:
13+
types: [ published ]
14+
workflow_dispatch:
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
jobs:
21+
test:
22+
name: Test
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: taiki-e/install-action@v2
26+
with: { tool: just }
27+
- uses: actions/checkout@v4
28+
- name: Ensure this crate has not yet been published (on release)
29+
if: github.event_name == 'release'
30+
run: just check-if-published
31+
- uses: Swatinem/rust-cache@v2
32+
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
33+
- run: just ci-test
34+
- name: Check semver
35+
uses: obi1kenobi/cargo-semver-checks-action@v2
36+
37+
msrv:
38+
name: Test MSRV
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: taiki-e/install-action@v2
42+
with: { tool: just }
43+
- uses: actions/checkout@v4
44+
- uses: Swatinem/rust-cache@v2
45+
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
46+
- name: Read crate metadata
47+
id: metadata
48+
run: echo "rust-version=$(sed -ne 's/rust-version *= *\"\(.*\)\"/\1/p' Cargo.toml)" >> $GITHUB_OUTPUT
49+
- name: Install Rust
50+
uses: dtolnay/rust-toolchain@stable
51+
with:
52+
toolchain: ${{ steps.metadata.outputs.rust-version }}
53+
- run: just ci-test-msrv
54+
55+
publish:
56+
name: Publish to crates.io
57+
if: startsWith(github.ref, 'refs/tags/')
58+
needs: [ test, msrv ]
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Publish to crates.io
63+
run: cargo publish
64+
env:
65+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/dependabot.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Dependabot auto-merge
2+
on: pull_request
3+
4+
permissions: write-all
5+
6+
jobs:
7+
dependabot:
8+
runs-on: ubuntu-latest
9+
if: github.actor == 'dependabot[bot]'
10+
steps:
11+
- name: Dependabot metadata
12+
id: metadata
13+
uses: dependabot/fetch-metadata@v2.3.0
14+
with:
15+
github-token: "${{ secrets.GITHUB_TOKEN }}"
16+
- name: Approve Dependabot PRs
17+
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
18+
run: gh pr review --approve "$PR_URL"
19+
env:
20+
PR_URL: ${{github.event.pull_request.html_url}}
21+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
22+
- name: Enable auto-merge for Dependabot PRs
23+
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
24+
run: gh pr merge --auto --squash "$PR_URL"
25+
env:
26+
PR_URL: ${{github.event.pull_request.html_url}}
27+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/rust.yml

-30
This file was deleted.

.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: check-added-large-files
8+
- id: check-executables-have-shebangs
9+
- id: check-json
10+
exclude: '.+/tsconfig.json'
11+
- id: check-shebang-scripts-are-executable
12+
exclude: '.+\.rs' # would be triggered by #![some_attribute]
13+
- id: check-symlinks
14+
- id: check-toml
15+
- id: check-yaml
16+
args: [ --allow-multiple-documents ]
17+
- id: destroyed-symlinks
18+
- id: end-of-file-fixer
19+
- id: mixed-line-ending
20+
args: [ --fix=lf ]
21+
- id: trailing-whitespace
22+
23+
- repo: local
24+
hooks:
25+
- id: cargo-fmt
26+
name: Rust Format
27+
description: "Automatically format Rust code with cargo fmt"
28+
entry: sh -c "cargo fmt --all"
29+
language: rust
30+
pass_filenames: false

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tilejson"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = "Library for serializing the TileJSON file format"
55
authors = [
66
"Stepan Kuzmin <to.stepan.kuzmin@gmail.com>",
@@ -14,12 +14,13 @@ repository = "https://github.com/georust/tilejson"
1414
readme = "README.md"
1515
keywords = ["maplibre", "mapbox", "tilejson", "serde"]
1616
categories = ["science::geo"]
17+
rust-version = "1.78"
1718

1819
[dependencies]
1920
serde = { version = "1", features = ["derive"] }
2021
serde_json = "1"
21-
serde_tuple = "0.5"
22-
thiserror = "1"
22+
serde_tuple = "1.1.0"
23+
thiserror = "2"
2324

2425
[lints.rust]
2526
unsafe_code = "forbid"

README.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# tilejson
22

3-
[![Build Status](https://github.com/georust/tilejson/workflows/Run%20tests/badge.svg)](https://github.com/georust/tilejson/actions)
4-
[![tilejson on crates.io](https://img.shields.io/crates/v/tilejson.svg)](https://crates.io/crates/tilejson)
5-
[![API Docs](https://docs.rs/tilejson/badge.svg)](https://docs.rs/tilejson)
3+
[![GitHub](https://img.shields.io/badge/github-tilejson-8da0cb?logo=github)](https://github.com/georust/tilejson)
4+
[![crates.io version](https://img.shields.io/crates/v/tilejson.svg)](https://crates.io/crates/tilejson)
5+
[![docs.rs docs](https://docs.rs/tilejson/badge.svg)](https://docs.rs/tilejson)
6+
[![license](https://img.shields.io/crates/l/tilejson.svg)](https://github.com/georust/tilejson/blob/main/LICENSE-APACHE)
7+
[![CI build](https://github.com/georust/tilejson/actions/workflows/ci.yml/badge.svg)](https://github.com/georust/tilejson/actions)
68

79
`tilejson` is a crate for serializing/deserializing the [TileJSON](https://github.com/mapbox/tilejson-spec) format — an open standard for representing map metadata.
810

@@ -55,17 +57,24 @@ fn main() {
5557

5658
Contributions are welcome! Have a look at the [issues](https://github.com/georust/tilejson/issues), and open a pull request if you'd like to add an algorithm or some functionality.
5759

60+
## Development
61+
62+
* This project is easier to develop with [just](https://github.com/casey/just#readme), a modern alternative to `make`.
63+
Install it with `cargo install just`.
64+
* To get a list of available commands, run `just`.
65+
* To run tests, use `just test`.
66+
5867
## License
5968

6069
Licensed under either of
6170

62-
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
63-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
64-
65-
at your option.
71+
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
72+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
73+
at your option.
6674

6775
### Contribution
6876

69-
Unless you explicitly state otherwise, any contribution intentionally submitted
70-
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
77+
Unless you explicitly state otherwise, any contribution intentionally
78+
submitted for inclusion in the work by you, as defined in the
79+
Apache-2.0 license, shall be dual licensed as above, without any
7180
additional terms or conditions.

justfile

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env just --justfile
2+
3+
@_default:
4+
just --list
5+
6+
# Clean all build artifacts
7+
clean:
8+
cargo clean
9+
rm -f Cargo.lock
10+
11+
# Update dependencies, including breaking changes
12+
update:
13+
cargo +nightly -Z unstable-options update --breaking
14+
cargo update
15+
16+
# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml
17+
msrv:
18+
cargo msrv find --write-msrv
19+
20+
# Run cargo clippy
21+
clippy:
22+
cargo clippy --workspace --all-targets -- -D warnings
23+
24+
# Test code formatting
25+
test-fmt:
26+
cargo fmt --all -- --check
27+
28+
# Run cargo fmt
29+
fmt:
30+
cargo +nightly fmt -- --config imports_granularity=Module,group_imports=StdExternalCrate
31+
32+
# Build and open code documentation
33+
docs:
34+
cargo doc --no-deps --open
35+
36+
# Quick compile
37+
check:
38+
RUSTFLAGS='-D warnings' cargo check
39+
40+
# Run all tests
41+
test:
42+
RUSTFLAGS='-D warnings' cargo test
43+
44+
# Test documentation
45+
test-doc:
46+
cargo test --doc
47+
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
48+
49+
rust-info:
50+
rustc --version
51+
cargo --version
52+
53+
# Run all tests as expected by CI
54+
ci-test: rust-info test-fmt clippy check test test-doc
55+
56+
# Run minimal subset of tests to ensure compatibility with MSRV
57+
ci-test-msrv: rust-info check test
58+
59+
# Verify that the current version of the crate is not the same as the one published on crates.io
60+
check-if-published:
61+
#!/usr/bin/env bash
62+
LOCAL_VERSION="$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')"
63+
echo "Detected crate version: $LOCAL_VERSION"
64+
CRATE_NAME="$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')"
65+
echo "Detected crate name: $CRATE_NAME"
66+
PUBLISHED_VERSION="$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')"
67+
echo "Published crate version: $PUBLISHED_VERSION"
68+
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
69+
echo "ERROR: The current crate version has already been published."
70+
exit 1
71+
else
72+
echo "The current crate version has not yet been published."
73+
fi

src/tilejson.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::vector_layer::VectorLayer;
1313
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
1414
pub struct TileJSON {
1515
/// A semver.org style version number as a string.
16-
/// Describes the version of the TileJSON spec that is implemented by this JSON object.
16+
/// Describes the version of the `TileJSON` spec that is implemented by this JSON object.
1717
/// Example: `"3.0.0"`
1818
/// See <https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#31-tilejson>
1919
pub tilejson: String,
@@ -31,12 +31,12 @@ pub struct TileJSON {
3131

3232
/// An array of objects. Each object describes one layer of vector tile data.
3333
///
34-
/// A vector_layer object MUST contain the id and fields keys, and MAY contain the description,
34+
/// A `vector_layer` object MUST contain the id and fields keys, and MAY contain the description,
3535
/// minzoom, or maxzoom keys. An implementation MAY include arbitrary keys in the object
3636
/// outside of those defined in this specification.
3737
///
3838
/// *Note: When describing a set of raster tiles or other tile format that does not have
39-
/// a "layers" concept (i.e. "format": "jpeg"), the vector_layers key is not required.*
39+
/// a "layers" concept (i.e. "format": "jpeg"), the `vector_layers` key is not required.*
4040
///
4141
/// See <https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#33-vector_layers>
4242
#[serde(skip_serializing_if = "Option::is_none")]
@@ -82,20 +82,20 @@ pub struct TileJSON {
8282
#[serde(skip_serializing_if = "Option::is_none")]
8383
pub center: Option<Center>,
8484

85-
/// An array of data files in GeoJSON format.
85+
/// An array of data files in `GeoJSON` format.
8686
///
8787
/// {z}, {x} and {y}, if present, are replaced with the corresponding integers.
8888
/// If multiple endpoints are specified, clients may use any combination of endpoints.
8989
/// All endpoints MUST return the same content for the same URL. If the array doesn't
9090
/// contain any entries, then no data is present in the map. This field is for overlaying
91-
/// GeoJSON data on tiled raster maps and is generally no longer used for GL-based maps.
91+
/// `GeoJSON` data on tiled raster maps and is generally no longer used for GL-based maps.
9292
/// See <https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#37-data>
9393
#[serde(skip_serializing_if = "Option::is_none")]
9494
pub data: Option<Vec<String>>,
9595

9696
/// A text description of the set of tiles.
9797
///
98-
/// The description can contain any valid unicode character as described by the JSON specification RFC 8259.
98+
/// The description can contain any valid Unicode character as described by the JSON specification RFC 8259.
9999
/// See <https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#38-description>
100100
#[serde(skip_serializing_if = "Option::is_none")]
101101
pub description: Option<String>,
@@ -109,10 +109,10 @@ pub struct TileJSON {
109109
///
110110
/// For example, in a set of tiles with maxzoom 10 and no fillzoom specified,
111111
/// a request for a z11 tile will use the z10 parent tiles to generate the new,
112-
/// overzoomed z11 tile. If the same TileJSON object had fillzoom specified at z7,
112+
/// overzoomed z11 tile. If the same `TileJSON` object had fillzoom specified at z7,
113113
/// a request for a z11 tile would use the z7 tile instead of z10.
114114
///
115-
/// While TileJSON may specify rules for overzooming tiles, it is ultimately up to the tile
115+
/// While `TileJSON` may specify rules for overzooming tiles, it is ultimately up to the tile
116116
/// serving client or renderer to implement overzooming.
117117
///
118118
/// OPTIONAL. Integer. Default: null.
@@ -129,7 +129,7 @@ pub struct TileJSON {
129129
/// See <https://github.com/mapbox/utfgrid-spec/tree/master/1.2> for the interactivity specification.
130130
///
131131
/// *Note: UTF-Grid interactivity predates GL-based map rendering and interaction.
132-
/// Map interactivity is now generally defined outside of the TileJSON specification
132+
/// Map interactivity is now generally defined outside the `TileJSON` specification
133133
/// and is dependent on the tile rendering library's features.*
134134
///
135135
/// See <https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#310-grids>
@@ -148,8 +148,8 @@ pub struct TileJSON {
148148
/// An integer specifying the maximum zoom level.
149149
///
150150
/// MUST be in range: 0 <= minzoom <= maxzoom <= 30.
151-
/// A client or server MAY request tiles outside of the zoom range,
152-
/// but the availability of these tiles is dependent on how the the tile server
151+
/// A client or server MAY request tiles outside the zoom range,
152+
/// but the availability of these tiles is dependent on how the tile server
153153
/// or renderer handles the request (such as overzooming tiles).
154154
/// OPTIONAL. Integer. Default: 30.
155155
/// See <https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#312-maxzoom>

0 commit comments

Comments
 (0)