Skip to content

Commit

Permalink
Use a faster, cached CI setup (Leafwing-Studios#333)
Browse files Browse the repository at this point in the history
* Borrow CI setup from Emergence

https://github.com/Leafwing-Studios/Emergence

* Stricter link format checking

* Fix doc links
  • Loading branch information
alice-i-cecile authored Mar 27, 2023
1 parent 97ab7ed commit 421a0b9
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 136 deletions.
107 changes: 39 additions & 68 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,79 @@ name: CI

on:
pull_request:
branches: [main]
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
build:
strategy:
matrix:
toolchain: [stable]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
check-lints:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
toolchain: stable
components: rustfmt, clippy
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
if: runner.os == 'linux'
- name: Build & run tests
run: cargo test --workspace
env:
RUSTFLAGS: "-C debuginfo=0 -D warnings"
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
- name: CI job
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- lints

ci:
check-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
if: runner.os == 'linux'
- name: CI job
- name: Build & run tests
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci
run: cargo run -p ci -- test
env:
RUSTFLAGS: "-C debuginfo=0 -D warnings"

check-markdown-links:
check-compiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: check dead links
continue-on-error: true
id: run1
uses: gaurav-nelson/github-action-markdown-link-check@d53a906aa6b22b8979d33bc86170567e619495ec
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/linters/markdown-link-check.json"
- name: Sleep for 30 seconds
if: steps.run1.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry)
continue-on-error: true
id: run2
if: steps.run1.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@d53a906aa6b22b8979d33bc86170567e619495ec
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/linters/markdown-link-check.json"
- name: Sleep for 30 seconds
if: steps.run2.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry 2)
continue-on-error: true
id: run3
if: steps.run2.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@d53a906aa6b22b8979d33bc86170567e619495ec
- uses: actions-rs/toolchain@v1
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/linters/markdown-link-check.json"
- name: set the status
if: always()
run: |
if ${{ steps.run1.outcome=='success' || steps.run2.outcome=='success' || steps.run3.outcome=='success' }}; then
echo success
else
exit 1
fi
toolchain: stable
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Check Compile
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- compile

