github rust 项目Travis ci配置
目录
- 复制github仓库[opt]
- rust fmt使用
- 安装
- 运行
- 配置
- 宏使用
- 与Travis ci集成
- rust clippy使用
- 类别(组)
- 安装
- 运行
- 配置
- 宏使用
- 与Travis ci集成
- travis-ci
- 简介
- .travis.yml
- 集成步骤
复制github仓库[opt]
这里我们要基于tentacle做二次开发
# clone要复制的仓库
git clone --bare https://github.com/nervosnetwork/tentacle.git
cd tentacle.git
# 提前在github上创建新的项目仓库
git push --mirror https://github.com/itling/libp2p-rust.git
rm -rf tentacle.git
git clone https://github.com/itling/libp2p-rust.git
rust fmt使用
fmt是一个根据样式规则格式化Rust代码的工具
安装
rustup component add rustfmt
运行
cargo fmt
配置
可以在项目根目录下创建一个名为rustfmt.toml
或 .rustfmt.toml
的TOML文件,规则使用variable = value的形式定义;
有哪些可使用的规则可以用rustfmt --help=config
命令查看;
可以使用rustfmt --print-config default rustfmt.toml
命令生成一个默认的配置文件
eg.
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
use_small_heuristics = "Default"
indent_style = "Block"
wrap_comments = false
format_code_in_doc_comments = false
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
merge_imports = false
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = false
fn_args_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2015"
version = "One"
inline_attribute_width = 0
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.4.12"
unstable_features = false
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Never"
report_fixme = "Never"
ignore = []
emit_mode = "Files"
make_backup = false
宏使用
- 如果你的代码不像被rustfmt格式化,可以使用 #[rustfmt::skip]
- 为防止rustfmt格式化宏或属性,请使用#[rustfmt::skip::macros(target_macro_name)] 或 #[rustfmt::skip::attributes(target_attribute_name)]
#![rustfmt::skip::attributes(custom_attribute)] #[custom_attribute(formatting , here , should , be , Skipped)]
#[rustfmt::skip::macros(html)]
fn main() {let macro_result1 = html! { <div>
Hello</div>}.to_string();
与Travis ci集成
使用–check标识,如果代码格式不正确,rustfmt将退出并显示出需要修改的代码块.
Travis设置可能看起来像这样:
language: rust
before_script:
- rustup component add rustfmt
script:
- cargo build
- cargo test
- cargo fmt -- --check
rust clippy使用
clippy有一组lints集合,用于检查你代码中错误和坏味道,帮助你改进你的Rust代码。
类别(组)
- clippy::all(默认配置,排除nursery,pedantic和cargo)
- clippy::correctness(代码完全错误或非常无用,默认情况下会导致硬错误)
- clippy::style (应该以更惯用的方式编写的代码)
- clippy::complexity (执行简单但复杂的代码)
- clippy::perf (可以以更快的方式编写的代码)
- clippy::pedantic (非常严格lints,默认情况下已禁用)
- clippy::nursery (尚未完成的新的lints,默认情况下处于关闭状态)
- clippy::cargo (对cargo manifest进行检查,默认情况下为关闭状态)
默认情况下,仅启用以下类别:
- clippy::style
- clippy::correctness
- clippy::complexity
- clippy::perf
安装
rustup component add clippy
运行
cargo clippy
自动应用修改建议,帮助你修改代码
cargo clippy --fix -Z unstable-options
配置
可以在项目根目录下创建一个名为rustfmt.toml
或 .rustfmt.toml
的TOML文件,规则使用variable = value的形式定义,所有的lint规则请参考:https://rust-lang.github.io/rust-clippy/master/index.htm。
cargo clippy
命令在执行的时候,首先会寻找工作目录中是否有.clippy.toml,如果有的话就会将其作为clippy配置,如果没有的话就会再寻找工作目录中是否有clippy.toml文件,如果还是没有的话,就会去寻找上层目录是否有.clippy.toml和clippy.toml文件。
eg.
blacklisted-names = ["toto", "tata", "titi"]
cognitive-complexity-threshold = 30
宏使用
可以在你的代码中使用clippy提供的宏,允许、警告、不允许Clippy lints,分别对应
#[allow(…)]、#[warn(…)]、#[deny(…)]。
- 全部lints只警告 (#![deny(clippy::all)])
- 可以同时使用两个lint 组 (#![deny(clippy::all)], #![deny(clippy::pedantic)])
- 部分lints(#![deny(clippy::single_match, clippy::box_vec)], etc.)
- allow/warn/deny可以修饰单个函数或模块
如果您不想在代码中使用clippy宏,则可以通过在运行期间将额外的标志传递给cargo clippy
命令来全局启用/禁用clippy,eg:
cargo clippy -- -A clippy::lint_name
cargo clippy -- -W clippy::lint_name
cargo clippy -- -W clippy::pedantic
cargo clippy -- -Aclippy::all -Wclippy::useless_format -Wclippy
::…
-W --warn 将规则改设为警告 -A --allow 将规则改设为允许 -D --deny 将规则改设为不允许
与Travis ci集成
language: rust
rust:- stable- beta
before_script:- rustup component add clippy
script:- cargo clippy# if you want the build job to fail when encountering warnings, use- cargo clippy -- -D warnings# in order to also check tests and non-default crate features, use- cargo clippy --all-targets --all-features -- -D warnings- cargo test# etc.
请注意,-D warnings
如果在代码中发现任何警告,将导致构建失败。其中包括rustc发现的警告(例如dead_code)。如果要避免这种情况,请在代码中使用#![deny(clippy::all)]
宏或在命令行中使用-D clippy::all
。
travis-ci
简介
Travis CI 是一个开源的,分布式的持续集成服务,用来构建及测试在 GitHub 托管的代码。
它提供了对多种编程语言的支持,包括 Ruby、JavaScript、Java、Scala、PHP、Haskell 和 Erlang 在内的多种语言。许多知名的开源项目使用它来在每次提交的时候进行构建测试,比如 Ruby on Rails,Ruby 和 Node.js
.travis.yml
Travis 要求项目的根目录下面,必须有一个.travis.yml文件。这是配置文件,指定了 Travis 的行为。该文件必须保存在 Github 仓库里面,一旦代码仓库有新的 Commit,Travis 就会去找这个文件,执行里面的命令。
eg.
language: rust
rust:- stable
before_script:- rustup component add rustfmt- rustup component add clippy
script:- RUSTFLAGS='-F warnings' cargo build --all- cargo build --examples --all
stages:- Check
jobs:include:- stage: Checkname: Formatscript:- cargo fmt --all -- --check
集成步骤
1、使用你的github账号授权登录https://travis-ci.com/signin
2、点击头像setting
3.点击manage repositories on Github,跳转到github授权页
4.选择需要ci的项目,请求授权
5. 授权后,可以看到当前授权的项目,点击setting 可以进入构建详情页面
6. 点击trigger build可立即触发构建
7.可以将当前的构建状态图标放到项目的readme中
github rust 项目Travis ci配置相关推荐
- 利用Travis CI 让你的github项目持续构建(Node.js为例)
Travis CI 是目前新兴的开源持续集成构建项目,它与jenkins,GO的很明显的特别在于采用yaml格式,简洁清新独树一帜.目前大多数的github项目都已经移入到Travis CI的构建队列 ...
- .NET Core+Selenium+Github+Travis CI =amp;gt; SiteHistory
前言 总是三分钟热度的我折腾了一个可以每天自动截取指定网站页面并保存到Github的项目SiteHistory,感觉挺好(每次都这样 frameborder="0" scrolli ...
- flutter ios打包_使用 Travis CI 为 Flutter 项目打包 Android/iOS 应用
Travis CI 构建 Building Flutter APKs and IPAs on Travis 这篇文章详细介绍了如何在 Travis CI 上为 Flutter 项目打包 Android ...
- gcr.io 国内源 —— 基于 Travis CI + GitHub + DockerHub + Google Cloud 实现自动定时同步 gcr.io 镜像到 DockerHub
一.背景介绍 由于国内网络原因,gcr.io 仓库里的镜像是无法直接拉取到的,这给开发工作造成了极大的不便 本文介绍一种方法能够实现自动化地定期地将 gcr.io 仓库中的镜像同步到个人 Docker ...
- 持续集成与持续部署(五)03-TravisCI——Travis CI和Docker的持续集成之所使用的基础组件、dockerfile配置、docker部署脚本
持续集成与持续部署(五)03-TravisCI--Travis CI和Docker的持续集成之所使用的基础组件.dockerfile配置.docker部署脚本 所使用的基础组件 代码托管在Github ...
- 使用Travis CI自动部署Hexo博客
自从使用GitHub Pages和Hexo来发布博客之后,不得不说方便了许多,只需要几个简单的命令博客就发布了.但在不断的使用中发现每次的发布操作也挺耗时的. 我一般的操作是将平时整理好的md文件放到 ...
- Vite(三)部署静态站点(wordpress与hugo与Vercel、CI/CD、Travis CI、GitLab CI)、环境变量与模式、服务端渲染(SSR)
Vite(三)部署静态站点(wordpress与hugo与Vercel.CI/CD.Travis CI.GitLab CI).环境变量与模式.服务端渲染(SSR) 文章目录 Vite(三)部署静态站点 ...
- 利用 Travis CI 把 Android 项目部署到 github
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 本文不涉及 CI 是什么以及优势等,不知道的还请自行 google,这里会手把手教你如何操作. 闲话少说,开始吧. 一共 ...
- github 上Go项目使用Travis CI和Docker Hub实现持续集成
介绍 在本文中,我们将介绍如何使用Github,Travis-CI和Docker Hub创建一个简单的持续集成过程. 项目 这次使用的一个项目是自己写的一个爬虫小程序(https://github.c ...
- 提高开源项目逼格-为你的github项目添加Travis CI
1.背景 每当我们浏览github开源项目的时候,比较牛的项目,往往在readme文件里,会有如下图这样的小绿标.因为博主的好奇心比较强,所以就研究了下怎么添加这个.大家也不妨动手试试! 2.步骤 ...
最新文章
- Pandas中iloc、loc、ix三者的区别
- hive python udf_python udf方法
- 安卓模拟器按键_安卓模拟机(夜神模拟器)
- 微信小程序自定义组件生命周期
- get mysql options_mysql命令的选项options
- python连接数据库设置编码_Python学习18-连接数据库
- [六字真言]1.唵.遁入佛门之异常.md
- URL different URI
- usc计算机博士游戏专业,USC工科博士专业排名,必然得仔细的看
- wifi各协议最高速率
- Linux下redis基本操作
- python能在ipad上运行吗_如何用iPad运行Python代码?
- 快速使用 Docker 部署 Spring Boot 项目
- 七月:交通车辆管理、门禁考勤,智能化升级的最优方案你get到了吗?
- linux+agent卸载_Symantec Backup Exec 2012 Agent for Linux 卸载 - 潇湘隐者
- java新手知识第二周
- 一颗璀璨的月光宝石——Lua
- php微信 开发笔记,PHP微信公众开发笔记(一)
- python多线程异步 简单小栗子(包子大战)
- “从沙子到芯片”集成电路技术介绍报告会