Skip to content

Commit

Permalink
chore: remove timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 7, 2024
1 parent 0173ad8 commit 098b45d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 88 deletions.
30 changes: 8 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI
env:
RUSTFLAGS: -AWarnings
RUSTFLAGS: -D Warnings
on:
push:
branches:
Expand All @@ -15,29 +15,15 @@ on:
permissions:
contents: read
jobs:
stable:
name: Build
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Rust Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
- name: Run Test
run: cargo test --all-features --workspace
nightly:
name: Nightly
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Rust Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
- name: Run Fmt
run: cargo nightly fmt --all-features --workspace -- check
- name: Run Clippy
run: 'cargo +nightly clippy --all-features --workspace -- -D warnings '
toolchain: stable,nightly
- run: cargo test --all-features --workspace
- run: cargo +nightly fmt --check
- run: cargo +nightly clippy --all-features --workspace
16 changes: 0 additions & 16 deletions Cargo.lock

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

11 changes: 3 additions & 8 deletions workspace/gh-workflow-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
use std::time::Duration;

use gh_workflow::{Job, Permissions, RustFlags, Step, Toolchain, Workflow};

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

let build = Job::new("build")
let build = Job::new("Build and Test")
.add_step(Step::checkout())
.add_step(
Step::setup_rust()
.add_toolchain(Toolchain::Stable)
.add_toolchain(Toolchain::Nightly),
)
.add_step(
Step::cargo("test", vec!["--all-features", "--workspace"])
.timeout(Duration::from_secs(10)),
)
.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", "-D", "warnings"],
vec!["--all-features", "--workspace"],
));

Workflow::new("CI")
Expand Down
1 change: 0 additions & 1 deletion workspace/gh-workflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
async-trait = "0.1.83"
convert_case = "0.6.0"
derive_more = { version = "1.0.0", features = ["from"] }
derive_setters = "0.1.6"
indexmap = {version = "2.6.0", features = ["serde"]}
Expand Down
27 changes: 14 additions & 13 deletions workspace/gh-workflow/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ pub struct Target {

/// A Rust representation for the inputs of the setup-rust action.
/// More information can be found [here](https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/action.yml).
/// NOTE: The public API should be close to the original action as much as possible.
/// NOTE: The public API should be close to the original action as much as
/// possible.
#[derive(Default, Clone, Setters)]
#[setters(strip_option)]
pub struct ToolchainStep {
Expand Down Expand Up @@ -104,19 +105,19 @@ impl AddStep for ToolchainStep {
fn apply(self, job: Job) -> Job {
let mut step = Step::uses("actions-rust-lang", "setup-rust-toolchain", 1);

if !self.toolchain.is_empty() {
let toolchain = self
.toolchain
.iter()
.map(|t| match t {
Toolchain::Stable => "stable".to_string(),
Toolchain::Nightly => "nightly".to_string(),
Toolchain::Custom((major, minor, patch)) => {
format!("{}.{}.{}", major, minor, patch)
}
})
.fold("".to_string(), |acc, a| format!("{},{}", acc, a));
let toolchain = self
.toolchain
.iter()
.map(|t| match t {
Toolchain::Stable => "stable".to_string(),
Toolchain::Nightly => "nightly".to_string(),
Toolchain::Custom((major, minor, patch)) => {
format!("{}.{}.{}", major, minor, patch)
}
})
.reduce(|acc, a| format!("{},{}", acc, a));

if let Some(toolchain) = toolchain {
step = step.with(("toolchain", toolchain));
}

Expand Down
37 changes: 9 additions & 28 deletions workspace/gh-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use convert_case::{Case, Casing};
use std::fmt::Display;
use std::path::Path;

use derive_setters::Setters;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{fmt::Display, path::Path, time::Duration};

use crate::{
error::{Error, Result},
ToolchainStep,
};
use crate::error::{Error, Result};
use crate::ToolchainStep;

#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -128,11 +127,6 @@ impl Workflow {
a.apply(self)
}

pub fn timeout(mut self, duration: Duration) -> Self {
self.timeout_minutes = Some(duration.as_secs() as u32 / 60);
self
}

pub fn env<T: SetEnv<Self>>(self, env: T) -> Self {
env.apply(self)
}
Expand Down Expand Up @@ -266,7 +260,7 @@ pub struct Job {
impl Job {
pub fn new<T: ToString>(name: T) -> Self {
Self {
name: Some(name.to_string().to_case(Case::Title)),
name: Some(name.to_string()),
runs_on: Some(OneOrManyOrObject::Single("ubuntu-latest".to_string())),
..Default::default()
}
Expand All @@ -280,11 +274,6 @@ impl Job {
a.apply(self)
}

pub fn timeout(mut self, duration: Duration) -> Self {
self.timeout_minutes = Some(duration.as_secs() as u32 / 60);
self
}

pub fn env<T: SetEnv<Self>>(self, env: T) -> Self {
env.apply(self)
}
Expand Down Expand Up @@ -379,18 +368,13 @@ pub struct Step<T> {

impl<T> Step<T> {
pub fn name<S: ToString>(mut self, name: S) -> Self {
self.name = Some(name.to_string().to_case(Case::Title));
self.name = Some(name.to_string());
self
}

pub fn env<R: SetEnv<Self>>(self, env: R) -> Self {
env.apply(self)
}

pub fn timeout(mut self, duration: Duration) -> Self {
self.timeout_minutes = Some(duration.as_secs() as u32 / 60);
self
}
}

impl<T> AddStep for Step<T>
Expand Down Expand Up @@ -418,12 +402,9 @@ impl Step<Run> {
params
.iter()
.map(|a| a.to_string())
.fold("".to_string(), |mut a, b| {
a.push_str(&b);
a
})
.reduce(|a, b| { format!("{} {}", a, b) })
.unwrap_or_default()
))
.name(format!("Cargo {}", cmd.to_string()).to_case(Case::Title))
}

pub fn cargo_nightly<T: ToString, P: ToString>(cmd: T, params: Vec<P>) -> Self {
Expand Down

0 comments on commit 098b45d

Please sign in to comment.