markdownlint:
check-doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
- name: Run Markdown Lint
uses: docker://ghcr.io/github/super-linter:slim-v4
toolchain: stable
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
if: runner.os == 'linux'
- name: Build and check doc
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- doc
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: true
DEFAULT_BRANCH: main
RUSTFLAGS: "-C debuginfo=0"
2 changes: 1 addition & 1 deletion examples/virtual_dpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn move_player(query: Query<&ActionState<Action>, With<Player>>) {
let action_state = query.single();
// If any button in a virtual direction pad is pressed, then the action state is "pressed"
if action_state.pressed(Action::Move) {
// Virtual direction pads are one of the types which return an AxisPair. The values will be
// Virtual direction pads are one of the types which return a DualAxis. The values will be
// represented as `-1.0`, `0.0`, or `1.0` depending on the combination of buttons pressed.
let axis_pair = action_state.axis_pair(Action::Move).unwrap();
println!("Move:");
Expand Down
2 changes: 1 addition & 1 deletion macros/src/actionlike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::{Data, DeriveInput, Ident};

/// This approach and implementation is inspired by the `strum` crate,
/// Copyright (c) 2019 Peter Glotfelty
/// available under the MIT License at https://github.com/Peternator7/strum
/// available under the MIT License at <https://github.com/Peternator7/strum>
pub(crate) fn actionlike_inner(ast: &DeriveInput) -> TokenStream {
// Splitting the abstract syntax tree
Expand Down
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Derives the [`Actionlike`] trait
//
//! This derive macro was inspired by the `strum` crate's `EnumIter` macro.
//! Original source: https://github.com/Peternator7/strum,
//! Original source: <https://github.com/Peternator7/strum>,
//! Copyright (c) 2019 Peter Glotfelty under the MIT License
extern crate proc_macro;
Expand Down
14 changes: 6 additions & 8 deletions src/action_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ pub struct ActionData {
pub state: ButtonState,
/// The "value" of the binding that triggered the action.
///
/// See [`ActionState::action_value()`] for more details.
/// See [`ActionState::value`] for more details.
///
/// **Warning:** this value may not be bounded as you might expect.
/// Consider clamping this to account for multiple triggering inputs.
pub value: f32,
/// The [`AxisPair`] of the binding that triggered the action.
///
/// See [`ActionState::action_axis_pair()`] for more details.
/// The [`DualAxisData`] of the binding that triggered the action.
pub axis_pair: Option<DualAxisData>,
/// When was the button pressed / released, and how long has it been held for?
pub timing: Timing,
Expand Down Expand Up @@ -233,7 +231,7 @@ impl<A: Actionlike> ActionState<A> {
/// triggers which may be tracked as buttons or axes. Examples of these include the Xbox LT/RT
/// triggers and the Playstation L2/R2 triggers. See also the `axis_inputs` example in the
/// repository.
/// - Dual axis inputs will return the magnitude of its [`AxisPair`] and will be in the range
/// - Dual axis inputs will return the magnitude of its [`DualAxisData`] and will be in the range
/// `0.0..=1.0`.
/// - Chord inputs will return the value of its first input.
///
Expand All @@ -256,8 +254,8 @@ impl<A: Actionlike> ActionState<A> {

/// Get the [`DualAxisData`] from the binding that triggered the corresponding `action`.
///
/// Only certain events such as [`VirtualDPad`][crate::user_input::VirtualDPad] and
/// [`DualAxis`][crate::user_input::DualAxis] provide an [`DualAxisData`], and this
/// Only certain events such as [`VirtualDPad`][crate::axislike::VirtualDPad] and
/// [`DualAxis`][crate::axislike::DualAxis] provide an [`DualAxisData`], and this
/// will return [`None`] for other events.
///
/// Chord inputs will return the [`DualAxisData`] of it's first input.
Expand Down Expand Up @@ -562,7 +560,7 @@ pub struct ActionStateDriver<A: Actionlike> {
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Reflect, FromReflect)]
pub struct Timing {
/// The [`Instant`] at which the button was pressed or released
/// Recorded as the [`Time`](bevy::core::Time) at the start of the tick after the state last changed.
/// Recorded as the [`Time`](bevy::time::Time) at the start of the tick after the state last changed.
/// If this is none, [`Timing::tick`] has not been called yet.
#[serde(skip)]
pub instant_started: Option<Instant>,
Expand Down
22 changes: 11 additions & 11 deletions src/axislike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl SingleAxis {
/// Creates a [`SingleAxis`] with the specified `axis_type` and `value`.
///
/// All thresholds are set to 0.0.
/// Primarily useful for [input mocking](crate::MockInput).
/// Primarily useful for [input mocking](crate::input_mocking).
#[must_use]
pub fn from_value(axis_type: impl Into<AxisType>, value: f32) -> SingleAxis {
SingleAxis {
Expand Down Expand Up @@ -157,8 +157,8 @@ impl std::hash::Hash for SingleAxis {
///
/// These can be stored in a [`VirtualDPad`], which is itself stored in an [`InputKind`] for consumption.
///
/// This input will generate [`AxisPair`] can be read with
/// [`ActionState::action_axis_pair()`][crate::ActionState::action_axis_pair()].
/// This input will generate a [`DualAxis`] which can be read with
/// [`ActionState::axis_pair`][crate::action_state::ActionState::axis_pair].
///
/// # Warning
///
Expand Down Expand Up @@ -193,7 +193,7 @@ impl DualAxis {
/// Creates a [`SingleAxis`] with the specified `axis_type` and `value`.
///
/// All thresholds are set to 0.0.
/// Primarily useful for [input mocking](crate::MockInput).
/// Primarily useful for [input mocking](crate::input_mocking).
#[must_use]
pub fn from_value(
x_axis_type: impl Into<AxisType>,
Expand Down Expand Up @@ -253,7 +253,7 @@ impl DualAxis {
}

#[allow(clippy::doc_markdown)] // False alarm because it thinks DPad is an un-quoted item
/// A virtual DPad that you can get an [`AxisPair`] from
/// A virtual DPad that you can get an [`DualAxis`] from.
///
/// Typically, you don't want to store a [`DualAxis`] in this type,
/// even though it can be stored as an [`InputKind`].
Expand Down Expand Up @@ -372,15 +372,15 @@ impl VirtualAxis {
}
}

/// Generates a [`VirtualDAxis`] corresponding to the `AD` keyboard keycodes.
/// Generates a [`VirtualAxis`] corresponding to the `AD` keyboard keycodes.
pub fn ad() -> VirtualAxis {
VirtualAxis {
negative: InputKind::Keyboard(KeyCode::A),
positive: InputKind::Keyboard(KeyCode::D),
}
}

/// Generates a [`VirtualDAxis`] corresponding to the `WS` keyboard keycodes.
/// Generates a [`VirtualAxis`] corresponding to the `WS` keyboard keycodes.
pub fn ws() -> VirtualAxis {
VirtualAxis {
negative: InputKind::Keyboard(KeyCode::S),
Expand Down Expand Up @@ -498,27 +498,27 @@ pub struct DualAxisData {

// Constructors
impl DualAxisData {
/// Creates a new [`AxisPair`] from the provided (x,y) coordinates
/// Creates a new [`DualAxisData`] from the provided (x,y) coordinates
pub fn new(x: f32, y: f32) -> DualAxisData {
DualAxisData {
xy: Vec2::new(x, y),
}
}

/// Creates a new [`AxisPair`] directly from a [`Vec2`]
/// Creates a new [`DualAxisData`] directly from a [`Vec2`]
pub fn from_xy(xy: Vec2) -> DualAxisData {
DualAxisData { xy }
}

/// Merge the state of this [`AxisPair`] with another.
/// Merge the state of this [`DualAxisData`] with another.
///
/// This is useful if you have multiple sticks bound to the same game action,
/// and you want to get their combined position.
///
/// # Warning
///
/// This method can result in values with a greater maximum magnitude than expected!
/// Use [`AxisPair::clamp_length`] to limit the resulting direction.
/// Use [`DualAxisData::clamp_length`] to limit the resulting direction.
pub fn merged_with(&self, other: DualAxisData) -> DualAxisData {
DualAxisData::from_xy(self.xy() + other.xy())
}
Expand Down
6 changes: 3 additions & 3 deletions src/buttonlike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy::reflect::{FromReflect, Reflect};
use serde::{Deserialize, Serialize};

/// The current state of a particular button,
/// usually corresponding to a single [`Actionlike`] action.
/// usually corresponding to a single [`Actionlike`](crate::Actionlike) action.
///
/// By default, buttons are [`ButtonState::Released`].
#[derive(
Expand Down Expand Up @@ -71,14 +71,14 @@ impl ButtonState {
*self == ButtonState::Released || *self == ButtonState::JustReleased
}

/// Was the button pressed since the last time [`ActionState::update`] was called?
/// Was the button pressed since the last time [`ActionState::update`](crate::action_state::ActionState::update) was called?
#[inline]
#[must_use]
pub fn just_pressed(&self) -> bool {
*self == ButtonState::JustPressed
}

/// Was the button released since the last time [`ActionState::update`] was called?
/// Was the button released since the last time [`ActionState::update`](crate::action_state::ActionState::update) was called?
#[inline]
#[must_use]
pub fn just_released(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use derive_more::{Display, Error};
/// The supplied vector-like struct was too close to zero to be converted into a rotation-like type
///
/// This error is produced when attempting to convert into a rotation-like type
/// such as a [`Rotation`] or [`Quat`](bevy::math::Quat) from a vector-like type
/// such as a [`Vec2`].
/// such as a [`Rotation`](crate::orientation::Rotation) or [`Quat`](bevy::math::Quat) from a vector-like type
/// such as a [`Vec2`](bevy::math::Vec2).
///
/// In almost all cases, the correct way to handle this error is to simply not change the rotation.
#[derive(Debug, Clone, Copy, Error, Display, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion src/input_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<A: Actionlike> InputMap<A> {

/// Insert a mapping between the simultaneous combination of `buttons` and the `action` provided
///
/// Any iterator that can be converted into a [`Button`] can be supplied, but will be converted into a [`PetitSet`] for storage and use.
/// Any iterator that can be converted into a [`InputKind`] can be supplied, but will be converted into a [`PetitSet`] for storage and use.
/// Chords can also be added with the [insert](Self::insert) method, if the [`UserInput::Chord`] variant is constructed explicitly.
///
/// When working with keyboard modifier keys, consider using the `insert_modified` method instead.
Expand Down
4 changes: 2 additions & 2 deletions src/input_mocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use bevy::window::CursorMoved;
pub trait MockInput {
/// Send the specified `user_input` directly
///
/// These are sent as the raw input events, and do not set the value of [`Input`] or [`Axis`] directly.
/// These are sent as the raw input events, and do not set the value of [`Input`] or [`Axis`](bevy::input::Axis) directly.
/// Note that inputs will continue to be pressed until explicitly released or [`MockInput::reset_inputs`] is called.
///
/// To send specific values for axislike inputs, set their `value` field.
Expand All @@ -87,7 +87,7 @@ pub trait MockInput {
///
/// You *must* call `app.update()` at least once after sending input
/// with `InputPlugin` included in your plugin set
/// for the raw input events to be processed into [`Input`] and [`Axis`] data.
/// for the raw input events to be processed into [`Input`] and [`Axis`](bevy::input::Axis) data.
fn send_input(&mut self, input: impl Into<UserInput>);

/// Send the specified `user_input` directly, using the specified gamepad
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub trait Actionlike: Send + Sync + Clone + 'static {

/// An iterator of [`Actionlike`] actions
///
/// Created by calling [`Actionlike::iter`].
/// Created by calling [`Actionlike::variants()`].
#[derive(Debug, Clone)]
pub struct ActionIter<A: Actionlike> {
index: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/orientation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mod orientation_trait {
}

mod rotation_direction {
/// A direction that a [`Rotation`] can be applied in
/// A direction that a [`Rotation`](crate::orientation::Rotation) can be applied in.
///
/// # Example
/// ```rust
Expand Down Expand Up @@ -477,7 +477,7 @@ mod direction {

impl Default for Direction {
/// [`Direction::EAST`] is the default direction,
/// as it is consistent with the default [`Rotation`]
/// as it is consistent with the default [`Rotation`](crate::orientation::Rotation)
fn default() -> Direction {
Direction::EAST
}
Expand Down
Loading

0 comments on commit 421a0b9

Please sign in to comment.