Skip to content

Commit

Permalink
ci: added automated builds and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare committed Mar 3, 2024
1 parent 575c831 commit 6a8b6a2
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 2 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: CI

on:
push:
branches: ["main"]
tags: "v*"
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- build: linux
platform: ubuntu-latest
target: x86_64-unknown-linux-gnu

- build: macos
platform: macos-latest
target: x86_64-apple-darwin

- build: windows
platform: windows-latest
target: x86_64-pc-windows-gnu
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies (linux only)
if: matrix.build == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Rust cache
uses: swatinem/rust-cache@v2

- name: Run Tests
run: cargo test --locked

- name: Build
run: cargo build -r --target ${{ matrix.target }} --locked

- name: Build Deb (linux)
if: matrix.build == 'linux'
run: |
cargo install cargo-deb
cargo deb -o protontweaks.deb
- name: Rename Binaries (linux / macos)
if: matrix.build != 'windows'
run: mv target/${{ matrix.target }}/release/protontweaks target/${{ matrix.target }}/release/protontweaks-${{ matrix.target }}

- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/protontweaks.exe
target/${{ matrix.target }}/release/protontweaks-${{ matrix.target }}
protontweaks.deb
- name: Upload the binaries
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
target/${{ matrix.target }}/release/protontweaks.exe
target/${{ matrix.target }}/release/protontweaks-${{ matrix.target }}
protontweaks.deb
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/result
3 changes: 2 additions & 1 deletion nix/protontweaks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ rustPlatform.buildRustPackage {
lockFile = ../Cargo.lock;
};

checkFlags = [ ];
# Most tests fail due to the isolation
doCheck = false;

buildInputs = [
openssl
Expand Down
44 changes: 43 additions & 1 deletion src/tweaks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ const PROTONTWEAKS_DB: &str = env!("PROTONTWEAKS_DB");

#[derive(Debug, Deserialize)]
pub struct App {
#[serde(skip_deserializing)]
pub id: String,
pub name: String,
pub tweaks: Tweaks,
pub issues: Vec<Issue>,
}

#[derive(Debug, Deserialize)]
pub struct Issue {
pub description: String,
pub solution: String,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -86,3 +92,39 @@ pub fn apply(app: &App) -> Result<(u32, u32), String> {
&app.tweaks.tricks,
)?);
}

#[cfg(test)]
mod tests {
use crate::tweaks::{get, list, url};

#[test]
fn url_should_create_a_tweaks_url() {
assert_eq!(
url("tweaks").to_string(),
"https://tweaks.rains.cafe/tweaks.json"
);
}

#[test]
fn list_should_return_the_tweaks_list() {
let tweaks = list();

assert!(
tweaks.tweaks.len() > 0,
"Expected to receive a list of valid tweaked apps!"
);
}

#[test]
fn get_should_return_the_tweak_info() {
let expected_id = "644930";
let tweak = get(expected_id);

assert_eq!(tweak.id, expected_id);
assert_eq!(tweak.issues.len(), 1);
assert_eq!(tweak.tweaks.tricks.len(), 1);
assert_eq!(tweak.tweaks.env.len(), 0);
assert_eq!(tweak.tweaks.settings.esync, None);
assert_eq!(tweak.tweaks.settings.fsync, None);
}
}
15 changes: 15 additions & 0 deletions src/utils/nix_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ pub fn version() -> Result<String, String> {
pub fn is_installed() -> bool {
super::command::is_installed("nix-shell")
}

#[cfg(test)]
mod tests {
use crate::utils::nix_shell::{is_installed, version};

#[test]
fn version_should_return_the_version() {
assert_eq!(version().is_ok(), true);
}

#[test]
fn is_installed_should_return_true_if_installed() {
assert_eq!(is_installed(), true);
}
}
15 changes: 15 additions & 0 deletions src/utils/protontricks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ pub fn is_installed() -> bool {
pub fn version() -> Result<String, String> {
protontricks(["--version"])
}

#[cfg(test)]
mod tests {
use crate::utils::protontricks::{is_installed, version};

#[test]
fn version_should_return_the_version() {
assert_eq!(version().is_ok(), true);
}

#[test]
fn is_installed_should_return_false_if_not_installed() {
assert_eq!(is_installed(), false);
}
}

0 comments on commit 6a8b6a2

Please sign in to comment.