forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add weekly cargo update workflow (foundry-rs#5497) (#6)
Co-authored-by: Enrique Ortiz <[email protected]> Co-authored-by: AA <aa@aa> Co-authored-by: evalir <[email protected]> Co-authored-by: Rahul Ravindran <[email protected]> Co-authored-by: Matt Solomon <[email protected]> Co-authored-by: DaniPopes <[email protected]> Co-authored-by: Arsenii Kulikov <[email protected]> Co-authored-by: Andrew Athan <[email protected]> Co-authored-by: Rahul Ravindran <[email protected]> Co-authored-by: grandizzy <[email protected]> Co-authored-by: Roman Krasiuk <[email protected]>
- Loading branch information
1 parent
e94f78d
commit faead4e
Showing
25 changed files
with
253 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Automatically run `cargo update` periodically | ||
|
||
name: Update Dependencies | ||
|
||
on: | ||
schedule: | ||
# Run weekly | ||
- cron: "0 0 * * SUN" | ||
workflow_dispatch: | ||
# Needed so we can run it manually | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: cargo-update | ||
TITLE: "chore(deps): weekly `cargo update`" | ||
BODY: | | ||
Automation to keep dependencies in `Cargo.lock` current. | ||
<details><summary><strong>cargo update log</strong></summary> | ||
<p> | ||
```log | ||
$cargo_update_log | ||
``` | ||
</p> | ||
</details> | ||
jobs: | ||
update: | ||
name: Update | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@nightly | ||
|
||
- name: cargo update | ||
# Remove first line that always just says "Updating crates.io index" | ||
run: cargo update --color never 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log | ||
|
||
- name: craft commit message and PR body | ||
id: msg | ||
run: | | ||
export cargo_update_log="$(cat cargo_update.log)" | ||
echo "commit_message<<EOF" >> $GITHUB_OUTPUT | ||
printf "$TITLE\n\n$cargo_update_log\n" >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
echo "body<<EOF" >> $GITHUB_OUTPUT | ||
echo "$BODY" | envsubst >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
add-paths: ./Cargo.lock | ||
commit-message: ${{ steps.msg.outputs.commit_message }} | ||
title: ${{ env.TITLE }} | ||
body: ${{ steps.msg.outputs.body }} | ||
branch: ${{ env.BRANCH }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console2} from "forge-std/Test.sol"; | ||
import {{contract_name}} from "../src/{contract_name}.sol"; | ||
|
||
contract {contract_name}Test is Test { | ||
{contract_name} public {instance_name}; | ||
|
||
function setUp() public { | ||
{instance_name} = new {contract_name}(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//! generate command | ||
use clap::{Parser, Subcommand}; | ||
use foundry_common::fs; | ||
use std::path::Path; | ||
use yansi::Paint; | ||
|
||
/// CLI arguments for `forge generate`. | ||
#[derive(Debug, Parser)] | ||
pub struct GenerateArgs { | ||
#[clap(subcommand)] | ||
pub sub: GenerateSubcommands, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum GenerateSubcommands { | ||
/// Scaffolds test file for given contract. | ||
Test(GenerateTestArgs), | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct GenerateTestArgs { | ||
/// Contract name for test generation. | ||
#[clap(long, short, value_name = "CONTRACT_NAME")] | ||
pub contract_name: String, | ||
} | ||
|
||
impl GenerateTestArgs { | ||
pub fn run(self) -> eyre::Result<()> { | ||
let contract_name = format_identifier(&self.contract_name, true); | ||
let instance_name = format_identifier(&self.contract_name, false); | ||
|
||
// Create the test file content. | ||
let test_content = include_str!("../../../../assets/generated/TestTemplate.t.sol"); | ||
let test_content = test_content | ||
.replace("{contract_name}", &contract_name) | ||
.replace("{instance_name}", &instance_name); | ||
|
||
// Create the test directory if it doesn't exist. | ||
fs::create_dir_all("test")?; | ||
|
||
// Define the test file path | ||
let test_file_path = Path::new("test").join(format!("{}.t.sol", contract_name)); | ||
|
||
// Write the test content to the test file. | ||
fs::write(&test_file_path, test_content)?; | ||
|
||
println!("{} test file: {}", Paint::green("Generated"), test_file_path.to_str().unwrap()); | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Utility function to convert an identifier to pascal or camel case. | ||
fn format_identifier(input: &str, is_pascal_case: bool) -> String { | ||
let mut result = String::new(); | ||
let mut capitalize_next = is_pascal_case; | ||
|
||
for word in input.split_whitespace() { | ||
if !word.is_empty() { | ||
let (first, rest) = word.split_at(1); | ||
let formatted_word = if capitalize_next { | ||
format!("{}{}", first.to_uppercase(), rest) | ||
} else { | ||
format!("{}{}", first.to_lowercase(), rest) | ||
}; | ||
capitalize_next = true; | ||
result.push_str(&formatted_word); | ||
} | ||
} | ||
result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.