Skip to content

Commit d64bb35

Browse files
authored
envschema: ready to publish (README, Apache-2.0, docs.rs examples, a Laravel Rust example) (#142)
1 parent 8c44c71 commit d64bb35

10 files changed

Lines changed: 651 additions & 46 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Release the visualci CLI: static binaries for Linux (musl) and macOS, attached to a GitHub release v<version>; and
2-
# publish the snapshot-diff crate (crates/snapshot-diff) to crates.io when its version isn't there yet.
2+
# publish the snapshot-diff crate (crates/snapshot-diff) to crates.io when its version isn't there yet (and, once their
3+
# Cargo.toml files drop `publish = false`, envschema-derive and envschema).
34
# A release happens by itself once CI passes on main with a workspace version (Cargo.toml) that has no release yet, so
45
# a version bump is all it takes and the docs never describe a CLI nobody can download. The cli-version job in ci.yml
56
# fails when the CLI changed since its last release without a bump. Pushing a v* tag by hand still works too.
@@ -128,3 +129,48 @@ jobs:
128129
env:
129130
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
130131
run: cargo publish --locked -p snapshot-diff
132+
133+
# envschema-derive and envschema on crates.io, the same way: once per version in their Cargo.toml files, the derive
134+
# first (envschema depends on it). Inert while either Cargo.toml says `publish = false`. Before that line goes, the
135+
# first release of each is published by hand with a per-crate token, and trusted publishing is configured on
136+
# crates.io for both crates (DocSpring/visualci, release.yml); this job then publishes every later version.
137+
envschema:
138+
if: github.event_name == 'push' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
139+
runs-on: ubuntu-latest
140+
permissions:
141+
contents: read
142+
id-token: write
143+
steps:
144+
- uses: actions/checkout@v4
145+
with:
146+
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
147+
- id: version
148+
run: |
149+
publish=
150+
for crate in envschema-derive envschema; do
151+
manifest=crates/$crate/Cargo.toml
152+
if grep -q '^publish = false' "$manifest"; then
153+
echo "$crate isn't published yet ($manifest says publish = false)"
154+
continue
155+
fi
156+
version=$(sed -n 's/^version = "\(.*\)"/\1/p' "$manifest" | head -1)
157+
code=$(curl -s -o /dev/null -w '%{http_code}' -A 'envschema release (github.com/DocSpring/visualci)' \
158+
"https://crates.io/api/v1/crates/$crate/$version")
159+
if [ "$code" = 200 ]; then
160+
echo "$crate $version is already on crates.io"
161+
else
162+
publish="$publish $crate"
163+
fi
164+
done
165+
echo "crates=${publish# }" >> "$GITHUB_OUTPUT"
166+
- id: auth
167+
if: steps.version.outputs.crates != ''
168+
uses: rust-lang/crates-io-auth-action@v1
169+
- if: steps.version.outputs.crates != ''
170+
env:
171+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
172+
CRATES: ${{ steps.version.outputs.crates }}
173+
run: |
174+
for crate in $CRATES; do
175+
cargo publish --locked -p "$crate"
176+
done

‎crates/envschema-derive/Cargo.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ name = "envschema-derive"
33
description = "The derive macro for envschema: typed settings read from environment variables"
44
version = "0.1.0"
55
edition.workspace = true
6+
rust-version = "1.88"
67
license.workspace = true
78
repository.workspace = true
9+
homepage = "https://github.com/DocSpring/visualci/tree/main/crates/envschema"
10+
documentation = "https://docs.rs/envschema-derive"
11+
readme = "README.md"
12+
keywords = ["config", "environment", "env", "settings", "derive"]
13+
categories = ["config"]
14+
# Not published yet: VisualCI's server runs it in production first. This flips to `true` (the line goes) when we publish
15+
# envschema-derive and envschema to crates.io, together with the envschema jobs in .github/workflows/release.yml.
816
publish = false
917

1018
[lib]

‎crates/envschema-derive/LICENSE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

‎crates/envschema-derive/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# envschema-derive
2+
3+
The `#[derive(Settings)]` macro for [envschema](https://crates.io/crates/envschema): typed settings read from prefixed
4+
environment variables, with one schema for loading, checks, secret masking, warnings about unknown variables and
5+
generated docs.
6+
7+
Don't depend on this crate directly: envschema re-exports the derive as `envschema::Settings`, and the code it
8+
generates refers to `::envschema`. The attributes are documented there, in
9+
[envschema's README](https://github.com/DocSpring/visualci/blob/main/crates/envschema/README.md) and
10+
[on docs.rs](https://docs.rs/envschema).
11+
12+
MSRV: Rust 1.88. Licensed under Apache-2.0.

‎crates/envschema-derive/src/lib.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
//! `#[derive(Settings)]` for [envschema](https://github.com/DocSpring/visualci/tree/main/crates/envschema). The
2-
//! attributes are documented on the derive's re-export, `envschema::Settings`.
1+
//! `#[derive(Settings)]` for [envschema](https://docs.rs/envschema). The attributes are documented on the derive's
2+
//! re-export, `envschema::Settings`. Depend on envschema, not on this crate: the code the derive generates refers to
3+
//! `::envschema`.
4+
#![deny(missing_docs)]
35

46
use proc_macro::TokenStream;
57
use proc_macro2::{Span, TokenStream as TokenStream2};
@@ -9,6 +11,8 @@ use syn::{
911
Attribute, Data, DeriveInput, Error, Expr, Fields, GenericArgument, Ident, Lit, LitStr, PathArguments, Token, Type,
1012
};
1113

14+
/// `#[derive(Settings)]`: implements `envschema::Settings` and a `Debug` that masks secrets. See `envschema::Settings`
15+
/// for the attributes.
1216
#[proc_macro_derive(Settings, attributes(env, settings))]
1317
pub fn derive_settings(input: TokenStream) -> TokenStream {
1418
let input = syn::parse_macro_input!(input as DeriveInput);

‎crates/envschema/Cargo.toml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ name = "envschema"
33
description = "Typed settings from prefixed environment variables, with one schema for loading, checks, secret masking, warnings about unknown variables, and generated docs"
44
version = "0.1.0"
55
edition.workspace = true
6+
rust-version = "1.88"
67
license.workspace = true
78
repository.workspace = true
9+
homepage = "https://github.com/DocSpring/visualci/tree/main/crates/envschema"
10+
documentation = "https://docs.rs/envschema"
11+
readme = "README.md"
812
keywords = ["config", "environment", "env", "settings", "dotenv"]
913
categories = ["config"]
10-
# Used by VisualCI's server for now; published once its API has settled.
14+
# Not published yet: VisualCI's server runs it in production first. This flips to `true` (the line goes) when we publish
15+
# envschema-derive and envschema to crates.io, together with the envschema jobs in .github/workflows/release.yml.
1116
publish = false
1217

1318
[dependencies]

‎crates/envschema/LICENSE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

0 commit comments

Comments
 (0)