Skip to content
Merged
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
48 changes: 47 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Release the visualci CLI: static binaries for Linux (musl) and macOS, attached to a GitHub release v<version>; and
# publish the snapshot-diff crate (crates/snapshot-diff) to crates.io when its version isn't there yet.
# publish the snapshot-diff crate (crates/snapshot-diff) to crates.io when its version isn't there yet (and, once their
# Cargo.toml files drop `publish = false`, envschema-derive and envschema).
# A release happens by itself once CI passes on main with a workspace version (Cargo.toml) that has no release yet, so
# a version bump is all it takes and the docs never describe a CLI nobody can download. The cli-version job in ci.yml
# fails when the CLI changed since its last release without a bump. Pushing a v* tag by hand still works too.
Expand Down Expand Up @@ -128,3 +129,48 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked -p snapshot-diff

# envschema-derive and envschema on crates.io, the same way: once per version in their Cargo.toml files, the derive
# first (envschema depends on it). Inert while either Cargo.toml says `publish = false`. Before that line goes, the
# first release of each is published by hand with a per-crate token, and trusted publishing is configured on
# crates.io for both crates (DocSpring/visualci, release.yml); this job then publishes every later version.
envschema:
if: github.event_name == 'push' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- id: version
run: |
publish=
for crate in envschema-derive envschema; do
manifest=crates/$crate/Cargo.toml
if grep -q '^publish = false' "$manifest"; then
echo "$crate isn't published yet ($manifest says publish = false)"
continue
fi
version=$(sed -n 's/^version = "\(.*\)"/\1/p' "$manifest" | head -1)
code=$(curl -s -o /dev/null -w '%{http_code}' -A 'envschema release (github.com/DocSpring/visualci)' \
"https://crates.io/api/v1/crates/$crate/$version")
if [ "$code" = 200 ]; then
echo "$crate $version is already on crates.io"
else
publish="$publish $crate"
fi
done
echo "crates=${publish# }" >> "$GITHUB_OUTPUT"
- id: auth
if: steps.version.outputs.crates != ''
uses: rust-lang/crates-io-auth-action@v1
- if: steps.version.outputs.crates != ''
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
CRATES: ${{ steps.version.outputs.crates }}
run: |
for crate in $CRATES; do
cargo publish --locked -p "$crate"
done
8 changes: 8 additions & 0 deletions crates/envschema-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ name = "envschema-derive"
description = "The derive macro for envschema: typed settings read from environment variables"
version = "0.1.0"
edition.workspace = true
rust-version = "1.88"
license.workspace = true
repository.workspace = true
homepage = "https://github.com/DocSpring/visualci/tree/main/crates/envschema"
documentation = "https://docs.rs/envschema-derive"
readme = "README.md"
keywords = ["config", "environment", "env", "settings", "derive"]
categories = ["config"]
# Not published yet: VisualCI's server runs it in production first. This flips to `true` (the line goes) when we publish
# envschema-derive and envschema to crates.io, together with the envschema jobs in .github/workflows/release.yml.
publish = false

[lib]
Expand Down
1 change: 1 addition & 0 deletions crates/envschema-derive/LICENSE
12 changes: 12 additions & 0 deletions crates/envschema-derive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# envschema-derive

The `#[derive(Settings)]` macro for [envschema](https://crates.io/crates/envschema): typed settings read from prefixed
environment variables, with one schema for loading, checks, secret masking, warnings about unknown variables and
generated docs.

Don't depend on this crate directly: envschema re-exports the derive as `envschema::Settings`, and the code it
generates refers to `::envschema`. The attributes are documented there, in
[envschema's README](https://github.com/DocSpring/visualci/blob/main/crates/envschema/README.md) and
[on docs.rs](https://docs.rs/envschema).

MSRV: Rust 1.88. Licensed under Apache-2.0.
8 changes: 6 additions & 2 deletions crates/envschema-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! `#[derive(Settings)]` for [envschema](https://github.com/DocSpring/visualci/tree/main/crates/envschema). The
//! attributes are documented on the derive's re-export, `envschema::Settings`.
//! `#[derive(Settings)]` for [envschema](https://docs.rs/envschema). The attributes are documented on the derive's
//! re-export, `envschema::Settings`. Depend on envschema, not on this crate: the code the derive generates refers to
//! `::envschema`.
#![deny(missing_docs)]

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

/// `#[derive(Settings)]`: implements `envschema::Settings` and a `Debug` that masks secrets. See `envschema::Settings`
/// for the attributes.
#[proc_macro_derive(Settings, attributes(env, settings))]
pub fn derive_settings(input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input as DeriveInput);
Expand Down
7 changes: 6 additions & 1 deletion crates/envschema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ name = "envschema"
description = "Typed settings from prefixed environment variables, with one schema for loading, checks, secret masking, warnings about unknown variables, and generated docs"
version = "0.1.0"
edition.workspace = true
rust-version = "1.88"
license.workspace = true
repository.workspace = true
homepage = "https://github.com/DocSpring/visualci/tree/main/crates/envschema"
documentation = "https://docs.rs/envschema"
readme = "README.md"
keywords = ["config", "environment", "env", "settings", "dotenv"]
categories = ["config"]
# Used by VisualCI's server for now; published once its API has settled.
# Not published yet: VisualCI's server runs it in production first. This flips to `true` (the line goes) when we publish
# envschema-derive and envschema to crates.io, together with the envschema jobs in .github/workflows/release.yml.
publish = false

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/envschema/LICENSE
Loading
Loading