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

ci: Add github actions for CI #3

Merged
merged 3 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [Xuanwo]
35 changes: 35 additions & 0 deletions .github/actions/check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Check'
description: 'Check will do all essential checks'
inputs:
github_token:
description: "Github Token"
required: true
runs:
using: "composite"
steps:
- uses: Swatinem/rust-cache@v1
with:
sharedKey: base-v1

- name: Format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Install cargo-audit
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-audit

- name: Audit dependencies
uses: actions-rs/cargo@v1
with:
command: audit

- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

# Maintain dependencies for rust
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "daily"
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/check
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-11
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1
- name: Build
uses: actions-rs/cargo@v1
with:
command: build

unit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-11
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: -- --nocapture
env:
RUST_LOG: DEBUG
RUST_BACKTRACE: full
1 change: 1 addition & 0 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::time::Duration;
/// Ok(())
/// }
/// ```
#[derive(Debug, Clone)]
pub struct ConstantBackoff {
delay: Duration,
max_times: Option<usize>,
Expand Down
10 changes: 7 additions & 3 deletions src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ pub struct Retry<
state: State<T, E, Fut>,
}

/// State maintains internal state of retry.
///
/// # Notes
///
/// `tokio::time::Sleep` is a very struct that occupy 640B, so we wrap it
/// into a `Pin<Box<_>>` to avoid this enum too large.
#[pin_project(project = StateProject)]
enum State<T, E, Fut: Future<Output = std::result::Result<T, E>>> {
Idle,

Polling(#[pin] Fut),
// TODO: we need to support other sleeper
Sleeping(#[pin] Pin<Box<tokio::time::Sleep>>),
Expand Down Expand Up @@ -130,7 +135,6 @@ where
match state {
StateProject::Idle => {
let fut = (this.future_fn)();
// this.state = State::Polling(fut);
this.state.set(State::Polling(fut));
continue;
}
Expand Down Expand Up @@ -167,7 +171,7 @@ mod tests {
}

#[tokio::test]
async fn test_retry_x() -> anyhow::Result<()> {
async fn test_retry() -> anyhow::Result<()> {
let result = always_error
.retry(ExponentialBackoff::default().with_min_delay(Duration::from_millis(1)))
.await;
Expand Down