Skip to content

Commit

Permalink
ci: Add github actions for CI (#3)
Browse files Browse the repository at this point in the history
* ci: Add github actions for CI

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix CI

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix docs

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Apr 14, 2022
1 parent bb7c203 commit 3452129
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 3 deletions.
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

0 comments on commit 3452129

Please sign in to comment.