#!/usr/bin/env fish
# Stage: trigger the linux-rake/macos-rake/windows-rake jobs (see
# .repomon/release.toml) by pushing the release tag to `origin`, then wait
# for each job's marker-file hand-back to land in the staging directory.
#
# repomon has no CLI to submit/await a job and no artifact-return channel of
# its own (each job's workspace is deleted right after it finishes, and only
# text logs persist) -- so the last step of each repomon job scp's a
# trivial success marker to $STAGING_DIR itself (there's no real build
# artifact to wait on here -- tracing-subscriber-init ships no binaries --
# just "did cargo rake test succeed on this platform").
#
# Also waits on audit.ok -- handed off by .repomon/audit.toml's job (a
# separate repomon workflow, also triggered by this same tag push) after
# `cargo rake audit` passes. repomon has no dependency mechanism between
# separate workflow files, so this shared staging directory is what makes a
# failing audit gate the release: if it fails, audit.toml's job stops
# before its handoff step runs, audit.ok never appears, and this poll
# eventually times out and dies instead of letting publish-crates.fish
# proceed.
#
# Runs for -rc tags too (unlike publish-crates.fish): this is exactly how
# you dry-run-verify the repomon leg end to end before cutting a real
# release.
set -l here (path dirname (status --current-filename))
source $here/lib.fish
cd (rel_repo_root)
or rel_die "not inside the tracing-subscriber-init git repo"
rel_resolve_tag
rel_require_cmd ssh
rel_require_cmd git
set -l staging_root /opt/releases/tracing-subscriber-init/staging
set -l staging_dir $staging_root/$RELEASE_TAG
test -d $staging_root
or rel_die "$staging_root does not exist -- create it on jozias@jasonozias.com first (mkdir -p $staging_root), and wire origin's post-receive hook to repomon"
mkdir -p $staging_dir
or rel_die "failed to create $staging_dir"
rel_log "pushing $RELEASE_TAG to origin to trigger repomon's tracing-subscriber-init-release and tracing-subscriber-init-audit workflows"
# Idempotent: harmless if the tag was already pushed to origin as part of
# the usual multi-remote tag push (origin/gh2/gh3).
git push origin $RELEASE_TAG
or rel_die "failed to push $RELEASE_TAG to origin"
rel_log "waiting for repomon's linux-rake/macos-rake/windows-rake jobs and the audit job to report success into $staging_dir"
rel_log "(watch progress with 'rpmt', or tail ~/.local/share/repomon/logs/tracing-subscriber-init/tracing-subscriber-init-release/ and .../tracing-subscriber-init-audit/)"
rel_wait_for_files $staging_dir linux.ok macos.ok windows.ok audit.ok 2400
or rel_die "timed out waiting for repomon jobs to report success in $staging_dir -- check the repomon daemon/runner logs (a failing cargo rake audit run stops audit.toml's job before it can hand off audit.ok)"
rel_log "all three platforms plus audit succeeded for $RELEASE_TAG"