Skip to content

Commit

Permalink
chore: add autofix.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Dec 11, 2024
1 parent 2b17453 commit 7f7c118
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 40 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -------------------------------------------------------------------
# ------------------------------- WARNING ---------------------------
# -------------------------------------------------------------------
#
# This file was automatically generated by gh-workflows using the
# gh-workflow-gen bin. You should add and commit this file to your
# git repository. **DO NOT EDIT THIS FILE BY HAND!** Any manual changes
# will be lost if the file is regenerated.
#
# To make modifications, update your `build.rs` configuration to adjust
# the workflow description as needed, then regenerate this file to apply
# those changes.
#
# -------------------------------------------------------------------
# ----------------------------- END WARNING -------------------------
# -------------------------------------------------------------------

name: autofix.ci
env:
RUSTFLAGS: -Dwarnings
on:
pull_request:
types:
- opened
- synchronize
- reopened
branches:
- main
push:
branches:
- main
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Rust Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: clippy, rustfmt
- name: Cargo Fmt
run: cargo +nightly fmt --all
- name: Cargo Clippy
run: cargo +nightly clippy --fix --allow-dirty --all-features --workspace -- -D warnings
- uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ jobs:
toolchain: nightly
components: clippy, rustfmt
- name: Cargo Fmt
run: cargo +nightly fmt --all
run: cargo +nightly fmt --all --check
- name: Cargo Clippy
run: cargo +nightly clippy --fix --allow-dirty --all-features --workspace -- -D warnings
- uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c
run: cargo +nightly clippy --all-features --workspace -- -D warnings
release:
needs:
- build
Expand All @@ -83,12 +82,15 @@ jobs:
uses: release-plz/[email protected]
with:
command: release
concurrency:
group: release-${{github.ref}}
cancel-in-progress: false
release-pr:
needs:
- build
- lint
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
name: Release PR
name: Release Pr
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/gh-workflow-tailcall/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ keywords = ["github", "actions", "workflow", "generator"]
[dependencies]
derive_setters = { version = "0.1.6" }
gh-workflow = { path = "../gh-workflow", version = "0.5.5" }
heck = "0.5.0"

[dev-dependencies]
insta = "1.40.0"
Expand Down
73 changes: 37 additions & 36 deletions crates/gh-workflow-tailcall/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use ctx::Context;
use derive_setters::Setters;
use generate::Generate;
use gh_workflow::error::Result;
use gh_workflow::{Workflow as GHWorkflow, *};
use heck::ToTitleCase;
use release_plz::{Command, Release};
use toolchain::Toolchain;

Expand Down Expand Up @@ -43,56 +45,61 @@ impl Default for Workflow {
impl Workflow {
/// Generates and tests the workflow file.
pub fn generate(self) -> Result<()> {
let workflow: GHWorkflow = self.into();
workflow.generate()
self.to_ci_workflow().generate()?;
Generate::new(self.to_autofix_workflow())
.name("autofix.yml")
.generate()?;
Ok(())
}

/// Converts the workflow into a Github workflow.
pub fn to_github_workflow(&self) -> GHWorkflow {
fn to_autofix_workflow(&self) -> GHWorkflow {
GHWorkflow::new("autofix.ci")
.add_env(self.workflow_flags())
.on(self.workflow_event())
.add_job("lint", self.lint_job(true))
}

/// Converts the workflow into a Github workflow.
fn to_ci_workflow(&self) -> GHWorkflow {
GHWorkflow::new(self.name.clone())
.add_env(self.workflow_flags())
.on(self.workflow_event())
// TODO: adding build and lint should not be required
.add_job("build", self.test_job())
.add_job("lint", self.lint_job())
.add_job_when(self.auto_release, "release", self.release_job())
.add_job_when(self.auto_release, "release-pr", self.release_pr_job())
.add_job("lint", self.lint_job(false))
.add_job_when(
self.auto_release,
"release",
self.release_job(Command::Release),
)
.add_job_when(
self.auto_release,
"release-pr",
self.release_job(Command::ReleasePR),
)
}

fn release_pr_job(&self) -> Job {
Job::new("Release PR")
.cond(self.workflow_cond())
fn release_job(&self, cmd: Command) -> Job {
Job::new(cmd.to_string().to_title_case())
.concurrency(
Concurrency::new(Expression::new("release-${{github.ref}}"))
.cancel_in_progress(false),
)
.add_needs(self.test_job())
.add_needs(self.lint_job())
.add_env(Env::github())
.add_env(Env::new(
"CARGO_REGISTRY_TOKEN",
"${{ secrets.CARGO_REGISTRY_TOKEN }}",
))
.permissions(self.write_permissions())
.add_step(Step::checkout())
.add_step(Release::default().command(Command::ReleasePR))
}

fn release_job(&self) -> Job {
Job::new("Release")
.cond(self.workflow_cond())
.add_needs(self.test_job())
.add_needs(self.lint_job())
.add_needs(self.lint_job(false))
.add_env(Env::github())
.add_env(Env::new(
"CARGO_REGISTRY_TOKEN",
"${{ secrets.CARGO_REGISTRY_TOKEN }}",
))
.permissions(self.write_permissions())
.add_step(Step::checkout())
.add_step(Release::default().command(Command::Release))
.add_step(Release::default().command(cmd))
}

fn lint_job(&self) -> Job {
fn lint_job(&self, auto_fix: bool) -> Job {
Job::new("Lint")
.permissions(Permissions::default().contents(Level::Read))
.add_step(Step::checkout())
Expand All @@ -102,18 +109,18 @@ impl Workflow {
.name("Cargo Fmt")
.nightly()
.add_args("--all")
.add_args_when(!self.auto_fix, "--check"),
.add_args_when(!auto_fix, "--check"),
)
.add_step(
Cargo::new("clippy")
.name("Cargo Clippy")
.nightly()
.add_args_when(self.auto_fix, "--fix")
.add_args_when(self.auto_fix, "--allow-dirty")
.add_args_when(auto_fix, "--fix")
.add_args_when(auto_fix, "--allow-dirty")
.add_args("--all-features --workspace -- -D warnings"),
)
.add_step_when(
self.auto_fix,
auto_fix,
Step::uses(
"autofix-ci",
"action",
Expand Down Expand Up @@ -169,9 +176,3 @@ impl Workflow {
RustFlags::deny("warnings")
}
}

impl From<Workflow> for GHWorkflow {
fn from(value: Workflow) -> Self {
value.to_github_workflow()
}
}

0 comments on commit 7f7c118

Please sign in to comment.