Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: autogen CI #14

Merged
merged 45 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f224cbe
chore: autogen CI
ssddOnTop Nov 4, 2024
2428ae0
fix typo
ssddOnTop Nov 4, 2024
37309e2
--test-- avoid if condition
ssddOnTop Nov 4, 2024
eda2d4b
update checkout version
ssddOnTop Nov 4, 2024
876d31c
avoid warns
ssddOnTop Nov 4, 2024
2abf939
avoid warns
ssddOnTop Nov 4, 2024
35767a6
add newline
ssddOnTop Nov 4, 2024
6ea1ffe
update lock files
tusharmath Nov 4, 2024
552538e
update workspace
tusharmath Nov 4, 2024
b0c50ae
update workflow
tusharmath Nov 4, 2024
1f67305
introduce `one_or_many_or_kv` and `workflow_on` macros
ssddOnTop Nov 4, 2024
5e081e4
fmt
ssddOnTop Nov 4, 2024
0934267
miscellaneous
ssddOnTop Nov 4, 2024
a8a12fa
improve workflow
tusharmath Nov 5, 2024
057a5d3
fix todo in `impl IsWith for IndexMap<String, Value>`
ssddOnTop Nov 4, 2024
c3e5005
implement todos and fix tests
ssddOnTop Nov 5, 2024
db77ad8
add type safety to Step
ssddOnTop Nov 5, 2024
da25221
cleanup
ssddOnTop Nov 5, 2024
61e801e
--wip-- [skip ci]
tusharmath Nov 6, 2024
653776f
fix errors
ssddOnTop Nov 6, 2024
0dd3fd6
miscellaneous
ssddOnTop Nov 6, 2024
d8d0d5b
fix errors
ssddOnTop Nov 6, 2024
cf4c41f
refactor: move workflow logic into toolchain
tusharmath Nov 6, 2024
369d3e2
update toolchain
tusharmath Nov 6, 2024
0e0b26d
chore: update toolchain
tusharmath Nov 6, 2024
bd93bb5
update workflot
tusharmath Nov 6, 2024
b6f3cc8
chore: update toolchain
tusharmath Nov 6, 2024
14a928a
chore: update toolchain
tusharmath Nov 6, 2024
9710db5
chore: update workflow
tusharmath Nov 6, 2024
a88dc1a
rename traits
tusharmath Nov 6, 2024
e9ef35d
fix commands
tusharmath Nov 6, 2024
db2e57f
update nightly command
tusharmath Nov 6, 2024
9144919
rename files
tusharmath Nov 6, 2024
c8fc5d0
add toolchain
tusharmath Nov 6, 2024
1bc4d55
chore: update toolchain
tusharmath Nov 6, 2024
5572ce8
simplify cargo commands
tusharmath Nov 6, 2024
1b46809
impl serde for AnyStep
ssddOnTop Nov 7, 2024
b4b783f
use untagged version of serde
tusharmath Nov 7, 2024
0173ad8
implement toolchain into step
tusharmath Nov 7, 2024
098b45d
chore: remove timeout
tusharmath Nov 7, 2024
eb5a1fc
impl display for enums
ssddOnTop Nov 7, 2024
6943d0f
try: fix ci
ssddOnTop Nov 7, 2024
d985ec1
fix warns in ci
ssddOnTop Nov 7, 2024
e4a3612
push updated ci
ssddOnTop Nov 7, 2024
ec35c01
fix clippy warns
ssddOnTop Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI
env:
RUSTFLAGS: -Dwarnings
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
branches:
- main
permissions:
contents: read
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable, nightly
components: clippy, rustfmt
- run: cargo test --all-features --workspace
- run: cargo +nightly fmt --check
- run: cargo +nightly clippy --all-features --workspace
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"cSpell.words": ["Gollum", "quicktype", "rustfmt"]
"cSpell.words": [
"Awarnings",
"Gollum",
"quicktype",
"rustfmt"
]
}
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions workspace/gh-workflow-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "gh-workflow-gen"
version = "0.1.0"
edition = "2021"

