feat(aiken-new): output a github action

- bonus: include git short sha in version

closes #515
This commit is contained in:
rvcas 2023-05-18 01:31:07 -04:00
parent 70b1911b10
commit d68d4656df
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
6 changed files with 155 additions and 18 deletions

80
Cargo.lock generated vendored
View File

@ -57,6 +57,7 @@ dependencies = [
"aiken-lsp",
"aiken-project",
"anyhow",
"built",
"clap",
"hex",
"ignore",
@ -145,7 +146,7 @@ dependencies = [
"strip-ansi-escapes",
"thiserror",
"tokio",
"toml",
"toml 0.7.3",
"uplc",
"walkdir",
"zip",
@ -368,6 +369,16 @@ dependencies = [
"serde",
]
[[package]]
name = "built"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96f9cdd34d6eb553f9ea20e5bf84abb7b13c729f113fc1d8e49dc00ad9fa8738"
dependencies = [
"cargo-lock",
"git2",
]
[[package]]
name = "bumpalo"
version = "3.12.0"
@ -407,6 +418,18 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "cargo-lock"
version = "8.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "031718ddb8f78aa5def78a09e90defe30151d1f6c672f937af4dd916429ed996"
dependencies = [
"semver",
"serde",
"toml 0.5.11",
"url",
]
[[package]]
name = "cc"
version = "1.0.79"
@ -945,6 +968,19 @@ version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
[[package]]
name = "git2"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "globset"
version = "0.4.10"
@ -1274,12 +1310,36 @@ version = "0.2.141"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
[[package]]
name = "libgit2-sys"
version = "0.14.2+1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libm"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb"
[[package]]
name = "libz-sys"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "linux-raw-sys"
version = "0.3.1"
@ -2210,6 +2270,15 @@ dependencies = [
"libc",
]
[[package]]
name = "semver"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
dependencies = [
"serde",
]
[[package]]
name = "serde"
version = "1.0.159"
@ -2628,6 +2697,15 @@ dependencies = [
"tracing",
]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.7.3"

View File

@ -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
View File

@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}

View File

@ -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");

View File

@ -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>>,

View File

@ -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()
)
}