Skip to content

utoopack-v1.5.12

utoopack-v1.5.12 #159

Workflow file for this run

name: cargo-publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version to publish (e.g. 1.0.30)"
required: true
dry_run:
description: "Dry-run only (uncheck to actually publish)"
type: boolean
required: false
default: true
jobs:
publish:
if: github.event_name == 'workflow_dispatch' || (startsWith(github.event.release.tag_name, 'utoo-v') && github.event.release.prerelease == false)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
# Need full history to diff against the previous utoo-v* tag.
fetch-depth: 0
- name: Resolve utoo version
id: meta
env:
VERSION_INPUT: ${{ github.event.inputs.version }}
TAG_RELEASE: ${{ github.event.release.tag_name }}
run: |
if [ -n "$VERSION_INPUT" ]; then
VERSION="$VERSION_INPUT"
TAG="utoo-v$VERSION_INPUT"
else
VERSION="${TAG_RELEASE#utoo-v}"
TAG="$TAG_RELEASE"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2026-07-29
# Resolve the ruborist version for this release:
#
# • LATEST = highest version on crates.io (or empty if never published)
# • CUR = version currently in crates/ruborist/Cargo.toml
# • CHANGED = whether crates/ruborist/ diffs against the previous utoo-v* tag
#
# Decision:
# • Never published yet → publish at CUR
# • CHANGED → publish at max(CUR, LATEST + patch bump)
# • Unchanged → reuse LATEST, skip publishing
- name: Resolve ruborist version
id: rub
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
set -euo pipefail
PREV_TAG=$(git tag --list 'utoo-v*' --sort=-v:refname | grep -v "^${TAG}$" | head -n1 || true)
echo "prev_tag=$PREV_TAG"
if [ -z "$PREV_TAG" ]; then
CHANGED=true
elif git diff --quiet "$PREV_TAG..HEAD" -- crates/ruborist/; then
CHANGED=false
else
CHANGED=true
fi
CUR=$(grep -E '^version[[:space:]]*=' crates/ruborist/Cargo.toml | head -n1 | sed -E 's/.*"([^"]+)".*/\1/')
# crates.io rejects anonymous API clients without a descriptive
# User-Agent. Keep this lookup fail-closed: treating an HTTP error as
# "never published" makes the next step try to republish CUR.
CRATE_META=$(curl \
--fail-with-body \
--silent \
--show-error \
--retry 4 \
--retry-all-errors \
--retry-delay 2 \
--connect-timeout 10 \
--max-time 30 \
--user-agent "utoo-cargo-publish/1.0 (https://github.com/utooland/utoo)" \
"https://crates.io/api/v1/crates/utoo-ruborist")
LATEST=$(jq -er '.crate.max_stable_version // .crate.max_version' <<< "$CRATE_META")
echo "current_in_repo=$CUR"
echo "latest_on_crates_io=${LATEST:-<none>}"
echo "source_changed=$CHANGED"
if [ -z "$LATEST" ]; then
RESOLVED="$CUR"
PUBLISH=true
elif [ "$CHANGED" = "true" ]; then
BUMPED=$(echo "$LATEST" | awk -F. '{print $1"."$2"."($3+1)}')
RESOLVED=$(printf '%s\n%s' "$CUR" "$BUMPED" | sort -V | tail -n1)
PUBLISH=true
else
RESOLVED="$LATEST"
PUBLISH=false
fi
echo "resolved=$RESOLVED"
echo "publish=$PUBLISH"
echo "version=$RESOLVED" >> "$GITHUB_OUTPUT"
echo "publish=$PUBLISH" >> "$GITHUB_OUTPUT"
- name: Bump versions in Cargo.toml
env:
UTOO_VERSION: ${{ steps.meta.outputs.version }}
RUB_VERSION: ${{ steps.rub.outputs.version }}
run: |
set -euo pipefail
sed -i.bak "0,/^version[[:space:]]*=/{s|^version[[:space:]]*=.*|version = \"${RUB_VERSION}\"|}" crates/ruborist/Cargo.toml
sed -i.bak "0,/^version[[:space:]]*=/{s|^version[[:space:]]*=.*|version = \"${UTOO_VERSION}\"|}" crates/pm/Cargo.toml
sed -i.bak "s|^utoo-ruborist[[:space:]]*=.*|utoo-ruborist = { path = \"../ruborist\", version = \"${RUB_VERSION}\", features = [\"http-tarball\", \"native-git\"] }|" crates/pm/Cargo.toml
rm -f crates/pm/Cargo.toml.bak crates/ruborist/Cargo.toml.bak
check_version() {
local file=$1
local expected=$2
local actual
actual=$(awk -F\" '/^version[[:space:]]*=/ { print $2; exit }' "$file")
if [ "$actual" != "$expected" ]; then
echo "Failed to update $file to version $expected; found $actual" >&2
head -12 "$file" >&2
exit 1
fi
}
check_version crates/ruborist/Cargo.toml "$RUB_VERSION"
check_version crates/pm/Cargo.toml "$UTOO_VERSION"
if ! grep -Fq "version = \"${RUB_VERSION}\"" crates/pm/Cargo.toml; then
echo "Failed to update utoo-ruborist dependency to version $RUB_VERSION" >&2
grep '^utoo-ruborist' crates/pm/Cargo.toml >&2 || true
exit 1
fi
echo "----- crates/ruborist/Cargo.toml -----"
head -12 crates/ruborist/Cargo.toml
echo "----- crates/pm/Cargo.toml -----"
head -16 crates/pm/Cargo.toml
grep '^utoo-ruborist' crates/pm/Cargo.toml
# release-triggered runs always do a real publish.
# workflow_dispatch runs honor the `dry_run` input (default true).
- name: Resolve dry-run mode
id: mode
env:
DRY_RUN_INPUT: ${{ github.event.inputs.dry_run }}
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "$DRY_RUN_INPUT" != "false" ]; then
echo "flag=--dry-run" >> "$GITHUB_OUTPUT"
echo "Mode: DRY-RUN"
else
echo "flag=" >> "$GITHUB_OUTPUT"
echo "Mode: REAL PUBLISH"
fi
- name: Publish utoo-ruborist
if: steps.rub.outputs.publish == 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish -p utoo-ruborist --allow-dirty ${{ steps.mode.outputs.flag }}
- name: Skip utoo-ruborist publish
if: steps.rub.outputs.publish != 'true'
run: |
echo "ruborist source unchanged since previous release — reusing v${{ steps.rub.outputs.version }} from crates.io."
- name: Publish utoo-pm
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish -p utoo-pm --allow-dirty ${{ steps.mode.outputs.flag }}