mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 07:17:27 +00:00
[CI] Improvement and fixes (#161)
* protocols: Fix building without the "games" feature * crate/lib: Add required features for examples This prevents cargo from running the examples if the required features aren't enabled. * ci: Run if ANY Cargo.toml files are changed * ci: Make sure to run unit tests * ci: Separate checks for library and CLI * ci: Add slightly better comments * ci: Only run deeper tests for CLI or LIB when their files were changed * ci: Improve act arguments for testing actions locally * ci: Fix pre-commit not running tests * ci: Only update shared cache after the initial build * ci: Make sure that rustup downloads get cached * tidy: Clean up file formatting * ci: Fix issue with audit
This commit is contained in:
parent
0c7dbe76d7
commit
b3a29b15b1
7 changed files with 123 additions and 15 deletions
3
.actrc
3
.actrc
|
|
@ -3,3 +3,6 @@
|
||||||
|
|
||||||
# Swap docker image for the one containing the rust toolchain
|
# Swap docker image for the one containing the rust toolchain
|
||||||
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest
|
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest
|
||||||
|
|
||||||
|
# Load custom event
|
||||||
|
-e .github/.act-event.json
|
||||||
|
|
|
||||||
6
.github/.act-event.json
vendored
Normal file
6
.github/.act-event.json
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"act": true,
|
||||||
|
"repository": {
|
||||||
|
"default_branch": "main"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
.github/workflows/audit.yml
vendored
1
.github/workflows/audit.yml
vendored
|
|
@ -13,4 +13,3 @@ jobs:
|
||||||
- uses: rustsec/audit-check@v1.4.1
|
- uses: rustsec/audit-check@v1.4.1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
if: ${{ !env.ACT }} # skip during local actions testing
|
|
||||||
|
|
|
||||||
93
.github/workflows/ci.yml
vendored
93
.github/workflows/ci.yml
vendored
|
|
@ -6,14 +6,14 @@ on:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
paths:
|
paths:
|
||||||
- "**.rs" # Any rust file
|
- "**.rs" # Any rust file
|
||||||
- "Cargo.toml"
|
- "**/Cargo.toml" # Any Cargo.toml
|
||||||
- ".rustfmt.toml"
|
- ".rustfmt.toml"
|
||||||
- ".github/workflows/ci.yml" # This action
|
- ".github/workflows/ci.yml" # This action
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
paths:
|
paths:
|
||||||
- "**.rs" # Any rust file
|
- "**.rs" # Any rust file
|
||||||
- "Cargo.toml"
|
- "**/Cargo.toml" # Any Cargo.toml
|
||||||
- ".rustfmt.toml"
|
- ".rustfmt.toml"
|
||||||
- ".github/workflows/ci.yml" # This action
|
- ".github/workflows/ci.yml" # This action
|
||||||
|
|
||||||
|
|
@ -21,9 +21,13 @@ env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
# First check that we can build EVERYTHING and that tests pass
|
||||||
build_first:
|
build_first:
|
||||||
name: "Build, check, and test with all features"
|
name: "Build, check, and test with all features"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
cli: ${{ steps.filter.outputs.cli }}
|
||||||
|
lib: ${{ steps.filter.outputs.lib }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
@ -33,10 +37,23 @@ jobs:
|
||||||
- name: Run Build
|
- name: Run Build
|
||||||
run: cargo check --verbose --workspace --bins --lib --examples --all-features
|
run: cargo check --verbose --workspace --bins --lib --examples --all-features
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: cargo test --verbose --workspace --bins --lib --examples --all-features
|
run: cargo test --verbose --workspace --bins --lib --examples --tests --all-features
|
||||||
build:
|
# Check what paths were modified so we only run the required tests
|
||||||
|
- uses: dorny/paths-filter@v2
|
||||||
|
id: filter
|
||||||
|
with:
|
||||||
|
filters: |
|
||||||
|
cli:
|
||||||
|
- 'crates/cli/**'
|
||||||
|
lib:
|
||||||
|
- 'crates/lib/**'
|
||||||
|
|
||||||
|
# If we were able to build then test different feature combinations compile with the library
|
||||||
|
build_lib:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [ "build_first" ]
|
needs: [ "build_first" ]
|
||||||
|
# Only run if library files were modified
|
||||||
|
if: ${{ needs.build_first.outputs.lib == 'true' }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -53,21 +70,61 @@ jobs:
|
||||||
build_name: "Just Game definitions"
|
build_name: "Just Game definitions"
|
||||||
- build_type: "--no-default-features --features serde"
|
- build_type: "--no-default-features --features serde"
|
||||||
build_name: "Just serde"
|
build_name: "Just serde"
|
||||||
name: "Build ${{ matrix.build_name }}"
|
name: "Build library ${{ matrix.build_name }}"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
shared-key: "cargo-deps"
|
shared-key: "cargo-deps"
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
|
save-if: false
|
||||||
- name: Run Build
|
- name: Run Build
|
||||||
run: cargo check --workspace --verbose --bins --lib ${{ matrix.build_type }}
|
run: cargo check -p gamedig --verbose --lib --examples --tests ${{ matrix.build_type }}
|
||||||
build_msrv:
|
|
||||||
name: "Build using MSRV (lib only)"
|
# If we were able to build then test different feature combinations compile with the CLI
|
||||||
|
build_cli:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: [ "build_first" ]
|
||||||
|
# Only run if CLI files were modified
|
||||||
|
if: ${{ needs.build_first.outputs.cli == 'true' }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- build_type: ""
|
||||||
|
build_name: "Default"
|
||||||
|
- build_type: "--no-default-features"
|
||||||
|
build_name: "No features"
|
||||||
|
name: "Build CLI ${{ matrix.build_name }}"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: "cargo-deps"
|
||||||
|
cache-targets: false
|
||||||
|
save-if: false
|
||||||
|
- name: Run Build
|
||||||
|
run: cargo check -p gamedig-cli --verbose --bins --examples --tests ${{ matrix.build_type }}
|
||||||
|
|
||||||
|
# If we were able to build then test the MSRV compiles (for the libary as not enforced for CLI)
|
||||||
|
build_msrv:
|
||||||
|
name: "Build using MSRV (lib only)"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [ "build_first" ]
|
||||||
|
# Only run if library files were modified
|
||||||
|
if: ${{ needs.build_first.outputs.lib == 'true' }}
|
||||||
|
# Unfortunate hard-coding of rustup directory so that rust-cache caches it
|
||||||
|
env:
|
||||||
|
RUSTUP_HOME: /home/runner/.rustup
|
||||||
|
steps:
|
||||||
|
# Act's rust runner has rustup in a different place
|
||||||
|
- if: ${{ env.ACT }}
|
||||||
|
run: mkdir -p /home/runner && ln -s /usr/share/rust/.rustup /home/runner/.rustup
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
cache-targets: false
|
||||||
|
cache-directories: ${{ env.RUSTUP_HOME }}/toolchains
|
||||||
- name: Install MSRV
|
- name: Install MSRV
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -75,14 +132,22 @@ jobs:
|
||||||
override: true
|
override: true
|
||||||
- name: Run MSRV
|
- name: Run MSRV
|
||||||
run: cargo check -p gamedig
|
run: cargo check -p gamedig
|
||||||
|
# Check the code is formatted properly
|
||||||
formatting:
|
formatting:
|
||||||
name: "Check code formatting"
|
name: "Check code formatting"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
# Unfortunate hard-coding of rustup directory so that rust-cache caches it
|
||||||
|
env:
|
||||||
|
RUSTUP_HOME: /home/runner/.rustup
|
||||||
steps:
|
steps:
|
||||||
|
# Act's rust runner has rustup in a different place
|
||||||
|
- if: ${{ env.ACT }}
|
||||||
|
run: mkdir -p /home/runner && ln -s /usr/share/rust/.rustup /home/runner/.rustup
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
|
cache-directories: ${{ env.RUSTUP_HOME }}/toolchains
|
||||||
- name: Install Formatting nightly
|
- name: Install Formatting nightly
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -91,6 +156,8 @@ jobs:
|
||||||
override: true
|
override: true
|
||||||
- name: Run Formatting check
|
- name: Run Formatting check
|
||||||
run: cargo fmt --check --verbose
|
run: cargo fmt --check --verbose
|
||||||
|
|
||||||
|
# If we were able to build then lint the codebase with clippy
|
||||||
clippy:
|
clippy:
|
||||||
name: "Run clippy tests"
|
name: "Run clippy tests"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -101,15 +168,20 @@ jobs:
|
||||||
with:
|
with:
|
||||||
shared-key: "cargo-deps"
|
shared-key: "cargo-deps"
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
|
save-if: false
|
||||||
|
# Run github actions version of clippy that adds annotations
|
||||||
- name: Run Clippy
|
- name: Run Clippy
|
||||||
uses: actions-rs/clippy-check@v1
|
uses: actions-rs/clippy-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --workspace --bins --lib --examples --all-features
|
args: --workspace --bins --lib --examples --tests --all-features
|
||||||
if: ${{ !env.ACT }} # skip during local actions testing
|
if: ${{ !env.ACT }} # skip during local actions testing
|
||||||
|
# Run clippy binary
|
||||||
- name: Run clippy (local)
|
- name: Run clippy (local)
|
||||||
run: cargo clippy --workspace --verbose --bins --lib --examples --all-features
|
run: cargo clippy --verbose --workspace --bins --lib --examples --tests --all-features
|
||||||
if: ${{ env.ACT }} # only run during local actions testing
|
if: ${{ env.ACT }} # only run during local actions testing
|
||||||
|
|
||||||
|
# If we were able to build then test that rustdoc (and rustdoc examples) compile
|
||||||
doc:
|
doc:
|
||||||
name: "Check rustdoc"
|
name: "Check rustdoc"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -120,6 +192,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
shared-key: "cargo-deps"
|
shared-key: "cargo-deps"
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
|
save-if: false
|
||||||
- name: "Run cargo doc"
|
- name: "Run cargo doc"
|
||||||
run: cargo doc --workspace
|
run: cargo doc --workspace
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
|
|
@ -9,45 +9,52 @@ repos:
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: rustup run --install nightly-2023-07-09 cargo-clippy -- --workspace --all-features -- -D warnings
|
entry: rustup run --install nightly-2023-07-09 cargo-clippy -- --workspace --all-features -- -D warnings
|
||||||
|
|
||||||
- id: build-no-features
|
- id: build-no-features
|
||||||
name: Check crate build with no features
|
name: Check crate build with no features
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: cargo check --workspace --no-default-features
|
entry: cargo check --workspace --no-default-features
|
||||||
|
|
||||||
- id: build-all-features
|
- id: build-all-features
|
||||||
name: Check crate builds with all features
|
name: Check crate builds with all features
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: cargo check --workspace --all-features --lib --bins --examples
|
entry: cargo check --workspace --all-features --lib --bins --examples
|
||||||
|
|
||||||
- id: test
|
- id: test
|
||||||
name: Check tests pass
|
name: Check tests pass
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: cargo test --workspace --bins --lib --examples --all-features
|
entry: cargo test --workspace --bins --lib --examples --tests --all-features
|
||||||
|
|
||||||
- id: format
|
- id: format
|
||||||
name: Check rustfmt
|
name: Check rustfmt
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: rustup run --install nightly-2023-07-09 cargo-fmt --check
|
entry: rustup run --install nightly-2023-07-09 cargo-fmt --check
|
||||||
|
|
||||||
- id: msrv
|
- id: msrv
|
||||||
name: Check MSRV compiles (lib only)
|
name: Check MSRV compiles (lib only)
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: rustup run --install 1.65 cargo check -p gamedig
|
entry: rustup run --install 1.65 cargo check -p gamedig
|
||||||
|
|
||||||
- id: docs
|
- id: docs
|
||||||
name: Check rustdoc compiles
|
name: Check rustdoc compiles
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: env RUSTDOCFLAGS="-D warnings" cargo doc
|
entry: env RUSTDOCFLAGS="-D warnings" cargo doc
|
||||||
|
|
||||||
- id: actions
|
- id: actions
|
||||||
name: Check actions work
|
name: Check actions work
|
||||||
language: system
|
language: system
|
||||||
files: '^[.]github/workflows/'
|
files: '^[.]github/workflows/'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: act -q
|
entry: act --rm
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,21 @@ encoding_rs = "0.8"
|
||||||
|
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
|
|
||||||
phf = { version = "0.11", optional = true, features = ["macros"] }
|
phf = { version = "0.11", optional = true, features = ["macros"] }
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
[[example]]
|
||||||
|
name = "minecraft"
|
||||||
|
required-features = ["games"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "teamfortress2"
|
||||||
|
required-features = ["games"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "valve_master_server_query"
|
||||||
|
required-features = ["services"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "generic"
|
||||||
|
required-features = ["games", "game_defs"]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
#[cfg(feature = "games")]
|
||||||
|
use crate::games::minecraft;
|
||||||
use crate::protocols::{gamespy, quake, unreal2, valve};
|
use crate::protocols::{gamespy, quake, unreal2, valve};
|
||||||
use crate::GDErrorKind::InvalidInput;
|
use crate::GDErrorKind::InvalidInput;
|
||||||
use crate::{minecraft, GDResult};
|
use crate::GDResult;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
@ -8,6 +10,7 @@ use std::time::Duration;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Enumeration of all custom protocols
|
/// Enumeration of all custom protocols
|
||||||
|
#[cfg(feature = "games")]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub enum ProprietaryProtocol {
|
pub enum ProprietaryProtocol {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue