feat(aiken-new): output a github action
- bonus: include git short sha in version closes #515
This commit is contained in:
@@ -8,10 +8,11 @@ homepage = "https://github.com/aiken-lang/aiken"
|
||||
license = "Apache-2.0"
|
||||
authors = ["Lucas Rosa <x@rvcas.dev>", "Kasey White <kwhitemsg@gmail.com>", "KtorZ <matthias.benkort@gmail.com>"]
|
||||
rust-version = "1.66.1"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.69"
|
||||
clap = { version = "4.1.8", features = ["derive", "wrap_help", "unicode"] }
|
||||
clap = { version = "4.1.8", features = ["derive", "wrap_help", "unicode", "string"] }
|
||||
hex = "0.4.3"
|
||||
ignore = "0.4.20"
|
||||
indoc = "2.0"
|
||||
@@ -30,3 +31,6 @@ aiken-lang = { path = "../aiken-lang", version = "1.0.6-alpha" }
|
||||
aiken-lsp = { path = "../aiken-lsp", version = "1.0.6-alpha" }
|
||||
aiken-project = { path = '../aiken-project', version = "1.0.6-alpha" }
|
||||
uplc = { path = '../uplc', version = "1.0.6-alpha" }
|
||||
|
||||
[build-dependencies]
|
||||
built = { version = "0.6.0", features = ["git2"] }
|
||||
|
||||
3
crates/aiken/build.rs
Normal file
3
crates/aiken/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
built::write_built_file().expect("Failed to acquire build-time information");
|
||||
}
|
||||
@@ -11,6 +11,8 @@ use std::{
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use crate::built_info;
|
||||
|
||||
#[derive(clap::Args)]
|
||||
/// Create a new Aiken project
|
||||
pub struct Args {
|
||||
@@ -49,6 +51,8 @@ fn create_project(args: Args, package_name: &PackageName) -> miette::Result<()>
|
||||
.save(&root)
|
||||
.into_diagnostic()?;
|
||||
|
||||
create_github_action(&root)?;
|
||||
|
||||
gitignore(&root)?;
|
||||
|
||||
Ok(())
|
||||
@@ -82,16 +86,18 @@ fn print_success_message(package_name: &PackageName) {
|
||||
}
|
||||
|
||||
fn create_lib_folder(root: &Path, package_name: &PackageName) -> miette::Result<()> {
|
||||
let lib = root.join("lib");
|
||||
fs::create_dir_all(&lib).into_diagnostic()?;
|
||||
let nested_path = lib.join(&package_name.repo);
|
||||
let nested_path = root.join("lib").join(&package_name.repo);
|
||||
|
||||
fs::create_dir_all(nested_path).into_diagnostic()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_validators_folder(root: &Path) -> miette::Result<()> {
|
||||
let validators = root.join("validators");
|
||||
|
||||
fs::create_dir_all(validators).into_diagnostic()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -114,13 +120,6 @@ fn readme(root: &Path, project_name: &str) -> miette::Result<()> {
|
||||
}}
|
||||
```
|
||||
|
||||
Validators are named after their purpose, so one of:
|
||||
|
||||
- `spent`
|
||||
- `mint`
|
||||
- `withdraw`
|
||||
- `publish`
|
||||
|
||||
## Building
|
||||
|
||||
```sh
|
||||
@@ -168,6 +167,44 @@ fn readme(root: &Path, project_name: &str) -> miette::Result<()> {
|
||||
).into_diagnostic()
|
||||
}
|
||||
|
||||
fn create_github_action(root: &Path) -> miette::Result<()> {
|
||||
let workflows = root.join(".github").join("workflows");
|
||||
|
||||
fs::create_dir_all(&workflows).into_diagnostic()?;
|
||||
|
||||
fs::write(
|
||||
workflows.join("tests.yml"),
|
||||
formatdoc! {
|
||||
r#"
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: aiken-lang/setup-aiken@v0.1.0
|
||||
with:
|
||||
version: v{version}
|
||||
|
||||
- run: aiken fmt --check
|
||||
- run: aiken check
|
||||
- run: aiken build
|
||||
"#,
|
||||
version = built_info::PKG_VERSION,
|
||||
},
|
||||
)
|
||||
.into_diagnostic()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn gitignore(root: &Path) -> miette::Result<()> {
|
||||
let gitignore_path = root.join(".gitignore");
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ use uplc::machine::cost_model::ExBudget;
|
||||
|
||||
pub mod cmd;
|
||||
|
||||
pub mod built_info {
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
}
|
||||
|
||||
pub fn with_project<A>(directory: Option<PathBuf>, mut action: A) -> miette::Result<()>
|
||||
where
|
||||
A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<aiken_project::error::Error>>,
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
use aiken::cmd::{
|
||||
blueprint::{self, address},
|
||||
build, check, docs, fmt, lsp, new,
|
||||
packages::{self, add},
|
||||
tx, uplc,
|
||||
use aiken::{
|
||||
built_info,
|
||||
cmd::{
|
||||
blueprint::{self, address},
|
||||
build, check, docs, fmt, lsp, new,
|
||||
packages::{self, add},
|
||||
tx, uplc,
|
||||
},
|
||||
};
|
||||
use clap::Parser;
|
||||
|
||||
/// Aiken: a smart-contract language and toolchain for Cardano
|
||||
#[derive(Parser)]
|
||||
#[clap(version, about, long_about = None)]
|
||||
#[clap(version = version(), about, long_about = None)]
|
||||
#[clap(propagate_version = true)]
|
||||
pub enum Cmd {
|
||||
New(new::Args),
|
||||
@@ -58,3 +61,11 @@ fn main() -> miette::Result<()> {
|
||||
Cmd::Uplc(sub_cmd) => uplc::exec(sub_cmd),
|
||||
}
|
||||
}
|
||||
|
||||
fn version() -> String {
|
||||
format!(
|
||||
"v{} {}",
|
||||
built_info::PKG_VERSION,
|
||||
built_info::GIT_COMMIT_HASH_SHORT.unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user