Skip to content

docs: implementation plan for publishable harmont-cli crate #3

docs: implementation plan for publishable harmont-cli crate

docs: implementation plan for publishable harmont-cli crate #3

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
crates-io:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
# crates/hm/build.rs cross-compiles hm-plugin-docker as a wasm
# plugin embedded into the binary, so the target must be on
# the toolchain for the `cargo check` in the next step.
targets: wasm32-wasip1
- uses: Swatinem/rust-cache@v2
- name: Set version from tag
run: |
VERSION="${GITHUB_REF_NAME#v}"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
sed -i "0,/version = \"0.0.0-dev\"/s//version = \"$VERSION\"/" crates/hm-plugin-protocol/Cargo.toml
sed -i "0,/version = \"0.0.0-dev\"/s//version = \"$VERSION\"/" crates/hm-plugin-sdk/Cargo.toml
sed -i "0,/version = \"0.0.0-dev\"/s//version = \"$VERSION\"/" crates/hm/Cargo.toml
# Rewrite workspace.dependencies pins so dependents resolve to the
# tagged version (cargo publish strips path deps; the version field
# is what consumers will receive).
sed -i "s|hm-plugin-protocol = { path = \"crates/hm-plugin-protocol\", version = \"0.0.0-dev\" }|hm-plugin-protocol = { path = \"crates/hm-plugin-protocol\", version = \"$VERSION\" }|" Cargo.toml
sed -i "s|hm-plugin-sdk = { path = \"crates/hm-plugin-sdk\", version = \"0.0.0-dev\" }|hm-plugin-sdk = { path = \"crates/hm-plugin-sdk\", version = \"$VERSION\" }|" Cargo.toml
cargo check --workspace --exclude hm-fixtures
- name: Publish hm-plugin-protocol
run: |
if curl -sf "https://crates.io/api/v1/crates/hm-plugin-protocol/$VERSION" > /dev/null 2>&1; then
echo "hm-plugin-protocol@$VERSION already published, skipping"
else
cargo publish -p hm-plugin-protocol --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty
fi
- name: Wait for crates.io index
run: sleep 30
- name: Publish hm-plugin-sdk
run: |
if curl -sf "https://crates.io/api/v1/crates/hm-plugin-sdk/$VERSION" > /dev/null 2>&1; then
echo "hm-plugin-sdk@$VERSION already published, skipping"
else
cargo publish -p hm-plugin-sdk --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty
fi
- name: Wait for crates.io index
run: sleep 30
- name: Build embedded WASM plugins
# The harmont-cli build.rs prefers crates/hm/embedded/*.wasm
# over the in-workspace cross-compile. Stage them here so the
# `cargo publish -p harmont-cli` verify-build (which runs in
# target/package/harmont-cli-<ver>/ without the sibling plugin
# crates) and any downstream `cargo install harmont-cli` both
# find the wasms already cooked. The include = [...] in
# crates/hm/Cargo.toml carries them into the tarball.
run: |
set -euo pipefail
for crate in hm-plugin-docker hm-plugin-output-human hm-plugin-output-json hm-plugin-cloud; do
cargo build --target wasm32-wasip1 -p "$crate" --release
done
mkdir -p crates/hm/embedded
for name in hm_plugin_docker hm_plugin_output_human hm_plugin_output_json hm_plugin_cloud; do
cp "target/wasm32-wasip1/release/$name.wasm" "crates/hm/embedded/$name.wasm"
done
ls -la crates/hm/embedded/
- name: Publish harmont-cli
run: |
if curl -sf "https://crates.io/api/v1/crates/harmont-cli/$VERSION" > /dev/null 2>&1; then
echo "harmont-cli@$VERSION already published, skipping"
else
cargo publish -p harmont-cli --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty
fi