[dependencies]

serde_json = "1.0.132"
indexmap = "2.6.0"
gh-workflow = { path = "../gh-workflow" }
42 changes: 42 additions & 0 deletions workspace/gh-workflow-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use gh_workflow::{Component, Job, Permissions, RustFlags, Step, Toolchain, Workflow};

fn main() {
let rust_flags = RustFlags::deny("warnings");

let build = Job::new("Build and Test")
.add_step(Step::checkout())
.add_step(
Step::setup_rust()
.add_toolchain(Toolchain::Stable)
.add_toolchain(Toolchain::Nightly)
.components(vec![Component::Clippy, Component::Rustfmt]),
)
.add_step(Step::cargo("test", vec!["--all-features", "--workspace"]))
.add_step(Step::cargo_nightly("fmt", vec!["--check"]))
.add_step(Step::cargo_nightly(
"clippy",
vec!["--all-features", "--workspace"],
));

Workflow::new("CI")
.env(rust_flags)
.permissions(Permissions::read())
.on(vec![
// TODO: enums
("push", vec![("branches", vec!["main"])]),
(
"pull_request",
vec![
("types", vec!["opened", "synchronize", "reopened"]),
("branches", vec!["main"]),
],
),
])
.add_job("build", build)
.unwrap()
.generate(format!(
"{}/../../.github/workflows/ci.yml",
env!("CARGO_MANIFEST_DIR")
))
.unwrap();
}
4 changes: 4 additions & 0 deletions workspace/gh-workflow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
pub mod error;
mod rust_flag;
mod toolchain;
pub(crate) mod workflow;

pub use rust_flag::*;
pub use toolchain::*;
pub use workflow::*;
93 changes: 93 additions & 0 deletions workspace/gh-workflow/src/rust_flag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//! A type-safe representation of the Rust toolchain.

use std::fmt::{Display, Formatter};

use crate::{Job, SetEnv, Step, Workflow};

#[derive(Clone)]
pub enum RustFlags {
Lint(String, Lint),
Combine(Box<RustFlags>, Box<RustFlags>),
}
#[derive(Clone)]
pub enum Lint {
Allow,
Warn,
Deny,
Forbid,
Codegen,
Experiment,
}

impl core::ops::Add for RustFlags {
type Output = RustFlags;

fn add(self, rhs: Self) -> Self::Output {
RustFlags::Combine(Box::new(self), Box::new(rhs))
}
}

impl RustFlags {
pub fn allow<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Allow)
}

pub fn warn<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Warn)
}

pub fn deny<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Deny)
}

pub fn forbid<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Forbid)
}

pub fn codegen<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Codegen)
}
}

impl Display for RustFlags {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
RustFlags::Lint(name, lint) => match lint {
Lint::Allow => write!(f, "-A{}", name),
Lint::Warn => write!(f, "-W{}", name),
Lint::Deny => write!(f, "-D{}", name),
Lint::Forbid => write!(f, "-F{}", name),
Lint::Codegen => write!(f, "-C{}", name),
Lint::Experiment => write!(f, "-Z{}", name),
},
RustFlags::Combine(lhs, rhs) => write!(f, "{} {}", lhs, rhs),
}
}
}

impl SetEnv<Job> for RustFlags {
fn apply(self, mut value: Job) -> Job {
let mut env = value.env.unwrap_or_default();
env.insert("RUSTFLAGS".to_string(), self.to_string());
value.env = Some(env);
value
}
}

impl SetEnv<Workflow> for RustFlags {
fn apply(self, mut value: Workflow) -> Workflow {
let mut env = value.env.unwrap_or_default();
env.insert("RUSTFLAGS".to_string(), self.to_string());
value.env = Some(env);
value
}
}

impl<T> SetEnv<Step<T>> for RustFlags {
fn apply(self, mut value: Step<T>) -> Step<T> {
let mut env = value.env.unwrap_or_default();
env.insert("RUSTFLAGS".to_string(), self.to_string());
value.env = Some(env);
value
}
}
Loading