use anyhow::Result;
use super::{GeneratedFile, Mechanism, MechanismContext, StepResult};
pub struct SetupAction;
impl Mechanism for SetupAction {
fn id(&self) -> &'static str {
"setup_action"
}
fn description(&self) -> &'static str {
"Composite GitHub Action to install the release binary"
}
fn generate(&self, ctx: &MechanismContext<'_>) -> Result<StepResult> {
let p = &ctx.config.project;
let bin = &p.binary_name;
let repo = ctx.config.github_slug();
let env = bin.to_uppercase().replace('-', "_");
let action = format!(
r#"name: Setup {bin}
description: Install {bin} from GitHub Releases (no Rust toolchain)
inputs:
version:
description: Release version without leading v (default latest)
required: false
default: ""
runs:
using: composite
steps:
- name: Install {bin}
shell: bash
env:
{env}_VERSION: ${{{{ inputs.version }}}}
{env}_REPO: {repo}
{env}_INSTALL_DIR: ${{{{ runner.temp }}}}/bin
run: |
set -euo pipefail
mkdir -p "${{{env}_INSTALL_DIR}}"
curl -fsSL "https://raw.githubusercontent.com/{repo}/main/scripts/install.sh" | sh
echo "${{{env}_INSTALL_DIR}}" >> "$GITHUB_PATH"
"{bin}" --version
"#
);
let path = format!(
"{}/setup-{bin}/action.yml",
ctx.config.paths.actions_dir.trim_end_matches('/')
);
Ok(StepResult {
files: vec![GeneratedFile {
relative_path: path.clone(),
contents: action,
executable: false,
}],
notes: vec![format!("CI: uses: {repo}/.github/actions/setup-{bin}@main")],
})
}
}